NameLookupServiceImpl implements NameLookupService { static boolean nameExists(StringBuilder sb, String name) { int index = sb.indexOf(name); while (index != -1) { final int end = index + name.length(); if ((sb.length() == end || sb.charAt(end) == '.') && (index == 0 || sb.charAt(index-1) == '.')) { return true; } index = sb.indexOf(name, end + 1); } return false; } NameLookupServiceImpl(Project project); String[] getNames(); NavigationItem[] findItem(final String name);  }
@Test public void test_nameExists(){ StringBuilder sb = new StringBuilder("name1"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name21.name1"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name21.name1.top"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name1.name12.top"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name1.name13.top"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name198.name13.top.name1"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name198.name13.name1.top.name12"); assertTrue(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name12"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name12.name17"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name21.name.top"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("name14.name12.top"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("supername1.name12.top"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("supername1.name12.topname1"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); sb = new StringBuilder("supername1.aname1.topname1"); assertFalse(NameLookupServiceImpl.nameExists(sb, "name1")); }