Skip to content

Commit

Permalink
Search type by name instead of canonical name in ClassGraphFacade
Browse files Browse the repository at this point in the history
Before this commit, searching for a matching type by canonical
name does not return concrete inner types.

This commit uses the type's name (instead of its canonical name)
to look for concrete types in the classpath.

Resolves issue #353
  • Loading branch information
fmbenhassine committed May 2, 2019
1 parent 816b0d6 commit cd88f4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static <T> List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type
}

private static <T> List<Class<?>> searchForPublicConcreteSubTypesOf(final Class<T> type) {
String typeName = type.getCanonicalName();
String typeName = type.getName();
ClassInfoList subTypes = type.isInterface() ? scanResult.getClassesImplementing(typeName) : scanResult.getSubclasses(typeName);
List<Class<?>> loadedSubTypes = subTypes.filter(subType -> subType.isPublic() && !subType.isAbstract()).loadClasses(true);
return Collections.unmodifiableList(loadedSubTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.Date;

import org.assertj.core.api.Assertions;
import org.jeasy.random.EasyRandom;
import org.jeasy.random.EasyRandomParameters;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -118,4 +119,32 @@ public void whenScanClasspathForConcreteTypesIsEnabled_thenShouldPopulateAbstrac

then(randomValue.getTestEnum()).isNotNull();
}

// issue https://github.com/j-easy/easy-random/issues/353

@Test
void testScanClasspathForConcreteTypes_whenConcreteTypeIsAnInnerClass() {
EasyRandomParameters parameters =
new EasyRandomParameters().scanClasspathForConcreteTypes(true);
EasyRandom easyRandom = new EasyRandom(parameters);

Foobar foobar = easyRandom.nextObject(Foobar.class);

Assertions.assertThat(foobar).isNotNull();
Assertions.assertThat(foobar.getToto()).isNotNull();
}

public class Foobar {

public abstract class Toto {}

public class TotoImpl extends Toto {}

private Toto toto;

public Toto getToto() {
return toto;
}
}

}

0 comments on commit cd88f4d

Please sign in to comment.