Added tests
This commit is contained in:
parent
332607ad6c
commit
11e7ad21b0
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -32,6 +33,18 @@ public class DefaultMultiValueMap<K, V> implements MultiValueMap<K, V> {
|
|||
|
||||
private final Map<K, List<V>> wrappee;
|
||||
|
||||
/**
|
||||
* Constructs a new intance of the {@code DefaultMultiValueMap} wrapping a plain {@link LinkedHashMap}.
|
||||
*/
|
||||
public DefaultMultiValueMap() {
|
||||
this(new LinkedHashMap<K, List<V>>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new intance of the {@code DefaultMultiValueMap} wrapping the given map.
|
||||
*
|
||||
* @param wrappee the map to be wrapped
|
||||
*/
|
||||
public DefaultMultiValueMap(Map<K, List<V>> wrappee) {
|
||||
Assert.notNull(wrappee, "'wrappee' must not be null");
|
||||
this.wrappee = wrappee;
|
||||
|
|
@ -112,4 +125,20 @@ public class DefaultMultiValueMap<K, V> implements MultiValueMap<K, V> {
|
|||
public Set<Entry<K, List<V>>> entrySet() {
|
||||
return wrappee.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return wrappee.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.wrappee.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return wrappee.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class DefaultMultiValueMapTests {
|
||||
|
||||
private DefaultMultiValueMap<String, String> map;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
map = new DefaultMultiValueMap<String, String>();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void add() {
|
||||
map.add("key", "value1");
|
||||
map.add("key", "value2");
|
||||
assertEquals(1, map.size());
|
||||
List<String> expected = new ArrayList<String>(2);
|
||||
expected.add("value1");
|
||||
expected.add("value2");
|
||||
assertEquals(expected, map.get("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirst() {
|
||||
List<String> values = new ArrayList<String>(2);
|
||||
values.add("value1");
|
||||
values.add("value2");
|
||||
map.put("key", values);
|
||||
assertEquals("value1", map.getFirst("key"));
|
||||
assertNull(map.getFirst("other"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void set() {
|
||||
map.set("key", "value1");
|
||||
map.set("key", "value2");
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(Collections.singletonList("value2"), map.get("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals() {
|
||||
map.set("key1", "value1");
|
||||
assertEquals(map, map);
|
||||
MultiValueMap<String, String> o1 = new DefaultMultiValueMap<String, String>();
|
||||
o1.set("key1", "value1");
|
||||
assertEquals(map, o1);
|
||||
assertEquals(o1, map);
|
||||
Map<String, List<String>> o2 = new HashMap<String, List<String>>();
|
||||
o2.put("key1", Collections.singletonList("value1"));
|
||||
assertEquals(map, o2);
|
||||
assertEquals(o2, map);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue