BridgeMethodMappingStoreImpl implements BridgeMethodMappingStore { @Override public Class<?>[] getTargetParamsTypes(final Class<?> clazz, final String methodName, final Class<?>[] erasedParamTypes) { if (!map.containsKey(clazz)) { processBridgeMethodMappingsAnnotation(clazz); } Map<String, Map<String, Class<?>[]>> methodNameMap = map.get(clazz); Map<String, Class<?>[]> erasedParamTypesMap = null; Class<?>[] targetParamTypes = null; if (methodNameMap != null) { erasedParamTypesMap = methodNameMap.get(methodName); } String key = Arrays.toString(erasedParamTypes); if (erasedParamTypesMap != null) { targetParamTypes = erasedParamTypesMap.get(key); } if (targetParamTypes == null) { throw new RuntimeException(String.format( "Annotation [%s] must be defined on [%s] for bridge method [%s] with erased param types [%s]", BridgeMethodMappings.class.getName(), clazz.getName(), methodName, key)); } return targetParamTypes; }  @Override Class<?>[] getTargetParamsTypes(final Class<?> clazz, final String methodName, final Class<?>[] erasedParamTypes);  }
@Test public void testValid() { Class<?>[] targetParamTypes = store.getTargetParamsTypes(SubGeneric1.class, "set", new Class<?>[] { Object.class, Object.class }); assertNotNull(targetParamTypes); assertEquals(Number.class, targetParamTypes[0]); assertEquals(String.class, targetParamTypes[1]); targetParamTypes = store.getTargetParamsTypes(SubGeneric1.class, "set", new Class<?>[] { Object.class, Object.class }); assertNotNull(targetParamTypes); assertEquals(Number.class, targetParamTypes[0]); assertEquals(String.class, targetParamTypes[1]); targetParamTypes = store.getTargetParamsTypes(SubGeneric1.class, "get", new Class<?>[] { Object.class }); assertNotNull(targetParamTypes); assertEquals(Number.class, targetParamTypes[0]); targetParamTypes = store.getTargetParamsTypes(SubGeneric1.class, "put", new Class<?>[] { Object.class, Object.class, boolean.class }); assertNotNull(targetParamTypes); assertEquals(Number.class, targetParamTypes[0]); assertEquals(String.class, targetParamTypes[1]); assertEquals(boolean.class, targetParamTypes[2]); }
@Test(expected = RuntimeException.class) public void testNoMappingsAnnotation() { store.getTargetParamsTypes(SubGeneric2.class, "set", new Class<?>[] { Object.class, Object.class }); }
@Test(expected = InvalidAnnotationException.class) public void testWrongMappings() { store.getTargetParamsTypes(SubGeneric3.class, "set", new Class<?>[] { Object.class, Object.class }); }