[URI-Creation] Difference Between URI.create() and new URI() (#12937)
* [URI-Creation] Difference Between URI.create() and new URI() * [URI-Creation] split test methods for invalid & valid inputs
This commit is contained in:
@@ -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."));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user