use of io.helidon.common.http.HashParameters in project helidon by oracle.
the class HashParametersTest method putIfAbsent.
@Test
public void putIfAbsent() throws Exception {
HashParameters hp = HashParameters.create();
List<String> result = hp.putIfAbsent("a", "v1", "v2", "v3");
assertThat(result, IsCollectionWithSize.hasSize(0));
assertThat(hp.all("a"), contains("v1", "v2", "v3"));
result = hp.putIfAbsent("a", "x1", "x2", "x3");
assertThat(result, contains("v1", "v2", "v3"));
assertThat(hp.all("a"), contains("v1", "v2", "v3"));
hp.putIfAbsent("b", Arrays.asList("v1", "v2", "v3"));
assertThat(hp.all("b"), contains("v1", "v2", "v3"));
hp.putIfAbsent("b", Arrays.asList("x1", "x2", "x3"));
assertThat(hp.all("b"), contains("v1", "v2", "v3"));
hp.putIfAbsent("b");
assertThat(hp.all("b"), contains("v1", "v2", "v3"));
hp.putIfAbsent("b", (Iterable<String>) null);
assertThat(hp.all("b"), contains("v1", "v2", "v3"));
result = hp.putIfAbsent("c");
assertThat(result, IsCollectionWithSize.hasSize(0));
result = hp.putIfAbsent("c", (Iterable<String>) null);
assertThat(result, IsCollectionWithSize.hasSize(0));
}
use of io.helidon.common.http.HashParameters in project helidon by oracle.
the class HashParametersTest method putAll.
@Test
public void putAll() throws Exception {
HashParameters hp = HashParameters.create();
hp.put("a", "a1", "a2");
hp.put("b", "b1", "b2");
HashParameters hp2 = HashParameters.create();
hp2.put("c", "c1", "c2");
hp2.put("b", "b3", "b4");
hp.putAll(hp2);
assertThat(hp.all("a"), contains("a1", "a2"));
assertThat(hp.all("b"), contains("b3", "b4"));
assertThat(hp.all("c"), contains("c1", "c2"));
hp.putAll(null);
assertThat(hp.all("a"), contains("a1", "a2"));
assertThat(hp.all("b"), contains("b3", "b4"));
}
use of io.helidon.common.http.HashParameters in project helidon by oracle.
the class HashParametersTest method computeIfAbsent.
@Test
public void computeIfAbsent() throws Exception {
AtomicBoolean visited = new AtomicBoolean(false);
HashParameters hp = HashParameters.create();
List<String> result = hp.computeIfAbsent("a", k -> {
visited.set(true);
return null;
});
assertThat(visited.get(), is(true));
assertThat(result, IsCollectionWithSize.hasSize(0));
assertThat(hp.all("a"), IsCollectionWithSize.hasSize(0));
visited.set(false);
result = hp.computeIfAbsent("a", k -> {
visited.set(true);
return Arrays.asList("v1", "v2", "v3");
});
assertThat(visited.get(), is(true));
assertThat(result, contains("v1", "v2", "v3"));
assertThat(hp.all("a"), contains("v1", "v2", "v3"));
visited.set(false);
result = hp.computeIfAbsent("a", k -> {
visited.set(true);
return Arrays.asList("x1", "x2", "x3");
});
assertThat(visited.get(), is(false));
assertThat(result, contains("v1", "v2", "v3"));
assertThat(hp.all("a"), contains("v1", "v2", "v3"));
visited.set(false);
result = hp.computeSingleIfAbsent("b", k -> {
visited.set(true);
return "x1";
});
assertThat(visited.get(), is(true));
assertThat(result, contains("x1"));
assertThat(hp.all("b"), contains("x1"));
visited.set(false);
result = hp.computeSingleIfAbsent("c", k -> {
visited.set(true);
return null;
});
assertThat(visited.get(), is(true));
assertThat(result, IsCollectionWithSize.hasSize(0));
assertThat(hp.first("c").isPresent(), is(false));
}
use of io.helidon.common.http.HashParameters in project helidon by oracle.
the class HashParametersTest method nonExistentKey.
@Test
public void nonExistentKey() throws Exception {
HashParameters hashParameters = HashParameters.create();
assertThat(hashParameters.all("a"), hasSize(0));
assertThat(hashParameters.first("a"), is(empty()));
}
use of io.helidon.common.http.HashParameters in project helidon by oracle.
the class HashParametersTest method concat.
@Test
public void concat() throws Exception {
HashParameters p1 = HashParameters.create();
p1.add("a", "1", "2");
p1.add("b", "3", "4", "5");
HashParameters p2 = HashParameters.create();
p2.add("a", "6");
p2.add("c", "7", "8");
HashParameters p3 = HashParameters.create();
HashParameters p4 = HashParameters.create();
p2.add("a", "9");
p2.add("c", "10");
p2.add("d", "11", "12");
HashParameters concat = HashParameters.concat(p1, p2, null, p3, null, p4, null, null);
assertThat(concat.all("a"), contains("1", "2", "6", "9"));
assertThat(concat.all("b"), contains("3", "4", "5"));
assertThat(concat.all("c"), contains("7", "8", "10"));
assertThat(concat.all("d"), contains("11", "12"));
concat = HashParameters.concat(p1);
assertThat(concat, is(p1));
}
Aggregations