예제 #1
0
  @Test
  public void testGetArrayComponentType() throws Exception {
    final Method method =
        getClass()
            .getMethod(
                "dummyMethod",
                List.class,
                List.class,
                List.class,
                List.class,
                List.class,
                List.class,
                List.class,
                List[].class,
                List[].class,
                List[].class,
                List[].class,
                List[].class,
                List[].class,
                List[].class);

    final Type[] types = method.getGenericParameterTypes();

    Assert.assertNull(TypeUtils.getArrayComponentType(types[0]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[1]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[2]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[3]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[4]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[5]));
    Assert.assertNull(TypeUtils.getArrayComponentType(types[6]));
    Assert.assertEquals(types[0], TypeUtils.getArrayComponentType(types[7]));
    Assert.assertEquals(types[1], TypeUtils.getArrayComponentType(types[8]));
    Assert.assertEquals(types[2], TypeUtils.getArrayComponentType(types[9]));
    Assert.assertEquals(types[3], TypeUtils.getArrayComponentType(types[10]));
    Assert.assertEquals(types[4], TypeUtils.getArrayComponentType(types[11]));
    Assert.assertEquals(types[5], TypeUtils.getArrayComponentType(types[12]));
    Assert.assertEquals(types[6], TypeUtils.getArrayComponentType(types[13]));
  }
예제 #2
0
  @Test
  public void testGetPrimitiveArrayComponentType() throws Exception {
    Assert.assertEquals(boolean.class, TypeUtils.getArrayComponentType(boolean[].class));
    Assert.assertEquals(byte.class, TypeUtils.getArrayComponentType(byte[].class));
    Assert.assertEquals(short.class, TypeUtils.getArrayComponentType(short[].class));
    Assert.assertEquals(int.class, TypeUtils.getArrayComponentType(int[].class));
    Assert.assertEquals(char.class, TypeUtils.getArrayComponentType(char[].class));
    Assert.assertEquals(long.class, TypeUtils.getArrayComponentType(long[].class));
    Assert.assertEquals(float.class, TypeUtils.getArrayComponentType(float[].class));
    Assert.assertEquals(double.class, TypeUtils.getArrayComponentType(double[].class));

    Assert.assertNull(TypeUtils.getArrayComponentType(boolean.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(byte.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(short.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(int.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(char.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(long.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(float.class));
    Assert.assertNull(TypeUtils.getArrayComponentType(double.class));
  }