Beispiel #1
0
 @Override
 @Test
 public void ifPresentApply() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Assert.assertNull(map.ifPresentApply(4, Functions.<String>getPassThru()));
   Assert.assertEquals("1", map.ifPresentApply(1, Functions.<String>getPassThru()));
 }
Beispiel #2
0
 @Override
 @Test
 public void forEachKey() {
   MutableList<Integer> collection = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   map.forEachKey(CollectionAddProcedure.on(collection));
   Assert.assertEquals(FastList.newListWith(1), collection);
 }
Beispiel #3
0
 @Override
 public void withoutAllKeys() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A");
   MutableMap<Integer, String> mapWithout = map.withoutAllKeys(FastList.newListWith(2, 3));
   Assert.assertSame(map, mapWithout);
   mapWithout = map.withoutAllKeys(FastList.newListWith(1, 2));
   Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout);
   Verify.assertInstanceOf(EmptyMap.class, mapWithout);
 }
Beispiel #4
0
 @Override
 @Test
 public void getIfAbsentWith() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Assert.assertNull(map.get(4));
   Assert.assertEquals("4", map.getIfAbsentWith(4, Functions.getToString(), 4));
   Assert.assertEquals("1", map.getIfAbsentWith(1, Functions.getToString(), 1));
   Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1"), map);
 }
Beispiel #5
0
 @Override
 @Test
 public void getIfAbsent() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Assert.assertNull(map.get(4));
   Assert.assertEquals("4", map.getIfAbsent(4, new Constant<String>("4")));
   Assert.assertEquals("1", map.getIfAbsent(1, new Constant<String>("1")));
   Assert.assertEquals(UnifiedMap.newWithKeysValues(1, "1"), map);
 }
Beispiel #6
0
 @Override
 public void withoutKey() {
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "A");
   MutableMap<Integer, String> mapWithout = map.withoutKey(2);
   Assert.assertSame(map, mapWithout);
   mapWithout = map.withoutKey(1);
   Verify.assertMapsEqual(UnifiedMap.newMap(), mapWithout);
   Verify.assertInstanceOf(EmptyMap.class, mapWithout);
 }
Beispiel #7
0
 @Override
 @Test
 public void values() {
   MutableList<String> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (String value : map.values()) {
     result.add(value);
   }
   Assert.assertEquals(FastList.newListWith("One"), result);
 }
Beispiel #8
0
 @Override
 @Test
 public void keySet() {
   MutableList<Integer> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (Integer key : map.keySet()) {
     result.add(key);
   }
   Assert.assertEquals(FastList.newListWith(1), result);
 }
Beispiel #9
0
  @Override
  @Test
  public void detect() {
    MutableMap<String, String> map = this.classUnderTest();

    Pair<String, String> actual = map.find(Predicates2.alwaysTrue());
    Assert.assertEquals(Tuples.pair("1", "One"), actual);

    Assert.assertNull(map.find(Predicates2.alwaysFalse()));
  }
Beispiel #10
0
 @Override
 @Test
 public void entrySet() {
   MutableList<String> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (Map.Entry<Integer, String> entry : map.entrySet()) {
     result.add(entry.getValue());
   }
   Assert.assertEquals(FastList.newListWith("One"), result);
 }
Beispiel #11
0
  @Override
  public void withKeyValue() {
    MutableMap<Integer, String> map1 =
        new SingletonMap<Integer, String>(1, "A").withKeyValue(2, "B");
    Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "A", 2, "B"), map1);
    Verify.assertInstanceOf(DoubletonMap.class, map1);

    MutableMap<Integer, String> map2 = new SingletonMap<Integer, String>(1, "A");
    MutableMap<Integer, String> map2with = map2.withKeyValue(1, "AA");
    Verify.assertMapsEqual(UnifiedMap.newWithKeysValues(1, "AA"), map2with);
    Assert.assertSame(map2, map2with);
  }
Beispiel #12
0
  @Override
  @Test
  public void reject() {
    MutableMap<String, String> map = this.classUnderTest();

    MutableMap<String, String> empty = map.filterNot(Predicates2.alwaysTrue());
    Verify.assertInstanceOf(EmptyMap.class, empty);

    MutableMap<String, String> full = map.filterNot(Predicates2.alwaysFalse());
    Verify.assertInstanceOf(SingletonMap.class, full);
    Assert.assertEquals(map, full);
  }
Beispiel #13
0
 @Override
 @Test
 public void forEachKeyValue() {
   final MutableList<String> collection = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   map.forEachKeyValue(
       new Procedure2<Integer, String>() {
         public void value(Integer key, String value) {
           collection.add(key + value);
         }
       });
   Assert.assertEquals(FastList.newListWith("1One"), collection);
 }
Beispiel #14
0
 @Override
 @Test
 public void getIfAbsentPut() {
   final MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           map.getIfAbsentPut(4, new Constant<String>("4"));
         }
       });
   Assert.assertEquals("1", map.getIfAbsentPut(1, new Constant<String>("1")));
 }
Beispiel #15
0
 @Override
 @Test
 public void getIfAbsentPutWith() {
   final MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   Verify.assertThrows(
       UnsupportedOperationException.class,
       new Runnable() {
         public void run() {
           map.getIfAbsentPutWith(4, Functions.getToString(), 4);
         }
       });
   Assert.assertEquals("1", map.getIfAbsentPutWith(1, Functions.getToString(), 1));
 }
Beispiel #16
0
 @Override
 @Test
 public void forEachWith() {
   final MutableList<Integer> result = Lists.mutable.of();
   MutableMap<Integer, Integer> map = new SingletonMap<Integer, Integer>(1, 1);
   map.forEachWith(
       new Procedure2<Integer, Integer>() {
         public void value(Integer argument1, Integer argument2) {
           result.add(argument1 + argument2);
         }
       },
       10);
   Assert.assertEquals(FastList.newListWith(11), result);
 }
Beispiel #17
0
 @Override
 @Test
 public void forEachWithIndex() {
   final MutableList<String> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   map.forEachWithIndex(
       new ObjectIntProcedure<String>() {
         public void value(String value, int index) {
           result.add(value);
           result.add(String.valueOf(index));
         }
       });
   Assert.assertEquals(FastList.newListWith("One", "0"), result);
 }