/** * It loads a real type of a field defined by parametric type. It searches in declaring class and super class. E. g. if a * field is declared as 'A fieldName', It tries to find type parameter called 'A' in super class declaration and its * evaluation in the class declaring the given field. * * @param field * @param testCase * @return type of the given field */ protected final Class<?> getActualType(Field field, Object testCase) { // e.g. TestPage, HomePage Type[] superClassActualTypeArguments = GenericTypeInspector.getTypeArguments(testCase); // e.g. T, E TypeVariable<?>[] superClassTypeParameters = GenericTypeInspector.getTypeParameters(testCase); // the type parameter has the same index as the actual type String fieldParameterTypeName = field.getGenericType().toString(); int index; for (index = 0; index < superClassTypeParameters.length; index++) { String superClassTypeParameterName = superClassTypeParameters[index].getName(); if (fieldParameterTypeName.equals(superClassTypeParameterName)) { break; } } return (Class<?>) superClassActualTypeArguments[index]; }
@Test public void testGetTypeArguments() { GenericTypeTestUtil.compareTypeArguments( new Class<?>[]{String.class, Integer.class, Double.class}, GenericTypeInspector.getTypeArguments(this)); }
@Test public void testGetTypeParameters() { GenericTypeTestUtil.compareTypeParameters( new String[]{"A", "B", "C"}, GenericTypeInspector.getTypeParameters(this)); } }
@Test public void testGetTypeArguments() { GenericTypeTestUtil.compareTypeArguments( new Class<?>[]{String.class, Integer.class, Double.class}, GenericTypeInspector.getTypeArguments(this)); }
@Test public void testGetTypeParameters() { GenericTypeTestUtil.compareTypeParameters( new String[]{"A", "B", "C"}, GenericTypeInspector.getTypeParameters(this)); } }
/** * It loads a real type of a field defined by parametric type. It searches in declaring class and super class. E. g. if a * field is declared as 'A fieldName', It tries to find type parameter called 'A' in super class declaration and its * evaluation in the class declaring the given field. * * @param field * @param testCase * @return type of the given field */ protected final Class<?> getActualType(Field field, Object testCase) { // e.g. TestPage, HomePage Type[] superClassActualTypeArguments = GenericTypeInspector.getTypeArguments(testCase); // e.g. T, E TypeVariable<?>[] superClassTypeParameters = GenericTypeInspector.getTypeParameters(testCase); // the type parameter has the same index as the actual type String fieldParameterTypeName = field.getGenericType().toString(); int index; for (index = 0; index < superClassTypeParameters.length; index++) { String superClassTypeParameterName = superClassTypeParameters[index].getName(); if (fieldParameterTypeName.equals(superClassTypeParameterName)) { break; } } return (Class<?>) superClassActualTypeArguments[index]; }
@Test public void testGetTypeArguments() { GenericTypeTestUtil.compareTypeArguments( new Class<?>[]{String.class, Integer.class, Double.class}, GenericTypeInspector.getTypeArguments(this)); }
@Test public void testGetTypeParameters() { GenericTypeTestUtil.compareTypeParameters( new String[]{"A", "B", "C"}, GenericTypeInspector.getTypeParameters(this)); } }