@Test public void testMatches() { IAnswer<Boolean> answer = new IAnswer<Boolean>() { @Override public Boolean answer() throws Throwable { Long input = (Long) EasyMock.getCurrentArguments()[0]; return input != null && input.equals(1L); } }; FollowManagement followManagement = EasyMock.createMock(FollowManagement.class); expect(followManagement.followsBlog(EasyMock.anyLong())).andAnswer(answer).anyTimes(); expect(followManagement.followsTag(EasyMock.anyLong())).andAnswer(answer).anyTimes(); expect(followManagement.followsUser(EasyMock.anyLong())).andAnswer(answer).anyTimes(); expect(followManagement.followsDiscussion(EasyMock.anyLong())).andAnswer(answer).anyTimes(); EasyMock.replay(followManagement); NoteData note = new NoteData(); note.setBlog(new UserBlogData()); note.setUser(new DetailedUserData()); Matcher<NoteData> matcher = new FollowingMatcher(followManagement); note.setDiscussionId(0L); Assert.assertFalse(matcher.matches(note)); note.setDiscussionId(1L); Assert.assertTrue(matcher.matches(note)); note.setDiscussionId(-1L); Assert.assertFalse(matcher.matches(note)); note.getUser().setId(0L); Assert.assertFalse(matcher.matches(note)); note.getUser().setId(1L); Assert.assertTrue(matcher.matches(note)); note.getUser().setId(-1L); Assert.assertFalse(matcher.matches(note)); note.getBlog().setId(0L); Assert.assertFalse(matcher.matches(note)); note.getBlog().setId(1L); Assert.assertTrue(matcher.matches(note)); note.getBlog().setId(-1L); Assert.assertFalse(matcher.matches(note)); note.setTags(new ArrayList<TagData>()); note.getTags().add(new TagData(0L, "Hallo")); Assert.assertFalse(matcher.matches(note)); note.getTags().add(new TagData(1L, "Hallo")); Assert.assertTrue(matcher.matches(note)); }
@Override public boolean matches(NoteData entity) { if (followManagement.followsBlog(entity.getBlog().getId()) || followManagement.followsUser(entity.getUser().getId()) || followManagement.followsDiscussion(entity.getDiscussionId())) { return true; } if (entity.getTags() != null) { for (TagData tag : entity.getTags()) { if (followManagement.followsTag(tag.getId())) { return true; } } } return false; }
FollowingMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (followManagement.followsBlog(entity.getBlog().getId()) || followManagement.followsUser(entity.getUser().getId()) || followManagement.followsDiscussion(entity.getDiscussionId())) { return true; } if (entity.getTags() != null) { for (TagData tag : entity.getTags()) { if (followManagement.followsTag(tag.getId())) { return true; } } } return false; } }
FollowingMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (followManagement.followsBlog(entity.getBlog().getId()) || followManagement.followsUser(entity.getUser().getId()) || followManagement.followsDiscussion(entity.getDiscussionId())) { return true; } if (entity.getTags() != null) { for (TagData tag : entity.getTags()) { if (followManagement.followsTag(tag.getId())) { return true; } } } return false; } FollowingMatcher(FollowManagement followManagement); }
FollowingMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (followManagement.followsBlog(entity.getBlog().getId()) || followManagement.followsUser(entity.getUser().getId()) || followManagement.followsDiscussion(entity.getDiscussionId())) { return true; } if (entity.getTags() != null) { for (TagData tag : entity.getTags()) { if (followManagement.followsTag(tag.getId())) { return true; } } } return false; } FollowingMatcher(FollowManagement followManagement); @Override boolean matches(NoteData entity); }
FollowingMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (followManagement.followsBlog(entity.getBlog().getId()) || followManagement.followsUser(entity.getUser().getId()) || followManagement.followsDiscussion(entity.getDiscussionId())) { return true; } if (entity.getTags() != null) { for (TagData tag : entity.getTags()) { if (followManagement.followsTag(tag.getId())) { return true; } } } return false; } FollowingMatcher(FollowManagement followManagement); @Override boolean matches(NoteData entity);  }