Skip to content

Commit acaa36e

Browse files
committed
Test that EclipseHelper does not serialize default values
The switch to reading annotations directly from .class files in the EclipseHelper fixed a subtle bug: default values for annotation parameters must not be serialized into the annotation index, but instead be inferred at runtime (in case the default values in the annotation class itself changed). Keep this bug fixed by testing for it in the unit tests. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d56fc95 commit acaa36e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/test/java/org/scijava/annotations/DirectoryIndexerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
import static org.junit.Assert.assertTrue;
3838
import static org.junit.Assume.assumeTrue;
3939

40+
import java.io.BufferedReader;
4041
import java.io.File;
42+
import java.io.FileReader;
4143
import java.io.IOException;
4244
import java.lang.annotation.Annotation;
4345
import java.net.URL;
@@ -91,6 +93,16 @@ public void testIndexer() throws Exception {
9193
readIndex(Complex.class, DirectoryIndexerTest.class.getClassLoader());
9294

9395
testDefaultAnnotations(map);
96+
97+
// verify that default values are not written to the serialized annotation index
98+
final File complex = new File(jsonDirectory, Complex.class.getName());
99+
final BufferedReader reader = new BufferedReader(new FileReader(complex));
100+
for (;;) {
101+
final String line = reader.readLine();
102+
if (line == null) break;
103+
assertTrue("Contains default value 'Q' for char0: " + line, line.indexOf('Q') < 0);
104+
}
105+
reader.close();
94106
}
95107

96108
@Test

0 commit comments

Comments
 (0)