ClassNameMapper { public void initialize(final List<String> everyPathAsString) { for (String resourcePath : everyPathAsString) { addClassNamesFromFolder(resourcePath); } } ClassNameMapper(); void initialize(final List<String> everyPathAsString); void put(final String simpleClassName, final String fullClassName); String get(final String simpleClassName);  }
@Test public void testInitializeWithEmptyListShouldNotListFiles() { List<String> emptyList = Collections.emptyList(); underTest.initialize(emptyList); verify(fileUtils, never()).listFiles((File) Mockito.any()); }
@Test public void testInitializeWithClassListShouldParseJavaClass() throws IOException { List<String> list = new ArrayList<>(); list.add(FOLDER_NAME); Collection<File> filesInFolder = new ArrayList<>(); String classFileName = "Something.class"; String className = "Something"; File classFile = new File(classFileName); filesInFolder.add(classFile); given(fileUtils.listFiles(FOLDER)).willReturn(filesInFolder); given(javaClassFactory.createJavaClass(classFile)).willReturn(javaClass); given(javaClass.getClassName()).willReturn(className); underTest.initialize(list); verify(javaClassFactory, times(1)).createJavaClass(classFile); }
@Test public void testInitializeWithNonClassListShouldNotParseJavaClass() throws IOException { List<String> list = new ArrayList<>(); list.add(FOLDER_NAME); Collection<File> filesInFolder = new ArrayList<>(); File notClassFile = new File("NotClass.xml"); filesInFolder.add(notClassFile); given(fileUtils.listFiles(FOLDER)).willReturn(filesInFolder); underTest.initialize(list); verify(javaClassFactory, never()).createJavaClass(notClassFile); }
@Test public void testInitializeWithInvalidClassListShouldThrowClassFormatException() throws IOException { List<String> list = new ArrayList<>(); list.add(FOLDER_NAME); Collection<File> filesInFolder = new ArrayList<>(); File invalidClass = new File("InvalidClass.class"); filesInFolder.add(invalidClass); given(fileUtils.listFiles(FOLDER)).willReturn(filesInFolder); given(javaClassFactory.createJavaClass(invalidClass)).willThrow(new ClassFormatException()); Whitebox.setInternalState(underTest, "logger", logger); underTest.initialize(list); verify(logger).info(Mockito.anyString(), Mockito.any(ClassFormatException.class)); }