* Tests {@link IdentifiedObjects#isHeuristicMatchForName(IdentifiedObject, String)}.
*/
@Test
public void testIsHeuristicMatchForName() {
final GenericName name = DefaultFactories.SIS_NAMES.createGenericName(null, "myScope", "myName");
IdentifiedObjectMock object = new IdentifiedObjectMock("myCode ", name); // Intentional trailing space.
// Test the code.
assertFalse(isHeuristicMatchForName(object, "other"));
assertTrue (isHeuristicMatchForName(object, "myCode"));
assertTrue (isHeuristicMatchForName(object, " my_code "));
assertFalse(isHeuristicMatchForName(object, "testmyCode"));
assertFalse(isHeuristicMatchForName(object, "other:myCode"));
assertFalse(isHeuristicMatchForName(object, "test"));
// Test the alias.
assertTrue (isHeuristicMatchForName(object, "myName"));
assertTrue (isHeuristicMatchForName(object, " My_name "));
assertFalse(isHeuristicMatchForName(object, "myScope"));
assertFalse(isHeuristicMatchForName(object, "other:myName"));
assertFalse(isHeuristicMatchForName(object, "myScope:other"));
assertFalse(isHeuristicMatchForName(object, "other:myScope:myName"));
// Test non-letter and non-digits characters.
object = new IdentifiedObjectMock("Mercator (1SP)", name);
assertTrue (isHeuristicMatchForName(object, "Mercator (1SP)"));
assertTrue (isHeuristicMatchForName(object, "Mercator_1SP"));
assertFalse(isHeuristicMatchForName(object, "Mercator_2SP"));
// Test diacritical signs
object = new IdentifiedObjectMock("Réunion", name);
assertTrue (isHeuristicMatchForName(object, "Réunion"));
assertTrue (isHeuristicMatchForName(object, "Reunion"));
}