@Test
 public void attributeNotNull() {
   Twin<String> testCandidate = Tuples.twin("Hello", null);
   assertAccepts(Predicates.attributeNotNull(Functions.firstOfPair()), testCandidate);
   assertRejects(Predicates.attributeNotNull(Functions.secondOfPair()), testCandidate);
   assertToString(Predicates.attributeNotNull(Functions.<String>firstOfPair()));
 }
 @Test
 public void toMap() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableMap<Integer, Integer> map =
       integers.toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru());
   Verify.assertContainsAll(map.keySet(), 1);
   Verify.assertContainsAll(map.values(), 1);
 }
 @Test
 public void attributeBetweenInclusive() {
   Predicate<Pair<Integer, ?>> predicate =
       Predicates.attributeBetweenInclusive(Functions.firstOfPair(), 9, 11);
   assertAccepts(predicate, Tuples.twin(9, 0), Tuples.twin(10, 0), Tuples.twin(11, 0));
   assertRejects(predicate, Tuples.twin(8, 0), Tuples.twin(12, 0));
 }
  @Override
  @Test(expected = NoSuchElementException.class)
  public void minBy() {
    ImmutableMap<Integer, String> map = this.classUnderTest();

    map.minBy(Functions.getStringPassThru());
  }
 @Test
 public void toSortedListBy() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableList<Integer> list = integers.toSortedListBy(Functions.getIntegerPassThru());
   Assert.assertEquals(FastList.newListWith(1), list);
   Assert.assertNotSame(integers, list);
 }
 public static <T extends Comparable<? super T>, V> CaseFunction<T, V> caseDefault(
     Function<? super T, ? extends V> defaultFunction,
     Predicate<? super T> predicate,
     Function<? super T, ? extends V> function) {
   CaseFunction<T, V> caseFunction = Functions.caseDefault(defaultFunction);
   return caseFunction.addCase(predicate, function);
 }
  @Override
  @Test
  public void ifPresentApply() {
    Integer absentKey = this.size() + 1;

    ImmutableMap<Integer, String> classUnderTest = this.classUnderTest();
    Assert.assertNull(classUnderTest.ifPresentApply(absentKey, Functions.getPassThru()));
  }
 @Test
 public void betweenExclusiveNumber() {
   assertBetweenExclusive(Predicates.betweenExclusive(1, 3));
   assertBetweenExclusive(
       Predicates.attributeBetweenExclusive(Functions.getIntegerPassThru(), 1, 3));
 }
 @Test
 public void attributeNotNullWithFunction() {
   assertRejects(Predicates.attributeNotNull(Functions.getPassThru()), (Object) null);
   assertAccepts(Predicates.attributeNotNull(Functions.getPassThru()), new Object());
 }
 @Test
 public void attributeIsNullWithFunctionName() {
   Twin<Integer> target = Tuples.twin(null, 1);
   assertAccepts(Predicates.attributeIsNull(Functions.firstOfPair()), target);
   assertRejects(Predicates.attributeIsNull(Functions.secondOfPair()), target);
 }
 @Test
 public void ifFalseWithClassAndFunctionName() {
   Twin<Boolean> target = Tuples.twin(true, false);
   assertRejects(Predicates.ifFalse(Functions.firstOfPair()), target);
   assertAccepts(Predicates.ifFalse(Functions.secondOfPair()), target);
 }
 @Test(expected = UnsupportedOperationException.class)
 @Override
 public void updateValue_collisions() {
   this.<Integer, Integer>newMap().updateValue(0, () -> 0, Functions.identity());
 }
 @Override
 @Test(expected = UnsupportedOperationException.class)
 public void getIfAbsentPutWithKey() {
   this.newMapWithKeysValues(1, 1, 2, 2, 3, 3)
       .getIfAbsentPutWithKey(4, Functions.getIntegerPassThru());
 }
Example #14
0
 public static Function<Object, String> getNullSafeToString(String defaultValue) {
   return Functions.nullSafe(TO_STRING_FUNCTION, defaultValue);
 }
Example #15
0
 /**
  * Alias for identity(). Inlineable.
  *
  * @see #identity()
  */
 public static <T> Function<T, T> getPassThru() {
   return Functions.identity();
 }