private final String RESOLVER_VALUE = "RESOLVER_KEY_!_!@)_#";
/** Make sure the simple set/get work as required. */
public void testBasic() {
// initialise:
CaretAnnotations annotations = new CaretAnnotations();
// simple set-get
annotations.setAnnotation(TEST_KEY, TEST_VALUE);
assertTrue("Must have a set annotation.",
annotations.hasAnnotation(TEST_KEY));
assertTrue("Must be annotated with the key/value pair set.",
annotations.isAnnotated(TEST_KEY, TEST_VALUE));
assertEquals("Get annotation must match the set value.",
annotations.getAnnotation(TEST_KEY), TEST_VALUE);
assertTrue("Must have the set annotation in key set.",
annotations.getAnnotationKeys().contains(TEST_KEY));
// reset the key to null (not the same as remove)
annotations.setAnnotation(TEST_KEY, null);
assertTrue("Must have a set annotation.",
annotations.hasAnnotation(TEST_KEY));
assertFalse("Must no longer be annotated with the key/value pair set.",
annotations.isAnnotated(TEST_KEY, TEST_VALUE));
assertNull("Get annotation must match the set value.",
annotations.getAnnotation(TEST_KEY));
assertTrue("Must have the set annotation in key set.",
annotations.getAnnotationKeys().contains(TEST_KEY));
// remove the key
annotations.removeAnnotation(TEST_KEY);
assertFalse("Must not have a removed annotation.",
annotations.hasAnnotation(TEST_KEY));
assertNull("Get annotation for removed key should be null.",
annotations.getAnnotation(TEST_KEY));
assertFalse("Must not have removed annotation in key set.",
annotations.getAnnotationKeys().contains(TEST_KEY));
// test clearing, then setting multiple:
annotations.setAnnotation(TEST_KEY, TEST_VALUE);
assertEquals("Must have the right size key set.",
annotations.getAnnotationKeys().size(), 1);
annotations.clear();
assertEquals("Must have empty key set after clear.",
annotations.getAnnotationKeys().size(), 0);
// test setting many:
for (int i = 0; i < 10; i++) {
annotations.setAnnotation("" + i, "" + i);
}
assertEquals("Must have the right number of annotations.",
annotations.getAnnotationKeys().size(), 10);
assertEquals("Must keep annotations when setting multiple.",
annotations.getAnnotation("4"), "4"); // check random one in the middle.
}