1010import org .hibernate .processor .test .util .WithClasses ;
1111import org .junit .Test ;
1212
13+ import java .lang .reflect .RecordComponent ;
1314import java .util .Arrays ;
1415
1516import static org .hibernate .processor .test .util .TestUtil .getMetamodelClassFor ;
17+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
1618import static org .junit .jupiter .api .Assertions .assertTrue ;
1719
1820@ TestForIssue (jiraKey = " HHH-18829" )
@@ -27,23 +29,25 @@ public void test() {
2729 System .out .println ( TestUtil .getMetaModelSourceAsString ( Address .class ) );
2830 System .out .println ( TestUtil .getMetaModelSourceAsString ( EmployeeWithIdClass .class ) );
2931
30- checkIfIdClassIsGenerated ( Employee .class );
31- checkIfIdClassIsGenerated ( AnotherEmployee .class );
32+ checkIfIdClassIsGenerated ( Employee .class , new String [] { "empName" , "empId" } );
33+ checkIfIdClassIsGenerated ( AnotherEmployee .class , new String [] { "empId" , "empName" } );
3234
3335 final var clazz = getMetamodelClassFor ( EmployeeWithIdClass .class );
3436 assertTrue ( Arrays .stream ( clazz .getClasses () ).map ( Class ::getSimpleName )
3537 .noneMatch ( "Id" ::equals ),
3638 "EmployeeWithIdClass_ should not have inner class Id" );
3739 }
3840
39- private static void checkIfIdClassIsGenerated (Class <?> entityClass ) {
41+ private static void checkIfIdClassIsGenerated (Class <?> entityClass , String [] idComponentNames ) {
4042 final var clazz = getMetamodelClassFor ( entityClass );
4143 final var maybeIdClass = Arrays .stream ( clazz .getClasses () )
4244 .filter ( c -> c .getSimpleName ().equals ( "Id" ) ).findAny ();
4345 assertTrue ( maybeIdClass .isPresent (), () -> clazz .getSimpleName () + "_ should have inner class Id" );
4446 final Class <?> idClass = maybeIdClass .get ();
4547 assertTrue ( idClass .isRecord (), "Generated ID class should be a record" );
46- final var recordComponents = idClass .getRecordComponents ();
47- // TODO : Check record components
48+ assertArrayEquals (
49+ idComponentNames ,
50+ Arrays .stream ( idClass .getRecordComponents () ).map ( RecordComponent ::getName ).toArray ( String []::new )
51+ );
4852 }
4953}
0 commit comments