remove URL mutator

This commit is contained in:
Jörg Prante 2024-01-04 22:15:07 +01:00
parent c45bbfca53
commit d6ac3e267d
6 changed files with 13 additions and 20 deletions

View file

@ -1,3 +1,3 @@
group = org.xbib
name = net
version = 4.0.4
version = 4.1.0

View file

@ -41,7 +41,7 @@ import java.util.Objects;
* URL url = URL.http().resolveFromHost("google.com").build();
*
*/
public class URL implements Comparable<URL> {
public final class URL implements Comparable<URL> {
static final URL NULL_URL = URL.builder().build();
@ -257,10 +257,6 @@ public class URL implements Comparable<URL> {
}
}
public URLBuilder mutator() {
return builder;
}
public URLBuilder newBuilder() {
return new URLBuilder();
}

View file

@ -301,11 +301,11 @@ public class URLBuilder {
*
* @return a string
*/
String toUrlString() {
public String toUrlString() {
return build().toExternalForm();
}
void validateSchemeCharacters(String scheme) {
private void validateSchemeCharacters(String scheme) {
boolean valid;
for (int i = 0; i < scheme.length(); i++) {
char c = scheme.charAt(i);

View file

@ -106,7 +106,7 @@ public class ParameterTest {
}
@Test
public void testMutatorQueryParameters() {
public void testQueryParametersWithUrlBuilder() {
URL url = URL.from("http://localhost");
String requestPath = "/path";
Map<String, Object> map = Map.of(
@ -120,10 +120,9 @@ public class ParameterTest {
.enableQueryString(true)
.add(map)
.build();
URLBuilder mutator = url.mutator();
mutator.path(requestPath);
httpParameter.forEach(e -> mutator.queryParam(e.getKey(), e.getValue()));
url = mutator.build();
URLBuilder builder = URL.builder(url).path(requestPath);
httpParameter.forEach(e -> builder.queryParam(e.getKey(), e.getValue()));
url = builder.build();
assertEquals("http://localhost/path?operation=searchRetrieve&query=iss%20%3D%2000280836&recordSchema=MARC21plus-1-xml&version=1.1",
url.toExternalForm());
}

View file

@ -267,8 +267,8 @@ class URLBuilderTest {
}
@Test
void testMutator() {
URLBuilder builder = URL.from("http://google.com:8008/foobar").mutator();
void testUrlBuilder() {
URLBuilder builder = URL.builder(URL.from("http://google.com:8008/foobar"));
builder.queryParam("a%", "b%");
builder.queryParam("c", " d ");
builder.scheme("https");
@ -278,11 +278,9 @@ class URLBuilderTest {
assertEquals("https://google.com:8008/foobar?a%=b%&c= d ", url.toString());
// test inheritance of params added by mutator
URL url1 = URL.from("http://example.com");
url1.mutator().queryParams.add("a", "b");
URL url1 = URL.builder(URL.from("http://example.com")).queryParam("a", "b").build();
assertEquals("http://example.com?a=b", url1.toString());
URL url2 = URL.from(url1); // copy
url2.mutator().queryParams.add("c", "d");
URL url2 = URL.builder(url1).queryParam("c", "d").build();
assertEquals("http://example.com?a=b&c=d", url2.toString());
}

View file

@ -44,7 +44,7 @@ class URLResolverTest {
String pathSpec = "foobar/";
String index = "index.html";
String queryString = "a=b";
URL url = base.resolve(pathSpec).resolve(index).mutator().query(queryString).build().normalize();
URL url = URL.builder(base.resolve(pathSpec).resolve(index)).query(queryString).build().normalize();
assertEquals("http://example:8080/foobar/index.html?a=b", url.toString());
}