@Override protected List<String> create(String[] elements) { List<String> fromList = Lists.newArrayList(elements); return Lists.transform(fromList, Functions.<String>identity()); } })
@Override protected SortedMap<String, String> makeEmptyMap() { return Maps.transformValues(Maps.<String, String>newTreeMap(), Functions.<String>identity()); }
@Override protected List<String> create(String[] elements) { List<String> fromList = Lists.newLinkedList(asList(elements)); return Lists.transform(fromList, Functions.<String>identity()); } })
public void testTransformIdentityFunctionEquality() { Map<String, Integer> underlying = ImmutableMap.of("a", 1); Map<String, Integer> map = Maps.transformValues(underlying, Functions.<Integer>identity()); assertMapsEqual(underlying, map); }
public void testIndex_nullValue() { List<Integer> values = Arrays.asList(1, null); try { Multimaps.index(values, Functions.identity()); fail(); } catch (NullPointerException expected) { } }
public void testTransformIdentityFunctionEquality() { Map<String, Integer> underlying = ImmutableMap.of("a", 1); Map<String, Integer> map = Maps.transformValues(underlying, Functions.<Integer>identity()); assertMapsEqual(underlying, map); }
public void testIdentity_same() { Function<String, String> identity = Functions.identity(); assertNull(identity.apply(null)); assertSame("foo", identity.apply("foo")); }
@Override protected Map<String, Collection<Integer>> makeEmptyMap() { return Multimaps.transformValues( ArrayListMultimap.<String, Integer>create(), Functions.<Integer>identity()) .asMap(); }
public void testTransform_rejectionPropagatesToOutput() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); Function<Foo, Foo> identity = identity(); ListenableFuture<Foo> transformed = transform(input, identity, REJECTING_EXECUTOR); input.set(new Foo()); try { getDone(transformed); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(RejectedExecutionException.class); } }
@GwtIncompatible // SerializableTester public void testIdentitySerializable() { checkCanReserializeSingleton(Functions.identity()); }
public void testTransform_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); ListenableFuture<Object> output = transform(input, identity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyError.class); } }
public void testTransform_Executor() throws Exception { Object value = new Object(); ExecutorSpy spy = new ExecutorSpy(directExecutor()); assertFalse(spy.wasExecuted); ListenableFuture<Object> future = transform(immediateFuture(value), identity(), spy); assertSame(value, getDone(future)); assertTrue(spy.wasExecuted); }
@Override protected Map<String, Collection<Integer>> makePopulatedMap() { ListMultimap<String, Integer> delegate = ArrayListMultimap.create(); populate(delegate); return Multimaps.transformValues(delegate, Functions.<Integer>identity()).asMap(); } }
public void testTransform_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); ListenableFuture<Object> output = transform(input, identity(), directExecutor()); try { getDone(output); fail(); } catch (ExecutionException expected) { assertThat(expected.getCause()).isInstanceOf(MyRuntimeException.class); } }
public void testNotInterfaceType() { try { new ForwardingWrapperTester().testForwarding(String.class, Functions.<String>identity()); fail(); } catch (IllegalArgumentException expected) { } }
public void testCatching_getThrowsError() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingError(new MyError()); // We'd catch only MyError.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catching(input, Throwable.class, identity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyError.class); }
public void testCatching_getThrowsRuntimeException() throws Exception { ListenableFuture<Object> input = UncheckedThrowingFuture.throwingRuntimeException(new MyRuntimeException()); // We'd catch only MyRuntimeException.class here, but then the test won't compile under GWT. ListenableFuture<Object> output = catching(input, Throwable.class, identity(), directExecutor()); assertThat(getDone(output)).isInstanceOf(MyRuntimeException.class); }
public void testForPredicate() { Function<Object, Boolean> alwaysTrue = Functions.forPredicate(Predicates.alwaysTrue()); Function<Object, Boolean> alwaysFalse = Functions.forPredicate(Predicates.alwaysFalse()); assertTrue(alwaysTrue.apply(0)); assertFalse(alwaysFalse.apply(0)); new EqualsTester() .addEqualityGroup(alwaysTrue, Functions.forPredicate(Predicates.alwaysTrue())) .addEqualityGroup(alwaysFalse) .addEqualityGroup(Functions.identity()) .testEquals(); }
@Override public Set<Cell<String, Integer, Character>> create(Object... elements) { Table<String, Integer, Character> table = createTable(); for (Object element : elements) { @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element; table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); } return Tables.transformValues(table, Functions.<Character>identity()).cellSet(); } })
public void testOnResultOf_equals() { new EqualsTester() .addEqualityGroup( Equivalence.identity().onResultOf(Functions.toStringFunction()), Equivalence.identity().onResultOf(Functions.toStringFunction())) .addEqualityGroup(Equivalence.equals().onResultOf(Functions.toStringFunction())) .addEqualityGroup(Equivalence.identity().onResultOf(Functions.identity())) .testEquals(); }