Add test cases for GenericTypeHelper class
Hi there,
This commit adds test cases for uncovered/partially covered methods `isAssignableFrom` and `getActualReturnType` for `GenericTypeHelper` class in package `com.google.devtools.common.options`. Please feel free to request any changes needed.
Closes
@@ -16,6 +16,7 @@ package com.google.devtools.common.options;
import static com.google.common.truth.Truth.assertThat;
+import com.google.common.reflect.TypeToken;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -72,4 +73,34 @@ public class GenericTypeHelperTest {
public void getConverterTypeForGenericExtensionSecondGrade() throws Exception {
assertDoIt(String.class, AlphabetTwoSomething.class);
}
+
+ @Test
+ public void getConverterTypeForParameterizedType() throws Exception {
+ TypeToken<EnumSomething<String>> enSthTypeToken = new TypeToken<>() {};
+ EnumSomething<String> instance = new EnumSomething<>();
+ assertThat(
+ GenericTypeHelper.getActualReturnType(
+ enSthTypeToken.getType(), instance.getClass().getMethod("doIt")))
+ .isEqualTo(String.class);
+ }
+
+ @Test
+ public void assignableFromPrimitive() {
+ assertThat(GenericTypeHelper.isAssignableFrom(Integer.TYPE, Integer.class)).isTrue();
+ assertThat(GenericTypeHelper.isAssignableFrom(Integer.TYPE, Long.TYPE)).isFalse();
+ assertThat(GenericTypeHelper.isAssignableFrom(Integer.TYPE, Integer.TYPE)).isFalse();
+ }
+
+ @Test
+ public void assignableFromSuper() {
+ assertThat(GenericTypeHelper.isAssignableFrom(DoSomething.class, EnumSomething.class)).isTrue();
+ assertThat(GenericTypeHelper.isAssignableFrom(EnumSomething.class, AlphabetSomething.class))
+ .isTrue();
+ }
+
+ @Test
+ public void assignableFromSuperSecondGrade() {
+ assertThat(GenericTypeHelper.isAssignableFrom(EnumSomething.class, AlphabetTwoSomething.class))
+ .isTrue();
+ }
}
