static IterableSubject assertThat(Stream<?> stream) { return Truth.assertThat(stream.toArray()).asList(); } }
private static void assertEqualWildcardType(WildcardType expected, WildcardType actual) { assertEquals(expected.toString(), actual.toString()); assertEquals(actual.toString(), expected.hashCode(), actual.hashCode()); assertThat(actual.getLowerBounds()) .asList() .containsExactlyElementsIn(asList(expected.getLowerBounds())) .inOrder(); assertThat(actual.getUpperBounds()) .asList() .containsExactlyElementsIn(asList(expected.getUpperBounds())) .inOrder(); }
public void testConcat_refStream_parallel() { Truth.assertThat( Streams.concat(Stream.of("a"), Stream.of("b"), Stream.empty(), Stream.of("c", "d")) .parallel() .toArray()) .asList() .containsExactly("a", "b", "c", "d") .inOrder(); }
private static void assertEqualTypeVariable(TypeVariable<?> expected, TypeVariable<?> actual) { assertEquals(expected.toString(), actual.toString()); assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getGenericDeclaration(), actual.getGenericDeclaration()); if (!Types.NativeTypeVariableEquals.NATIVE_TYPE_VARIABLE_ONLY) { assertEquals(actual.toString(), expected.hashCode(), actual.hashCode()); } assertThat(actual.getBounds()) .asList() .containsExactlyElementsIn(asList(expected.getBounds())) .inOrder(); }
public void testAppendZeroElements() { String[] result = ObjectArrays.concat(new String[] {}, "foo"); assertThat(result).asList().contains("foo"); }
public void testPrependZeroElements() { String[] result = ObjectArrays.concat("foo", new String[] {}); assertThat(result).asList().contains("foo"); }
public void testWildcardCaptured_typeVariableDeclaresTypeBound_wildcardHasExplicitUpperBound() throws Exception { TypeToken<Counter<? extends Number>> type = new TypeToken<Counter<? extends Number>>() {}; TypeToken<?> fieldType = type.resolveType(Counter.class.getDeclaredField("counts").getGenericType()); Type[] typeArgs = ((ParameterizedType) fieldType.getType()).getActualTypeArguments(); assertThat(typeArgs).asList().hasSize(1); TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0]; assertThat(captured.getBounds()).asList().containsExactly(Number.class); assertThat(new TypeToken<List<? extends Number>>() {}.isSupertypeOf(fieldType)).isTrue(); assertThat(new TypeToken<List<? extends Iterable<?>>>() {}.isSupertypeOf(fieldType)).isFalse(); }
public void testWildcardCaptured_typeVariableDeclaresTypeBound_wildcardHasNoExplicitUpperBound() throws Exception { TypeToken<Counter<?>> type = new TypeToken<Counter<?>>() {}; TypeToken<?> fieldType = type.resolveType(Counter.class.getDeclaredField("counts").getGenericType()); Type[] typeArgs = ((ParameterizedType) fieldType.getType()).getActualTypeArguments(); assertThat(typeArgs).asList().hasSize(1); TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0]; assertThat(captured.getBounds()).asList().containsExactly(Number.class); assertThat(new TypeToken<List<? extends Number>>() {}.isSupertypeOf(fieldType)).isTrue(); assertThat(new TypeToken<List<? extends Iterable<?>>>() {}.isSupertypeOf(fieldType)).isFalse(); }
public void testWildcardCaptured_wildcardWithImplicitBound() throws Exception { TypeToken<Holder<?>> type = new TypeToken<Holder<?>>() {}; ImmutableList<Parameter> parameters = type.method(Holder.class.getDeclaredMethod("setList", List.class)).getParameters(); assertThat(parameters).hasSize(1); TypeToken<?> parameterType = parameters.get(0).getType(); Type[] typeArgs = ((ParameterizedType) parameterType.getType()).getActualTypeArguments(); assertThat(typeArgs).asList().hasSize(1); TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0]; assertThat(captured.getBounds()).asList().containsExactly(Object.class); assertThat(new TypeToken<List<?>>() {}.isSupertypeOf(parameterType)).isTrue(); }
public void testWildcardCaptured_wildcardWithExplicitBound() throws Exception { TypeToken<Holder<? extends Number>> type = new TypeToken<Holder<? extends Number>>() {}; ImmutableList<Parameter> parameters = type.method(Holder.class.getDeclaredMethod("setList", List.class)).getParameters(); assertThat(parameters).hasSize(1); TypeToken<?> parameterType = parameters.get(0).getType(); Type[] typeArgs = ((ParameterizedType) parameterType.getType()).getActualTypeArguments(); assertThat(typeArgs).asList().hasSize(1); TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0]; assertThat(captured.getBounds()).asList().containsExactly(Number.class); assertThat(new TypeToken<List<? extends Number>>() {}.isSupertypeOf(parameterType)).isTrue(); }
@GwtIncompatible // toArray public void testEmptyToArry() { ArrayTable<String, String, Character> table = ArrayTable.create(Arrays.<String>asList(), Arrays.<String>asList()); assertThat(table.toArray(Character.class)).asList().isEmpty(); }
public void testResolveType_parameterizedType() { @SuppressWarnings("rawtypes") // trying to test raw type Parameterized<?, ?, ?> parameterized = new Parameterized<TypeTokenResolutionTest, Bar, String>() {}; TypeResolver typeResolver = TypeResolver.covariantly(parameterized.getClass()); ParameterizedType resolved = (ParameterizedType) typeResolver.resolveType(parameterized.parameterizedType()); assertEquals(TypeTokenResolutionTest.class, resolved.getOwnerType()); assertEquals(Bar.class, resolved.getRawType()); assertThat(resolved.getActualTypeArguments()).asList().contains(String.class); }
public void testPrependTwoElements() { String[] result = ObjectArrays.concat("foo", new String[] {"bar", "baz"}); assertThat(result).asList().containsExactly("foo", "bar", "baz").inOrder(); }
public void testAppendTwoElements() { String[] result = ObjectArrays.concat(new String[] {"foo", "bar"}, "baz"); assertThat(result).asList().containsExactly("foo", "bar", "baz").inOrder(); }
public void testPrependOneElement() { String[] result = ObjectArrays.concat("foo", new String[] {"bar"}); assertThat(result).asList().containsExactly("foo", "bar").inOrder(); }
@GwtIncompatible // ObjectArrays.concat(Object[], Object[], Class) public void testConcatNonemptyEmpty() { String[] result = ObjectArrays.concat(new String[] {"a", "b"}, new String[0], String.class); assertEquals(String[].class, result.getClass()); assertThat(result).asList().containsExactly("a", "b").inOrder(); }
@GwtIncompatible // ObjectArrays.concat(Object[], Object[], Class) public void testConcatBasic() { String[] result = ObjectArrays.concat(new String[] {"a", "b"}, new String[] {"c", "d"}, String.class); assertEquals(String[].class, result.getClass()); assertThat(result).asList().containsExactly("a", "b", "c", "d").inOrder(); }
@GwtIncompatible // ObjectArrays.concat(Object[], Object[], Class) public void testConcatEmptyNonempty() { String[] result = ObjectArrays.concat(new String[0], new String[] {"a", "b"}, String.class); assertEquals(String[].class, result.getClass()); assertThat(result).asList().containsExactly("a", "b").inOrder(); }
public void testGenericArrayType() { @SuppressWarnings("unchecked") // Trying to test generic array ImmutableList<Integer>[] array = new ImmutableList[] {ImmutableList.of(1)}; TypeToken<ImmutableList<Integer>[]> type = new TypeToken<ImmutableList<Integer>[]>() {}; map.putInstance(type, array); assertEquals(1, map.size()); assertThat(map.getInstance(type)).asList().containsExactly(array[0]); }
public void testGenericArrayType() { @SuppressWarnings("unchecked") // Trying to test generic array ImmutableList<Integer>[] array = new ImmutableList[] {ImmutableList.of(1)}; TypeToken<ImmutableList<Integer>[]> type = new TypeToken<ImmutableList<Integer>[]>() {}; ImmutableTypeToInstanceMap<Iterable<?>[]> map = ImmutableTypeToInstanceMap.<Iterable<?>[]>builder().put(type, array).build(); assertEquals(1, map.size()); // Redundant cast works around a javac bug. assertThat((Iterable<?>[]) map.getInstance(type)).asList().containsExactly(array[0]); }