4141 * @since 2.0
4242 */
4343public final class CodeListTest {
44+ /**
45+ * Suffix of code list values created by other tests.
46+ * Those values need to be ignored by {@code CodeListTest}.
47+ * We use the {@value} prefix in their name for identifying them.
48+ */
49+ public static final String IGNORABLE_NAME_SUFFIX = "Test" ;
50+
4451 /**
4552 * Creates a new test case.
4653 */
@@ -72,6 +79,7 @@ public void testAll() throws NoSuchFieldException, NoSuchMethodException,
7279 assertTrue (Modifier .isStatic (valuesMethod .getModifiers ()), () -> className + ".values() is not static." );
7380 final ControlledVocabulary [] values = (ControlledVocabulary []) valuesMethod .invoke (null , (Object []) null );
7481 assertNotNull (values , () -> className + ".values() returned null." );
82+ int ignored = 0 ;
7583 /*
7684 * Tests every CodeList instances returned by values().
7785 * Every field should be public, static and final.
@@ -81,6 +89,10 @@ public void testAll() throws NoSuchFieldException, NoSuchMethodException,
8189 final String valueName = value .name ();
8290 final String fullName = className + '.' + valueName ;
8391 assertTrue (codeClass .isInstance (value ), () -> fullName + " is of unexpected type." );
92+ if (valueName .endsWith (IGNORABLE_NAME_SUFFIX )) {
93+ ignored ++;
94+ continue ; // Skip values created in other tests.
95+ }
8496 final Field field = codeClass .getDeclaredField (valueName );
8597 final int modifiers = field .getModifiers ();
8698 if (field .isAnnotationPresent (UML .class )) {
@@ -110,7 +122,7 @@ public void testAll() throws NoSuchFieldException, NoSuchMethodException,
110122 if (CodeList .class .isAssignableFrom (codeClass )) {
111123 final Vocabulary desc = codeClass .getAnnotation (Vocabulary .class );
112124 assertNotNull (desc , () -> className + " has no @Vocabulary annotation." );
113- assertEquals (values .length , desc .capacity (), () -> className + " is not properly sized." );
125+ assertEquals (values .length - ignored , desc .capacity (), () -> className + " is not properly sized." );
114126 /*
115127 * Tests valueOf(String).
116128 */
0 commit comments