@Test
 public void genericErasureWorkaround() {
   SubjectFactory<StringSubject, String> factory =
       new SubjectFactory<StringSubject, String>() {
         @Override
         public StringSubject getSubject(FailureStrategy fs, String target) {
           return new StringSubject(fs, target);
         }
       };
   assertThat(factory.getSubjectClass()).isEqualTo(StringSubject.class);
 }
Exemplo n.º 2
0
  public String build() {
    Class<?> subjectClass = subjectFactory.getSubjectClass();
    List<Method> methods = Arrays.asList(subjectClass.getMethods());
    Class<?> targetType = ReflectionUtil.typeParameter(subjectClass, TARGET_TYPE_PARAMETER);

    StringBuilder methodWrappers = new StringBuilder();
    for (Method m : methods) {
      appendMethodWrapper(methodWrappers, subjectClass, targetType, m);
    }
    String code =
        String.format(
            CLASS_TEMPLATE,
            subjectClass.getPackage().getName(),
            subjectClass.getSimpleName(),
            targetType.getCanonicalName(),
            methodWrappers.toString());

    return code;
  }
Exemplo n.º 3
0
 public IteratingWrapperClassBuilder(SubjectFactory<?, ?> subjectFactory) {
   this.subjectFactory = subjectFactory;
   this.className = subjectFactory.getSubjectClass().getCanonicalName() + ITERATING_WRAPPER;
 }