-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1475 from MikeEdgar/issue-1255
Support for readers and filters to access the Jandex index
- Loading branch information
Showing
7 changed files
with
181 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
core/src/test/java/io/smallrye/openapi/runtime/OpenApiProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package io.smallrye.openapi.runtime; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.UUID; | ||
|
||
import org.jboss.jandex.IndexView; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class OpenApiProcessorTest { | ||
|
||
ClassLoader loader; | ||
|
||
@BeforeEach | ||
void setup() { | ||
this.loader = Thread.currentThread().getContextClassLoader(); | ||
} | ||
|
||
@Test | ||
void testNewInstanceWithNullClassName() { | ||
Object instance = OpenApiProcessor.newInstance(null, loader, OpenApiProcessor.EMPTY_INDEX); | ||
assertNull(instance); | ||
} | ||
|
||
@Test | ||
void testNewInstanceWithNotFoundClassName() { | ||
String invalidClassName = UUID.randomUUID().toString(); | ||
|
||
Throwable thrown = assertThrows(OpenApiRuntimeException.class, | ||
() -> OpenApiProcessor.newInstance(invalidClassName, loader, OpenApiProcessor.EMPTY_INDEX)); | ||
assertEquals(ClassNotFoundException.class, thrown.getCause().getClass()); | ||
} | ||
|
||
@Test | ||
void testNewInstanceWithEmptyIndex() { | ||
IndexAwareObject instance = OpenApiProcessor.newInstance(IndexAwareObject.class.getName(), loader, | ||
OpenApiProcessor.EMPTY_INDEX); | ||
assertNotNull(instance); | ||
assertFalse(instance.defaultConstructorUsed); | ||
assertEquals(0, instance.index.getKnownClasses().size()); | ||
} | ||
|
||
@Test | ||
void testNewInstanceWithIndexUnsupported() { | ||
IndexUnawareObject instance = OpenApiProcessor.newInstance(IndexUnawareObject.class.getName(), loader, | ||
OpenApiProcessor.EMPTY_INDEX); | ||
assertNotNull(instance); | ||
assertTrue(instance.defaultConstructorUsed); | ||
} | ||
|
||
static class IndexAwareObject { | ||
IndexView index; | ||
boolean defaultConstructorUsed; | ||
|
||
IndexAwareObject() { | ||
defaultConstructorUsed = true; | ||
} | ||
|
||
IndexAwareObject(IndexView index) { | ||
this.index = index; | ||
defaultConstructorUsed = false; | ||
} | ||
|
||
IndexAwareObject(Object other) { | ||
defaultConstructorUsed = false; | ||
} | ||
} | ||
|
||
static class IndexUnawareObject { | ||
boolean defaultConstructorUsed; | ||
|
||
IndexUnawareObject() { | ||
defaultConstructorUsed = true; | ||
} | ||
|
||
IndexUnawareObject(Object other) { | ||
defaultConstructorUsed = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters