Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed May 12, 2024
1 parent c04e849 commit 3996b8e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ private ClassLoader createClassLoader() {
throw new CustomResourceClassLoaderException("Could not transform file to URL: " + s, e);
}
}).toArray(URL[]::new);
String urlsAsString = Arrays.toString(urls);
if (parentClassLoader != null) {
log.trace("Using URLClassLoader with parent ClassLoader {} and {}", parentClassLoader, Arrays.toString(urls));
log.trace("Using URLClassLoader with parent ClassLoader {} and {}", parentClassLoader, urlsAsString);
return new URLClassLoader(urls, parentClassLoader);
} else {
log.trace("Using URLClassLoader with {}", Arrays.toString(urls));
log.trace("Using URLClassLoader with {}", urlsAsString);
return new URLClassLoader(urls);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
class JandexUtils {

private static final Logger log = LoggerFactory.getLogger(JandexIndexer.class);
private static final Logger log = LoggerFactory.getLogger(JandexUtils.class);

static final String JAR_FILE_SUFFIX = ".jar";
private static final String DEFAULT_JANDEX_INDEX = "META-INF/jandex.idx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -54,7 +53,7 @@ void givenClassName_thenLoadClassAndSkipScan() {
customResourceCollector.withCustomResourceClass("com.example.Test");

Class<? extends HasMetadata>[] classes = customResourceCollector.findCustomResourceClasses();
verify(customResourceClassLoader, times(1)).loadCustomResourceClass(eq("com.example.Test"));
verify(customResourceClassLoader, times(1)).loadCustomResourceClass("com.example.Test");
verify(jandexCustomResourceClassScanner, times(0)).findCustomResourceClasses();
assertEquals(1, classes.length);
}
Expand All @@ -65,7 +64,7 @@ void givenClassNameAndFileToScan_thenLoadClassAndSkipScan() {
customResourceCollector.withFileToScan(Mockito.mock(File.class));

Class<? extends HasMetadata>[] classes = customResourceCollector.findCustomResourceClasses();
verify(customResourceClassLoader, times(1)).loadCustomResourceClass(eq("com.example.Test"));
verify(customResourceClassLoader, times(1)).loadCustomResourceClass("com.example.Test");
verify(jandexCustomResourceClassScanner, times(0)).findCustomResourceClasses();
assertEquals(1, classes.length);
}
Expand All @@ -80,7 +79,7 @@ void givenClassNameAndFileToScanAndForceScan_thenScan() {
.thenReturn(Arrays.asList("com.example.Test1", "com.example.Test2"));

Class<? extends HasMetadata>[] classes = customResourceCollector.findCustomResourceClasses();
verify(customResourceClassLoader, times(1)).loadCustomResourceClass(eq("com.example.Test"));
verify(customResourceClassLoader, times(1)).loadCustomResourceClass("com.example.Test");
verify(jandexCustomResourceClassScanner, times(1)).findCustomResourceClasses();
assertEquals(3, classes.length);
}
Expand Down Expand Up @@ -173,7 +172,7 @@ void withParentClassLoader_thenDelegate() {
@Test
void withClasspathElement_thenDelegate() {
customResourceCollector.withClasspathElement("path");
verify(customResourceClassLoader, times(1)).withClasspathElement(eq("path"));
verify(customResourceClassLoader, times(1)).withClasspathElement("path");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,29 @@ void setUp() throws DependencyResolutionRequiredException {
}

@Test
void testGetUrlsCompile() {
void checkGetClasspathElementsCompile() {
Set<String> urls = ClasspathType.WITH_COMPILE_DEPENDENCIES.getClasspathElements(this.project);
assertEquals(1, urls.size());
assertTrue(urls.contains(COMPILE_PATH));
}

@Test
void testGetUrlsRuntime() {
void checkGetClasspathElementsRuntime() {
Set<String> urls = ClasspathType.WITH_RUNTIME_DEPENDENCIES.getClasspathElements(this.project);
assertEquals(1, urls.size());
assertTrue(urls.contains(RUNTIME_PATH));
}

@Test
void testGetUrlsAll() {
void checkGetClasspathElementsAll() {
Set<String> urls = ClasspathType.WITH_ALL_DEPENDENCIES.getClasspathElements(this.project);
assertEquals(2, urls.size());
assertTrue(urls.contains(RUNTIME_PATH));
assertTrue(urls.contains(COMPILE_PATH));
}

@Test
void testGetUrlsAllAndTests() {
void checkGetClasspathElementsAllAndTests() {
Set<String> urls = ClasspathType.WITH_ALL_DEPENDENCIES_AND_TESTS.getClasspathElements(this.project);
assertEquals(3, urls.size());
assertTrue(urls.contains(RUNTIME_PATH));
Expand All @@ -85,7 +85,7 @@ void testGetUrlsAllAndTests() {
}

@Test
void testGetUrlsProject() {
void checkGetClasspathElementsProject() {
Set<String> urls = ClasspathType.PROJECT_ONLY.getClasspathElements(this.project);
assertEquals(1, urls.size());
assertTrue(urls.contains(PROJECT_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setup(@TempDir File tempDir) {
when(crdGenerator.inOutputDir(any())).thenReturn(crdGenerator);
when(crdGenerator.withParallelGenerationEnabled(anyBoolean())).thenReturn(crdGenerator);
when(crdGenerator.withImplicitPreserveUnknownFields(anyBoolean())).thenReturn(crdGenerator);
when(crdGenerator.customResourceClasses(ArgumentMatchers.<Class<? extends HasMetadata>>any())).thenReturn(crdGenerator);
when(crdGenerator.customResourceClasses(ArgumentMatchers.<Class<? extends HasMetadata>> any())).thenReturn(crdGenerator);
crdGenerationInfo = Mockito.mock(CRDGenerationInfo.class);
when(crdGenerator.detailedGenerate()).thenReturn(crdGenerationInfo);

Expand Down

0 comments on commit 3996b8e

Please sign in to comment.