|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.processor.test.resultclass; |
| 6 | + |
| 7 | +import jakarta.persistence.EntityManager; |
| 8 | +import org.assertj.core.api.Assertions; |
| 9 | +import org.hibernate.processor.test.util.CompilationTest; |
| 10 | +import org.hibernate.processor.test.util.WithClasses; |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import java.lang.reflect.Method; |
| 14 | +import java.lang.reflect.ParameterizedType; |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; |
| 18 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor; |
| 19 | +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; |
| 20 | +import static org.hibernate.processor.test.util.TestUtil.getMethodFromMetamodelFor; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | + |
| 23 | +public class ResultClassTest extends CompilationTest { |
| 24 | + @Test |
| 25 | + @WithClasses({Post.class, NameValue.class}) |
| 26 | + public void test() { |
| 27 | + System.out.println( getMetaModelSourceAsString( Post.class ) ); |
| 28 | + assertMetamodelClassGeneratedFor( Post.class ); |
| 29 | + |
| 30 | + assertPresenceOfMethodInMetamodelFor( Post.class, "getNameValue", EntityManager.class ); |
| 31 | + final Method method = getMethodFromMetamodelFor( Post.class, "getNameValue", EntityManager.class ); |
| 32 | + if ( method.getGenericReturnType() instanceof ParameterizedType parameterized ) { |
| 33 | + assertEquals( List.class, parameterized.getRawType() ); |
| 34 | + assertEquals( NameValue.class, parameterized.getActualTypeArguments()[0] ); |
| 35 | + } |
| 36 | + else { |
| 37 | + Assertions.fail(); |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments