|
| 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.data.multivaluebinding; |
| 6 | + |
| 7 | +import jakarta.persistence.EntityManager; |
| 8 | +import org.hibernate.processor.test.util.CompilationTest; |
| 9 | +import org.hibernate.processor.test.util.WithClasses; |
| 10 | +import org.junit.Test; |
| 11 | + |
| 12 | +import java.lang.reflect.Method; |
| 13 | +import java.lang.reflect.ParameterizedType; |
| 14 | +import java.lang.reflect.Type; |
| 15 | +import java.util.Collection; |
| 16 | +import java.util.List; |
| 17 | + |
| 18 | +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; |
| 19 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor; |
| 20 | +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; |
| 21 | +import static org.hibernate.processor.test.util.TestUtil.getMethodFromMetamodelFor; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 23 | +import static org.junit.jupiter.api.Assertions.fail; |
| 24 | + |
| 25 | +public class TopicPostTest extends CompilationTest { |
| 26 | + @Test |
| 27 | + @WithClasses({Post.class, PostRepository.class}) |
| 28 | + public void test() { |
| 29 | + assertMetamodelClassGeneratedFor( Post.class, true ); |
| 30 | + assertMetamodelClassGeneratedFor( Post.class ); |
| 31 | + assertMetamodelClassGeneratedFor( PostRepository.class ); |
| 32 | + |
| 33 | + assertPresenceOfMethodInMetamodelFor( Post.class, "getPostsByName", EntityManager.class, List.class ); |
| 34 | + final Method method = getMethodFromMetamodelFor( Post.class, "getPostsByName", EntityManager.class, List.class ); |
| 35 | + final Type methodParam = method.getGenericParameterTypes()[1]; |
| 36 | + if ( methodParam instanceof ParameterizedType parameterized ) { |
| 37 | + assertEquals( String.class, parameterized.getActualTypeArguments()[0] ); |
| 38 | + } |
| 39 | + else { |
| 40 | + fail(); |
| 41 | + } |
| 42 | + |
| 43 | + assertPresenceOfMethodInMetamodelFor( PostRepository.class, "getPostsByName", Collection.class ); |
| 44 | + final Method repositoryMethod = getMethodFromMetamodelFor( PostRepository.class, "getPostsByName", Collection.class ); |
| 45 | + final Type repositoryMethodParam = repositoryMethod.getGenericParameterTypes()[0]; |
| 46 | + if ( repositoryMethodParam instanceof ParameterizedType parameterized ) { |
| 47 | + assertEquals( String.class, parameterized.getActualTypeArguments()[0] ); |
| 48 | + } |
| 49 | + else { |
| 50 | + fail(); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments