66import com .epam .izh .rd .online .repository .BookRepository ;
77import com .epam .izh .rd .online .service .AuthorService ;
88import com .epam .izh .rd .online .service .BookService ;
9- import com .sun .deploy .util .ReflectionUtil ;
109import org .apache .commons .lang3 .StringUtils ;
1110import org .junit .jupiter .api .DisplayName ;
1211import org .junit .jupiter .api .Test ;
@@ -72,11 +71,10 @@ void testConstructors(Class clazz, Class[] params) {
7271 @ MethodSource ("com.epam.izh.rd.online.Providers#testServiceAndRepositories" )
7372 @ DisplayName ("Проверка наличия классов репозиториев, сервисов и их интерфейсов" )
7473 void testClasses (String canonicalClassName , String interfaceName ) {
75- boolean isClassAvailable = ReflectionUtil
76- .isClassAvailable (canonicalClassName , Thread .currentThread ().getContextClassLoader ());
74+ boolean isClassAvailable = isClassAvailable (canonicalClassName , Thread .currentThread ().getContextClassLoader ());
7775 assertTrue (isClassAvailable , "Не найден класс " + canonicalClassName );
7876
79- Class clazz = ReflectionUtil . getClass (canonicalClassName , Thread .currentThread ().getContextClassLoader ());
77+ Class clazz = getClass (canonicalClassName , Thread .currentThread ().getContextClassLoader ());
8078 List <String > interfacesNames = Arrays .asList (clazz .getInterfaces ()).stream ().map (Class ::getCanonicalName )
8179 .collect (
8280 Collectors .toList ());
@@ -102,7 +100,7 @@ void testEqualsAndHash() {
102100 @ Test
103101 @ DisplayName ("Проверка всей общей логики работы сервисов и репозиториев" )
104102 void testLogic () {
105- Class clazz = ReflectionUtil . getClass ("com.epam.izh.rd.online.repository.SimpleAuthorRepository" ,
103+ Class clazz = getClass ("com.epam.izh.rd.online.repository.SimpleAuthorRepository" ,
106104 Thread .currentThread ().getContextClassLoader ());
107105 AuthorRepository authorRepository = null ;
108106 try {
@@ -113,7 +111,7 @@ void testLogic() {
113111 fail ("Сначала полностью реализуйте всю стрктуру приложения." );
114112 }
115113
116- clazz = ReflectionUtil . getClass ("com.epam.izh.rd.online.repository.SimpleSchoolBookRepository" ,
114+ clazz = getClass ("com.epam.izh.rd.online.repository.SimpleSchoolBookRepository" ,
117115 Thread .currentThread ().getContextClassLoader ());
118116 BookRepository bookRepository = null ;
119117 try {
@@ -124,7 +122,7 @@ void testLogic() {
124122 fail ("Сначала полностью реализуйте всю стрктуру приложения." );
125123 }
126124
127- clazz = ReflectionUtil . getClass ("com.epam.izh.rd.online.service.SimpleAuthorService" ,
125+ clazz = getClass ("com.epam.izh.rd.online.service.SimpleAuthorService" ,
128126 Thread .currentThread ().getContextClassLoader ());
129127 AuthorService authorService = null ;
130128 try {
@@ -136,7 +134,7 @@ void testLogic() {
136134 fail ("Сначала полностью реализуйте всю стрктуру приложения." );
137135 }
138136
139- clazz = ReflectionUtil . getClass ("com.epam.izh.rd.online.service.SimpleSchoolBookService" ,
137+ clazz = getClass ("com.epam.izh.rd.online.service.SimpleSchoolBookService" ,
140138 Thread .currentThread ().getContextClassLoader ());
141139 BookService bookService = null ;
142140 try {
@@ -266,8 +264,7 @@ void testLogic() {
266264 }
267265
268266 private Author getNewInstanceOfAuthor (String name , String lastName , LocalDate birthdate , String country ) {
269- Class clazz = ReflectionUtil
270- .getClass ("com.epam.izh.rd.online.entity.Author" , Thread .currentThread ().getContextClassLoader ());
267+ Class clazz = getClass ("com.epam.izh.rd.online.entity.Author" , Thread .currentThread ().getContextClassLoader ());
271268 try {
272269 Author author = (Author ) clazz .newInstance ();
273270
@@ -286,8 +283,8 @@ private Author getNewInstanceOfAuthor(String name, String lastName, LocalDate bi
286283
287284 private SchoolBook getNewInstanceOfSchoolBook (int numberOfPages , String name , String authorName ,
288285 String authorLastName , LocalDate publishDate ) {
289- Class clazz = ReflectionUtil
290- . getClass ( "com.epam.izh.rd.online.entity.SchoolBook" , Thread .currentThread ().getContextClassLoader ());
286+ Class clazz = getClass (
287+ "com.epam.izh.rd.online.entity.SchoolBook" , Thread .currentThread ().getContextClassLoader ());
291288 try {
292289 SchoolBook schoolBook = (SchoolBook ) clazz .newInstance ();
293290
@@ -312,4 +309,22 @@ private void setValueToField(Class clazz, String fieldName, Object obj, Object v
312309 ReflectionUtils .setField (Objects .requireNonNull (ReflectionUtils .findField (clazz , fieldName )), obj , value );
313310 }
314311
312+
313+ private static Class getClass (String name , ClassLoader classLoader ) {
314+ try {
315+ return Class .forName (name , false , classLoader );
316+ } catch (Throwable e ) {
317+ return null ;
318+ }
319+ }
320+
321+ private static boolean isClassAvailable (String name , ClassLoader classLoader ) {
322+ try {
323+ Class clazz = Class .forName (name , false , classLoader );
324+ return clazz != null ;
325+ } catch (Throwable e ) {
326+ return false ;
327+ }
328+ }
329+
315330}
0 commit comments