diff --git a/core-java-modules/core-java-networking-4/pom.xml b/core-java-modules/core-java-networking-4/pom.xml new file mode 100644 index 0000000000..ec7c80c12e --- /dev/null +++ b/core-java-modules/core-java-networking-4/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + core-java-networking-4 + core-java-networking-4 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + core-java-networking-4 + + diff --git a/core-java-modules/core-java-networking-4/src/test/java/com/baeldung/uricreation/UriCreationUnitTest.java b/core-java-modules/core-java-networking-4/src/test/java/com/baeldung/uricreation/UriCreationUnitTest.java new file mode 100644 index 0000000000..ce640d9509 --- /dev/null +++ b/core-java-modules/core-java-networking-4/src/test/java/com/baeldung/uricreation/UriCreationUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.uricreation; + +import org.junit.jupiter.api.Test; + +import java.net.URI; +import java.net.URISyntaxException; + +import static org.junit.jupiter.api.Assertions.*; + +public class UriCreationUnitTest { + @Test + void givenValidUriString_whenUsingConstructor_shouldGetExpectedResult() { + try { + URI myUri = new URI("https://www.baeldung.com/articles"); + assertNotNull(myUri); + } catch (URISyntaxException e) { + fail(); + } + } + + @Test + void givenInvalidUriString_whenUsingConstructor_shouldGetExpectedResult() { + assertThrows(URISyntaxException.class, () -> new URI("I am an invalid URI string.")); + } + + @Test + void givenValidUriString_whenUsingCreateMethod_shouldGetExpectedResult() { + URI myUri = URI.create("https://www.baeldung.com/articles"); + assertNotNull(myUri); + } + + @Test + void givenInvalidUriString_whenUsingCreateMethod_shouldGetExpectedResult() { + assertThrows(IllegalArgumentException.class, () -> URI.create("I am an invalid URI string.")); + } +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index a6ad43676d..148f536792 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -98,6 +98,7 @@ core-java-lang-syntax-2 core-java-networking core-java-networking-2 + core-java-networking-4 core-java-nio core-java-nio-2 core-java-numbers