Skip to content

Commit b281d8b

Browse files
committed
HHH-17882 test for list of warnings in addSuppressWarningsAnnotation
Signed-off-by: Gavin King <[email protected]>
1 parent 3cfec2f commit b281d8b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/ClassWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ private static String writeSuppressWarnings(Context context) {
204204
final StringBuilder annotation = new StringBuilder("@SuppressWarnings({");
205205
final String[] warnings = context.getSuppressedWarnings();
206206
for (int i = 0; i < warnings.length; i++) {
207-
if ( i>0 ) annotation.append(", ");
207+
if ( i>0 ) {
208+
annotation.append(", ");
209+
}
208210
annotation.append('"').append(warnings[i]).append('"');
209211
}
210212
return annotation.append("})").toString();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.processor.test.supresswarnings;
8+
9+
import org.hibernate.processor.HibernateProcessor;
10+
import org.hibernate.processor.test.util.CompilationTest;
11+
import org.hibernate.processor.test.util.WithClasses;
12+
import org.hibernate.processor.test.util.WithProcessorOption;
13+
import org.junit.Test;
14+
15+
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
16+
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
17+
import static org.junit.Assert.assertTrue;
18+
19+
/**
20+
* @author Hardy Ferentschik
21+
*/
22+
public class SuppressExplicitWarningsAnnotationGeneratedTest extends CompilationTest {
23+
@Test
24+
@WithClasses(TestEntity.class)
25+
@WithProcessorOption(key = HibernateProcessor.ADD_SUPPRESS_WARNINGS_ANNOTATION, value = "foo, bar")
26+
public void testSuppressedWarningsAnnotationGenerated() {
27+
assertMetamodelClassGeneratedFor( TestEntity.class );
28+
29+
// need to check the source because @SuppressWarnings is not a runtime annotation
30+
String metaModelSource = getMetaModelSourceAsString( TestEntity.class );
31+
assertTrue(
32+
"@SuppressWarnings should be added to the metamodel.",
33+
metaModelSource.contains( "@SuppressWarnings({\"foo\", \"bar\"})" )
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)