@Test public void testMatches() { String prefix = UUID.randomUUID().toString(); String mainContent = UUID.randomUUID().toString(); String suffix = UUID.randomUUID().toString(); NoteData noteListData = new NoteData(); noteListData.setContent(prefix + mainContent + suffix); noteListData.setId(1L); NoteService noteService = EasyMock.createMock(NoteService.class); EasyMock.expect(noteService.getNote(EasyMock.anyLong(), EasyMock.anyObject(Converter.class))) .andReturn(noteListData.getContent()).anyTimes(); EasyMock.replay(noteService); Matcher<NoteData> matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.ANYWHERE); Assert.assertTrue(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.ANYWHERE, prefix, mainContent, suffix); Assert.assertTrue(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.ANYWHERE, UUID .randomUUID().toString()); Assert.assertFalse(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.START, prefix); Assert.assertTrue(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.START, mainContent); Assert.assertFalse(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.END, suffix); Assert.assertTrue(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.END, mainContent); Assert.assertFalse(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.EXACT, prefix + mainContent + suffix); Assert.assertTrue(matcher.matches(noteListData)); matcher = new FullTextSearchFiltersMatcher(noteService, MatchMode.EXACT, mainContent); Assert.assertFalse(matcher.matches(noteListData)); }
@Override public boolean matches(NoteData entity) { if (fullTextSearchFilters == null || fullTextSearchFilters.length == 0) { return true; } String content = noteService.getNote(entity.getId(), new Converter<Note, String>() { @Override public String convert(Note source) { return source.getContent().getContent().toLowerCase(); } }); boolean matches = false; if (content != null) { for (String searchFilter : fullTextSearchFilters) { searchFilter = searchFilter.toLowerCase(); if (MatchMode.ANYWHERE.equals(matchMode)) { matches = content.contains(searchFilter); } else if (MatchMode.START.equals(matchMode)) { matches = content.startsWith(searchFilter); } else if (MatchMode.END.equals(matchMode)) { matches = content.endsWith(searchFilter); } else if (MatchMode.EXACT.equals(matchMode)) { matches = content.equals(searchFilter); } if (!matches) { return false; } } } return matches; }
FullTextSearchFiltersMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (fullTextSearchFilters == null || fullTextSearchFilters.length == 0) { return true; } String content = noteService.getNote(entity.getId(), new Converter<Note, String>() { @Override public String convert(Note source) { return source.getContent().getContent().toLowerCase(); } }); boolean matches = false; if (content != null) { for (String searchFilter : fullTextSearchFilters) { searchFilter = searchFilter.toLowerCase(); if (MatchMode.ANYWHERE.equals(matchMode)) { matches = content.contains(searchFilter); } else if (MatchMode.START.equals(matchMode)) { matches = content.startsWith(searchFilter); } else if (MatchMode.END.equals(matchMode)) { matches = content.endsWith(searchFilter); } else if (MatchMode.EXACT.equals(matchMode)) { matches = content.equals(searchFilter); } if (!matches) { return false; } } } return matches; } }
FullTextSearchFiltersMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (fullTextSearchFilters == null || fullTextSearchFilters.length == 0) { return true; } String content = noteService.getNote(entity.getId(), new Converter<Note, String>() { @Override public String convert(Note source) { return source.getContent().getContent().toLowerCase(); } }); boolean matches = false; if (content != null) { for (String searchFilter : fullTextSearchFilters) { searchFilter = searchFilter.toLowerCase(); if (MatchMode.ANYWHERE.equals(matchMode)) { matches = content.contains(searchFilter); } else if (MatchMode.START.equals(matchMode)) { matches = content.startsWith(searchFilter); } else if (MatchMode.END.equals(matchMode)) { matches = content.endsWith(searchFilter); } else if (MatchMode.EXACT.equals(matchMode)) { matches = content.equals(searchFilter); } if (!matches) { return false; } } } return matches; } FullTextSearchFiltersMatcher(NoteService noteService, MatchMode matchMode,
            String... fullTextSearchFilters); }
FullTextSearchFiltersMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (fullTextSearchFilters == null || fullTextSearchFilters.length == 0) { return true; } String content = noteService.getNote(entity.getId(), new Converter<Note, String>() { @Override public String convert(Note source) { return source.getContent().getContent().toLowerCase(); } }); boolean matches = false; if (content != null) { for (String searchFilter : fullTextSearchFilters) { searchFilter = searchFilter.toLowerCase(); if (MatchMode.ANYWHERE.equals(matchMode)) { matches = content.contains(searchFilter); } else if (MatchMode.START.equals(matchMode)) { matches = content.startsWith(searchFilter); } else if (MatchMode.END.equals(matchMode)) { matches = content.endsWith(searchFilter); } else if (MatchMode.EXACT.equals(matchMode)) { matches = content.equals(searchFilter); } if (!matches) { return false; } } } return matches; } FullTextSearchFiltersMatcher(NoteService noteService, MatchMode matchMode,
            String... fullTextSearchFilters); @Override boolean matches(NoteData entity); }
FullTextSearchFiltersMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (fullTextSearchFilters == null || fullTextSearchFilters.length == 0) { return true; } String content = noteService.getNote(entity.getId(), new Converter<Note, String>() { @Override public String convert(Note source) { return source.getContent().getContent().toLowerCase(); } }); boolean matches = false; if (content != null) { for (String searchFilter : fullTextSearchFilters) { searchFilter = searchFilter.toLowerCase(); if (MatchMode.ANYWHERE.equals(matchMode)) { matches = content.contains(searchFilter); } else if (MatchMode.START.equals(matchMode)) { matches = content.startsWith(searchFilter); } else if (MatchMode.END.equals(matchMode)) { matches = content.endsWith(searchFilter); } else if (MatchMode.EXACT.equals(matchMode)) { matches = content.equals(searchFilter); } if (!matches) { return false; } } } return matches; } FullTextSearchFiltersMatcher(NoteService noteService, MatchMode matchMode,
            String... fullTextSearchFilters); @Override boolean matches(NoteData entity);  }