### Question:
RosettaMapperFactory implements ResultSetMapperFactory { static Type determineGenericReturnType(Class rawType, Type returnType) { if (rawType == returnType || !(returnType instanceof ParameterizedType)) { return rawType; } else { ParameterizedType parameterizedType = (ParameterizedType) returnType; if (rawType == parameterizedType.getRawType()) { return parameterizedType; } else if (parameterizedType.getActualTypeArguments().length == 1) { return determineGenericReturnType(rawType, parameterizedType.getActualTypeArguments()[0]); } else { return rawType; } } }  @Override boolean accepts(@SuppressWarnings("rawtypes") Class type, StatementContext ctx); @Override @SuppressWarnings({ "rawtypes", "unchecked" }) ResultSetMapper mapperFor(Class rawType, StatementContext ctx);  }### Answer:
@Test public void itHandlesGenericType() { Type type = determineGenericReturnType(GenericBean.class, returnTypeForMethod("genericType")); assertThat(type).isInstanceOf(ParameterizedType.class); ParameterizedType genericType = (ParameterizedType) type; assertThat(genericType.getRawType()).isEqualTo(GenericBean.class); assertThat(genericType.getActualTypeArguments()).containsExactly(CircularBean.class); }
@Test public void itHandlesPrimitives() { Type type = determineGenericReturnType(int.class, returnTypeForMethod("primitive")); assertThat(type).isEqualTo(int.class); }
@Test public void itHandlesPrimitiveWrappers() { Type type = determineGenericReturnType(Integer.class, returnTypeForMethod("primitiveWrapper")); assertThat(type).isEqualTo(Integer.class); }
@Test public void itHandlesListOfConcreteType() { Type type = determineGenericReturnType(CircularBean.class, returnTypeForMethod("listOfConcreteType")); assertThat(type).isEqualTo(CircularBean.class); }
@Test public void itHandlesListOfGenericType() { Type type = determineGenericReturnType(GenericBean.class, returnTypeForMethod("listOfGenericType")); assertThat(type).isInstanceOf(ParameterizedType.class); ParameterizedType genericType = (ParameterizedType) type; assertThat(genericType.getRawType()).isEqualTo(GenericBean.class); assertThat(genericType.getActualTypeArguments()).containsExactly(CircularBean.class); }
@Test public void itHandlesListOfPrimitiveWrappers() { Type type = determineGenericReturnType(Integer.class, returnTypeForMethod("listOfPrimitiveWrapper")); assertThat(type).isEqualTo(Integer.class); }
@Test public void itHandlesConcreteType() { Type type = determineGenericReturnType(CircularBean.class, returnTypeForMethod("concreteType")); assertThat(type).isEqualTo(CircularBean.class); }