public class TestMapWritable extends TestCase {
private Configuration configuration = NutchConfiguration.create();
public void testMap() throws Exception {
MapWritable map = new MapWritable();
assertTrue(map.isEmpty());
for (int i = 0; i < 100; i++) {
Text key = new Text("" + i);
IntWritable value = new IntWritable(i);
map.put(key, value);
assertEquals(i + 1, map.size());
assertTrue(map.containsKey(new Text("" + i)));
assertTrue(map.containsValue(new IntWritable(i)));
map.remove(key);
assertEquals(i, map.size());
map.put(key, value);
assertEquals(value, map.get(key));
assertFalse(map.isEmpty());
assertTrue(map.keySet().contains(key));
assertEquals(i + 1, map.values().size());
assertTrue(map.values().contains(value));
}
testWritable(map);
MapWritable map2 = new MapWritable();
testWritable(map2);
map2.putAll(map);
assertEquals(100, map2.size());
testWritable(map2);
map.clear();
assertTrue(map.isEmpty());
assertEquals(0, map.size());