Skip to content

Commit

Permalink
Entity scan on non-existing data model package silences error (#3197)
Browse files Browse the repository at this point in the history
* Added a step to model checking.Check if the annotated class collection obtained is empty.

* Added a test to model checking.

Solved some problems.

* Change the screwdriver to GitHub Actions. (#10)

The issue has been solved.

* Fixed the import statement.

* Test

* Test

* Replace ci-cd.yml with screwdriver.yaml.
  • Loading branch information
Doom9527 authored Apr 20, 2024
1 parent 57e7a98 commit 19de457
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ public Set<Class<?>> getAnnotatedClasses(Package toScan, Class<? extends Annotat

@Override
public Set<Class<?>> getAnnotatedClasses(String packageName, Class<? extends Annotation> annotation) {
return startupCache.get(annotation.getCanonicalName()).stream()
.filter(clazz ->
clazz.getPackage().getName().equals(packageName)
|| clazz.getPackage().getName().startsWith(packageName + "."))
LinkedHashSet<Class<?>> annotatedClasses = startupCache.get(annotation.getCanonicalName()).stream()
.filter(clazz -> clazz.getPackage().getName().equals(packageName)
|| clazz.getPackage().getName().startsWith(packageName + "."))
.collect(Collectors.toCollection(LinkedHashSet::new));

// Check if the annotated class collection obtained is empty
if (annotatedClasses.isEmpty()) {
throw new IllegalArgumentException("No annotated classes found in the specified package: " + packageName);
}

return annotatedClasses;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package com.yahoo.elide.core.utils;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.yahoo.elide.annotation.Include;
Expand Down Expand Up @@ -53,4 +54,11 @@ public void testGetAnyAnnotatedClasses() {
|| cls.isAnnotationPresent(Entity.class));
}
}

@Test
public void testGetAnnotatedClassesNoClassesFound() {
assertThrows(IllegalArgumentException.class, () -> {
scanner.getAnnotatedClasses("nonexistent.package", Include.class);
}, "No annotated classes found in the specified package: nonexistent.package");
}
}

0 comments on commit 19de457

Please sign in to comment.