HHH-17882 test for list of warnings in addSuppressWarningsAnnotation

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-03-29 11:02:18 +01:00 committed by Christian Beikov
parent 16ebcc427b
commit 31b5af94c1
2 changed files with 39 additions and 1 deletions

View File

@ -204,7 +204,9 @@ public final class ClassWriter {
final StringBuilder annotation = new StringBuilder("@SuppressWarnings({");
final String[] warnings = context.getSuppressedWarnings();
for (int i = 0; i < warnings.length; i++) {
if ( i>0 ) annotation.append(", ");
if ( i>0 ) {
annotation.append(", ");
}
annotation.append('"').append(warnings[i]).append('"');
}
return annotation.append("})").toString();

View File

@ -0,0 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.processor.test.supresswarnings;
import org.hibernate.processor.HibernateProcessor;
import org.hibernate.processor.test.util.CompilationTest;
import org.hibernate.processor.test.util.WithClasses;
import org.hibernate.processor.test.util.WithProcessorOption;
import org.junit.Test;
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
import static org.junit.Assert.assertTrue;
/**
* @author Hardy Ferentschik
*/
public class SuppressExplicitWarningsAnnotationGeneratedTest extends CompilationTest {
@Test
@WithClasses(TestEntity.class)
@WithProcessorOption(key = HibernateProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION, value = "foo, bar")
public void testSuppressedWarningsAnnotationGenerated() {
assertMetamodelClassGeneratedFor( TestEntity.class );
// need to check the source because @SuppressWarnings is not a runtime annotation
String metaModelSource = getMetaModelSourceAsString( TestEntity.class );
assertTrue(
"@SuppressWarnings should be added to the metamodel.",
metaModelSource.contains( "@SuppressWarnings({\"foo\", \"bar\"})" )
);
}
}