コード例 #1
0
  @Test
  public void anySatisfy() {
    ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>();

    Assert.assertFalse(map.anySatisfy(Predicates.instanceOf(String.class)));
    Assert.assertFalse(map.anySatisfy(Predicates.equal("Monkey")));
  }
コード例 #2
0
  @Test
  public void noneSatisfy() {
    ImmutableSortedMap<String, String> map = new ImmutableEmptySortedMap<String, String>();

    Assert.assertTrue(map.noneSatisfy(Predicates.instanceOf(Integer.class)));
    Assert.assertTrue(map.noneSatisfy(Predicates.equal("Monkey")));
  }
コード例 #3
0
 @Test
 public void containsKey() {
   ImmutableSortedMap<Integer, String> map = this.classUnderTest();
   ImmutableSortedMap<Integer, String> revMap =
       this.classUnderTest(Comparators.<Integer>reverseNaturalOrder());
   Assert.assertFalse(map.containsKey(0));
   Assert.assertFalse(revMap.containsKey(1));
 }
コード例 #4
0
  @Override
  @Test
  public void ifPresentApply() {
    Integer absentKey = this.size() + 1;

    ImmutableSortedMap<Integer, String> classUnderTest = this.classUnderTest();
    Assert.assertNull(classUnderTest.ifPresentApply(absentKey, Functions.<String>getPassThru()));
  }
コード例 #5
0
  @Override
  @Test
  public void get() {
    Integer absentKey = this.size() + 1;
    String absentValue = String.valueOf(absentKey);

    // Absent key behavior
    ImmutableSortedMap<Integer, String> classUnderTest = this.classUnderTest();
    Assert.assertNull(classUnderTest.get(absentKey));
    Assert.assertFalse(classUnderTest.containsValue(absentValue));

    // Still unchanged
    Assert.assertEquals(this.equalUnifiedMap(), classUnderTest);
  }
コード例 #6
0
  @Override
  @Test
  public void collectMap() {
    ImmutableSortedMap<Integer, String> map = this.classUnderTest();
    ImmutableSortedMap<Integer, String> revMap =
        this.classUnderTest(Comparators.<Integer>reverseNaturalOrder());

    Function2<Integer, String, Pair<Integer, String>> alwaysTrueFunction = Tuples::pair;
    ImmutableMap<Integer, String> collect = map.collect(alwaysTrueFunction);
    ImmutableMap<Integer, String> revCollect = revMap.collect(alwaysTrueFunction);

    Verify.assertEmpty(collect);
    Assert.assertSame(collect, revCollect);
  }
コード例 #7
0
  @Test
  public void serialization() {
    ImmutableSortedMap<Integer, String> map = this.classUnderTest();
    ImmutableSortedMap<Integer, String> deserialized =
        SerializeTestHelper.serializeDeserialize(map);
    Assert.assertSame(ImmutableEmptySortedMap.INSTANCE, map);
    Assert.assertSame(map, deserialized);

    ImmutableSortedMap<Integer, String> revMap =
        this.classUnderTest(Comparators.<Integer>reverseNaturalOrder());
    ImmutableSortedMap<Integer, String> revDeserialized =
        SerializeTestHelper.serializeDeserialize(revMap);
    Verify.assertInstanceOf(ImmutableSortedMap.class, revDeserialized);
    Assert.assertNotNull(revDeserialized.comparator());
  }
コード例 #8
0
  @Override
  @Test
  public void getIfAbsent() {
    super.getIfAbsent();

    Integer absentKey = this.size() + 1;
    String absentValue = String.valueOf(absentKey);

    // Absent key behavior
    ImmutableSortedMap<Integer, String> classUnderTest = this.classUnderTest();
    Assert.assertEquals(
        absentValue,
        classUnderTest.getIfAbsent(absentKey, new PassThruFunction0<String>(absentValue)));

    // Still unchanged
    Assert.assertEquals(this.equalUnifiedMap(), classUnderTest);
  }
コード例 #9
0
  @Override
  @Test
  public void rejectMap() {
    ImmutableSortedMap<Integer, String> map = this.classUnderTest();
    ImmutableSortedMap<Integer, String> actual = map.reject(Predicates2.alwaysFalse());
    Verify.assertInstanceOf(ImmutableEmptySortedMap.class, actual);
    Assert.assertSame(ImmutableEmptySortedMap.INSTANCE, actual);

    ImmutableSortedMap<Integer, String> revMap =
        this.classUnderTest(Comparators.<Integer>reverseNaturalOrder());
    ImmutableSortedMap<Integer, String> revActual = revMap.reject(Predicates2.alwaysTrue());
    Verify.assertInstanceOf(ImmutableEmptySortedMap.class, revActual);
    Assert.assertSame(revMap.comparator(), revActual.comparator());
  }
コード例 #10
0
 @Override
 @Test
 public void testToString() {
   ImmutableSortedMap<Integer, String> map = this.classUnderTest();
   Assert.assertEquals("{}", map.toString());
 }
コード例 #11
0
 @Test
 public void detect() {
   ImmutableSortedMap<Integer, String> map = this.classUnderTest();
   Assert.assertNull(map.detect(Predicates2.alwaysTrue()));
 }