Search in sources :

Example 56 with Type

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

the class TypeCoercerTest method coerceToEnumShouldWorkInList.

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

Example 57 with Type

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

the class TypeCoercerTest method coerceToEnumsShouldWorkWithUpperAndLowerCaseValues.

@Test
public void coerceToEnumsShouldWorkWithUpperAndLowerCaseValues() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfTestEnums").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<String> input = ImmutableList.of("grey", "YELLOW", "red", "PURPLE");
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<TestEnum> expected = ImmutableList.of(TestEnum.grey, TestEnum.yellow, TestEnum.RED, TestEnum.PURPLE);
    assertEquals(expected, result);
}
Also used : Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 58 with Type

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

the class TypeCoercerTest method disallowSubclassOfSuperclass.

/**
   * Cannot declare a field that is not a superclass (i.e. LinkedList instead of List or
   * ImmutableList). Required as TypeCoercer will assign an ImmutableList.
   */
@Test(expected = IllegalArgumentException.class)
public void disallowSubclassOfSuperclass() throws NoSuchFieldException {
    Type type = TestFields.class.getField("subclassOfList").getGenericType();
    typeCoercerFactory.typeCoercerForType(type);
}
Also used : Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 59 with Type

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

the class TypeCoercerTest method hasElementTypesForPair.

@Test
public void hasElementTypesForPair() throws NoSuchFieldException {
    Type type = TestFields.class.getField("pairOfPathsAndStrings").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    assertTrue(coercer.hasElementClass(String.class));
    assertTrue(coercer.hasElementClass(Path.class));
    assertFalse(coercer.hasElementClass(Integer.class));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) Type(java.lang.reflect.Type) Test(org.junit.Test)

Example 60 with Type

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

the class TypeCoercerTest method coerceToEitherLeftOrRightWithCollections.

@Test
public void coerceToEitherLeftOrRightWithCollections() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("eitherStringOrStringList").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    String inputString = "a_string";
    ImmutableList<String> inputList = ImmutableList.of("a", "b");
    assertEquals(Either.ofLeft(inputString), coercer.coerce(cellRoots, filesystem, Paths.get(""), inputString));
    assertEquals(Either.ofRight(inputList), coercer.coerce(cellRoots, filesystem, Paths.get(""), inputList));
}
Also used : Type(java.lang.reflect.Type) 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