Search in sources :

Example 61 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method traverseWithEitherAndContainer.

@Test
public void traverseWithEitherAndContainer() throws NoSuchFieldException {
    Type type = TestFields.class.getField("eitherStringOrStringList").getGenericType();
    @SuppressWarnings("unchecked") TypeCoercer<Either<String, List<String>>> coercer = (TypeCoercer<Either<String, List<String>>>) typeCoercerFactory.typeCoercerForType(type);
    TestTraversal traversal = new TestTraversal();
    Either<String, List<String>> input = Either.ofRight((List<String>) ImmutableList.of("foo"));
    coercer.traverse(input, traversal);
    assertThat(traversal.getObjects(), Matchers.contains(ImmutableList.of(sameInstance((Object) input.getRight()), sameInstance((Object) input.getRight().get(0)))));
    traversal = new TestTraversal();
    Either<String, List<String>> input2 = Either.ofLeft("foo");
    coercer.traverse(input2, traversal);
    assertThat(traversal.getObjects(), hasSize(1));
    assertThat(traversal.getObjects().get(0), sameInstance((Object) "foo"));
}
Also used : Type(java.lang.reflect.Type) Either(com.facebook.buck.model.Either) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 62 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method traverseShouldVisitEveryObject.

/**
   * Traverse visits every element of an input value without coercing to the output type.
   */
@Test
public void traverseShouldVisitEveryObject() throws NoSuchFieldException {
    Type type = TestFields.class.getField("stringMapOfLists").getGenericType();
    @SuppressWarnings("unchecked") TypeCoercer<ImmutableMap<String, ImmutableList<String>>> coercer = (TypeCoercer<ImmutableMap<String, ImmutableList<String>>>) typeCoercerFactory.typeCoercerForType(type);
    final ImmutableMap<String, ImmutableList<String>> input = ImmutableMap.of("foo", ImmutableList.of("//foo:bar", "//foo:baz"), "bar", ImmutableList.of(":bar", "//foo:foo"));
    TestTraversal traversal = new TestTraversal();
    coercer.traverse(input, traversal);
    Matcher<Iterable<?>> matcher = Matchers.contains(ImmutableList.of(sameInstance((Object) input), is((Object) "foo"), sameInstance((Object) input.get("foo")), is((Object) "//foo:bar"), is((Object) "//foo:baz"), is((Object) "bar"), sameInstance((Object) input.get("bar")), is((Object) ":bar"), is((Object) "//foo:foo")));
    assertThat(traversal.getObjects(), matcher);
}
Also used : Type(java.lang.reflect.Type) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 63 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method coercingHeterogeneousAppleSourceGroups.

@Test
public void coercingHeterogeneousAppleSourceGroups() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfSourcesWithFlags").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<?> input = ImmutableList.of("Group1/foo.m", ImmutableList.of("Group1/bar.m", ImmutableList.of("-Wall", "-Werror")), "Group2/baz.m", ImmutableList.of("Group2/blech.m", ImmutableList.of("-fobjc-arc")));
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<SourceWithFlags> expectedResult = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m")), SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall", "-Werror")), SourceWithFlags.of(new FakeSourcePath("Group2/baz.m")), SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")));
    assertEquals(expectedResult, result);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Type(java.lang.reflect.Type) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Test(org.junit.Test)

Example 64 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method shouldAllowListTypeToBeSuperclassOfResult.

@Test
public void shouldAllowListTypeToBeSuperclassOfResult() throws CoerceFailedException, NoSuchFieldException {
    Type type = TestFields.class.getField("superclassOfImmutableList").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<String> input = ImmutableList.of("a", "b", "c");
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    assertEquals(ImmutableList.of("a", "b", "c"), result);
}
Also used : Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 65 with Type

use of java.lang.reflect.Type in project buck by facebook.

the class TypeCoercerTest method coerceToNeededCoverageSpec.

@Test
public void coerceToNeededCoverageSpec() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfNeededCoverageSpecs").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<?> input = ImmutableList.of(ImmutableList.of(0.0, "//some:build-target"), ImmutableList.of(0.9, "//other/build:target"), ImmutableList.of(1.0, "//:target", "some/path.py"));
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<NeededCoverageSpec> expectedResult = ImmutableList.of(NeededCoverageSpec.of(0.0f, BuildTargetFactory.newInstance("//some:build-target"), Optional.empty()), NeededCoverageSpec.of(0.9f, BuildTargetFactory.newInstance("//other/build:target"), Optional.empty()), NeededCoverageSpec.of(1.0f, BuildTargetFactory.newInstance("//:target"), Optional.of("some/path.py")));
    assertEquals(expectedResult, result);
}
Also used : Type(java.lang.reflect.Type) NeededCoverageSpec(com.facebook.buck.python.NeededCoverageSpec) Test(org.junit.Test)

Aggregations

Type (java.lang.reflect.Type)6423 ParameterizedType (java.lang.reflect.ParameterizedType)1761 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)722 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)722 GenericArrayType (java.lang.reflect.GenericArrayType)690 WildcardType (java.lang.reflect.WildcardType)571 Test (org.junit.Test)512 ArrayList (java.util.ArrayList)427 Method (java.lang.reflect.Method)416 TypeVariable (java.lang.reflect.TypeVariable)337 List (java.util.List)335 Map (java.util.Map)289 Gson (com.google.gson.Gson)231 V1Status (io.kubernetes.client.models.V1Status)228 V1Status (io.kubernetes.client.openapi.models.V1Status)224 HashMap (java.util.HashMap)204 Field (java.lang.reflect.Field)163 Annotation (java.lang.annotation.Annotation)160 IOException (java.io.IOException)140 Collection (java.util.Collection)111