From 672eaed86ce3db574a10226b9b8286b1029b9041 Mon Sep 17 00:00:00 2001 From: Cedomir Igaly Date: Sun, 2 Apr 2023 12:24:55 +0200 Subject: [PATCH] HHH-16261 - More strict test case --- .../test/records/Java14RecordsTest.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Java14RecordsTest.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Java14RecordsTest.java index e965b3b57f..4bccbd5d73 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Java14RecordsTest.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/records/Java14RecordsTest.java @@ -1,13 +1,23 @@ package org.hibernate.jpamodelgen.test.records; +import jakarta.persistence.metamodel.SingularAttribute; import org.hibernate.jpamodelgen.test.util.CompilationTest; import org.hibernate.jpamodelgen.test.util.TestForIssue; import org.hibernate.jpamodelgen.test.util.WithClasses; import org.junit.Test; +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.List; + +import static java.lang.reflect.Modifier.isStatic; import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor; import static org.hibernate.jpamodelgen.test.util.TestUtil.getFieldFromMetamodelFor; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class Java14RecordsTest extends CompilationTest { @@ -16,7 +26,27 @@ public class Java14RecordsTest extends CompilationTest { @WithClasses({Address.class, Author.class}) public void testEmbeddableRecordProperty() { assertMetamodelClassGeneratedFor(Address.class); + for (final String fieldName : List.of("street", "city", "postalCode")) { + assertNotNull("Address must contain '" + fieldName + "' field", getFieldFromMetamodelFor(Address.class, fieldName)); + } assertMetamodelClassGeneratedFor(Author.class); - assertNotNull("Author must contain 'address' field", getFieldFromMetamodelFor(Author.class, "address")); + + final Field addressField = getFieldFromMetamodelFor(Author.class, "address"); + assertNotNull("Author must contain 'address' field", addressField); + assertTrue(isStatic(addressField.getModifiers())); + if (addressField.getGenericType() instanceof ParameterizedType parameterizedType) { + assertEquals(SingularAttribute.class, parameterizedType.getRawType()); + final Type[] typeArguments = parameterizedType.getActualTypeArguments(); + assertEquals(2, typeArguments.length); + assertEquals(Author.class, typeArguments[0]); + assertEquals(Address.class, typeArguments[1]); + } else { + fail("Address field must be instance of ParameterizedType"); + } + + final Field addressNameField = getFieldFromMetamodelFor(Author.class, "address".toUpperCase()); + assertNotNull("Author must contain 'ADDRESS' field", addressNameField); + assertTrue(isStatic(addressNameField.getModifiers())); + assertEquals(String.class, addressNameField.getGenericType()); } }