|
5 | 5 | import org.hibernate.annotations.Cache;
|
6 | 6 | import org.hibernate.annotations.CacheConcurrencyStrategy;
|
7 | 7 | import org.hibernate.internal.util.MutableInteger;
|
| 8 | +import org.hibernate.models.AnnotationAccessException; |
8 | 9 | import org.hibernate.models.UnknownAnnotationAttributeException;
|
9 | 10 | import org.hibernate.models.spi.MutableAnnotationUsage;
|
10 | 11 | import org.hibernate.models.internal.SourceModelBuildingContextImpl;
|
@@ -369,6 +370,32 @@ void testForEachAnnotation(Index index) {
|
369 | 370 | counter.set( 0 );
|
370 | 371 | classDetails.forEachAnnotationUsage( NamedQuery.class, entityAnnotationUsage -> counter.increment() );
|
371 | 372 | assertThat( counter.get() ).isEqualTo( 2 );
|
| 373 | + } |
| 374 | + |
| 375 | + @Test |
| 376 | + void testGetSingleUsageWithJandex() { |
| 377 | + testGetSingleUsage( buildJandexIndex( SimpleEntity.class ) ); |
| 378 | + } |
| 379 | + |
| 380 | + @Test |
| 381 | + void testGetSingleUsageWithoutJandex() { |
| 382 | + testGetSingleUsage( null ); |
| 383 | + } |
| 384 | + |
| 385 | + void testGetSingleUsage(Index index) { |
| 386 | + final SourceModelBuildingContextImpl buildingContext = createBuildingContext( index, SimpleEntity.class ); |
| 387 | + final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); |
| 388 | + final ClassDetails classDetails = classDetailsRegistry.getClassDetails( SimpleEntity.class.getName() ); |
| 389 | + |
| 390 | + try { |
| 391 | + classDetails.getAnnotationUsage( NamedQuery.class ); |
| 392 | + fail( "Expecting an AnnotationAccessException to be thrown" ); |
| 393 | + } |
| 394 | + catch (AnnotationAccessException expected) { |
| 395 | + // this is expected |
| 396 | + } |
372 | 397 |
|
| 398 | + final AnnotationUsage<NamedQuery> singleAnnotationUsage = classDetails.getSingleAnnotationUsage( NamedQuery.class ); |
| 399 | + assertThat( singleAnnotationUsage ).isNull(); |
373 | 400 | }
|
374 | 401 | }
|
0 commit comments