Search in sources :

Example 11 with HashParameters

use of io.helidon.common.http.HashParameters in project helidon by oracle.

the class HashParametersTest method unmodifiabilityEmpty.

@Test
public void unmodifiabilityEmpty() throws Exception {
    HashParameters hashParameters = HashParameters.create();
    assertThrows(UnsupportedOperationException.class, () -> {
        hashParameters.all("a").add("this should fail");
    });
}
Also used : HashParameters(io.helidon.common.http.HashParameters) Test(org.junit.jupiter.api.Test)

Example 12 with HashParameters

use of io.helidon.common.http.HashParameters in project helidon by oracle.

the class HashParametersTest method remove.

@Test
public void remove() throws Exception {
    HashParameters hp = HashParameters.create();
    List<String> removed = hp.remove("a");
    assertThat(removed, IsCollectionWithSize.hasSize(0));
    hp.put("a", "v1", "v2");
    removed = hp.remove("a");
    assertThat(removed, contains("v1", "v2"));
    assertThat(hp.all("a"), IsCollectionWithSize.hasSize(0));
}
Also used : HashParameters(io.helidon.common.http.HashParameters) Test(org.junit.jupiter.api.Test)

Example 13 with HashParameters

use of io.helidon.common.http.HashParameters in project helidon by oracle.

the class HashParametersTest method unmodifiabilityNonEmpty.

@Test
public void unmodifiabilityNonEmpty() throws Exception {
    HashParameters hashParameters = HashParameters.create();
    hashParameters.add("a", "v1", "v2");
    assertThrows(UnsupportedOperationException.class, () -> {
        hashParameters.all("a").add("this should fail");
    });
}
Also used : HashParameters(io.helidon.common.http.HashParameters) Test(org.junit.jupiter.api.Test)

Example 14 with HashParameters

use of io.helidon.common.http.HashParameters in project helidon by oracle.

the class HashParametersTest method put.

@Test
public void put() throws Exception {
    HashParameters hp = HashParameters.create();
    List<String> result = hp.put("a", "v1", "v2", "v3");
    assertThat(hp.all("a"), contains("v1", "v2", "v3"));
    assertThat(result, IsCollectionWithSize.hasSize(0));
    result = hp.put("a", "x1", "x2");
    assertThat(result, contains("v1", "v2", "v3"));
    assertThat(hp.all("a"), contains("x1", "x2"));
    List<String> l = new ArrayList<>(Arrays.asList("y1", "y2"));
    hp.put("a", l);
    assertThat(hp.all("a"), contains("y1", "y2"));
    l.add("y3");
    assertThat(hp.all("a").size(), is(2));
    hp.put("a");
    assertThat(hp.first("a").isPresent(), is(false));
    hp.put("b", "b1", "b2");
    hp.put("b", (Iterable<String>) null);
    assertThat(hp.first("b").isPresent(), is(false));
}
Also used : ArrayList(java.util.ArrayList) HashParameters(io.helidon.common.http.HashParameters) Test(org.junit.jupiter.api.Test)

Example 15 with HashParameters

use of io.helidon.common.http.HashParameters in project helidon by oracle.

the class HashParametersTest method toMap.

@Test
public void toMap() throws Exception {
    HashParameters hp = HashParameters.create();
    hp.put("a", "v1", "v2");
    hp.put("b", "v3", "v4");
    Map<String, List<String>> map = hp.toMap();
    assertThat(map.size(), is(2));
    assertThat(map.get("a"), contains("v1", "v2"));
    assertThat(map.get("b"), contains("v3", "v4"));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) HashParameters(io.helidon.common.http.HashParameters) Test(org.junit.jupiter.api.Test)

Aggregations

HashParameters (io.helidon.common.http.HashParameters)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)3 Parameters (io.helidon.common.http.Parameters)2 List (java.util.List)2 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Optional.empty (java.util.Optional.empty)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 IsCollectionWithSize (org.hamcrest.collection.IsCollectionWithSize)1 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)1 IsIterableContainingInOrder.contains (org.hamcrest.collection.IsIterableContainingInOrder.contains)1 Is.is (org.hamcrest.core.Is.is)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1