rename newBuilder() to mutator() to follow principle of least surprise, let newBuilder() create a new and empty URL builder instead
This commit is contained in:
parent
53e9469d18
commit
4665353fc7
5 changed files with 24 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
group = org.xbib
|
||||
name = net
|
||||
version = 1.3.3
|
||||
version = 1.3.4
|
||||
|
||||
# test
|
||||
jackson.version = 2.8.11
|
||||
|
|
|
@ -325,10 +325,14 @@ public class URL implements Comparable<URL> {
|
|||
}
|
||||
}
|
||||
|
||||
public Builder newBuilder() {
|
||||
public Builder mutator() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private String toString(boolean withFragment) {
|
||||
if (internalStringRepresentation != null) {
|
||||
return internalStringRepresentation;
|
||||
|
|
|
@ -118,7 +118,7 @@ class URLBuilderTest {
|
|||
|
||||
@Test
|
||||
void testAllParts() {
|
||||
assertUrl(URL.https().resolveFromHost("foo.bar.com").port(3333)
|
||||
assertUrl(URL.https().resolveFromHost("foobar.com").port(3333)
|
||||
.pathSegment("foo")
|
||||
.pathSegment("bar")
|
||||
.matrixParam("mtx1", "val1")
|
||||
|
@ -127,11 +127,11 @@ class URLBuilderTest {
|
|||
.queryParam("q2", "v2")
|
||||
.fragment("zomg it's a fragment")
|
||||
.toUrlString(),
|
||||
"https://foo.bar.com:3333/foo/bar;mtx1=val1;mtx2=val2?q1=v1&q2=v2#zomg%20it's%20a%20fragment");
|
||||
"https://foobar.com:3333/foo/bar;mtx1=val1;mtx2=val2?q1=v1&q2=v2#zomg%20it's%20a%20fragment");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSlashInHost() {
|
||||
void testSlashHost() {
|
||||
URL.http().resolveFromHost("/").toUrlString();
|
||||
}
|
||||
|
||||
|
@ -259,12 +259,21 @@ class URLBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testNewBuilder() {
|
||||
URL.Builder builder = URL.from("http://google.com:8008/foobar").newBuilder();
|
||||
void testMutator() {
|
||||
URL.Builder builder = URL.from("http://google.com:8008/foobar").mutator();
|
||||
builder.scheme("https");
|
||||
assertEquals("https://google.com:8008/foobar", builder.build().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNewBuilder() {
|
||||
URL url = URL.from("http://google.com:8008/foobar");
|
||||
URL.Builder builder = url.newBuilder()
|
||||
.scheme(url.getScheme())
|
||||
.schemeSpecificPart(url.getSchemeSpecificPart());
|
||||
assertEquals("http://google.com:8008/foobar", builder.build().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUserInfo(){
|
||||
String s = URL.http().userInfo("foo:bar").host("foo.com").toUrlString();
|
||||
|
|
|
@ -14,6 +14,10 @@ class URLResolverTest {
|
|||
void testResolveURI() throws Exception {
|
||||
URI base = URI.create("http://example.org/foo");
|
||||
assertEquals("http://example.org/", base.resolve("/").toString());
|
||||
assertEquals("http://example.org/foo", base.toString());
|
||||
URI rel = URI.create("http://foobar/rel");
|
||||
assertEquals("http://foobar/rel", base.resolve(rel).toString());
|
||||
assertEquals("http://example.org/foo", base.toString());
|
||||
assertEquals("http://example.org/foobar", base.resolve("/foobar").toString());
|
||||
assertEquals("http://example.org/foobar", base.resolve("foobar").toString());
|
||||
base = URI.create("http://example.org/foo/");
|
||||
|
|
|
@ -20,14 +20,12 @@ class URLTest {
|
|||
for (JsonTest test : tests) {
|
||||
String base = test.base;
|
||||
String input = test.input;
|
||||
//System.err.println("testing: " + base + " " + input + " " + test.failure);
|
||||
if (test.skip) {
|
||||
continue;
|
||||
}
|
||||
if (test.failure) {
|
||||
try {
|
||||
URL url = URL.base(base).resolve(input);
|
||||
//System.err.println("resolved: " + url.toString());
|
||||
fail();
|
||||
} catch (Exception e) {
|
||||
// pass
|
||||
|
@ -36,7 +34,6 @@ class URLTest {
|
|||
if (base != null && input != null) {
|
||||
try {
|
||||
URL url = URL.base(base).resolve(input);
|
||||
//System.err.println("resolved: " + url.toString());
|
||||
if (test.protocol != null) {
|
||||
assertEquals(test.protocol, url.getScheme() + ":");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue