use of org.mamute.dto.KarmaAndContext in project mamute by caelum.
the class ReputationEventDAOTest method should_group_reputation_karma_reward_by_post.
@Test
public void should_group_reputation_karma_reward_by_post() throws Exception {
ReputationEvent event1Question1 = event30MinAgo(EventType.ANSWER_DOWNVOTE);
ReputationEvent event2Question1 = event30MinAgo(EventType.QUESTION_DOWNVOTE);
Integer question1Karma = event1Question1.getKarmaReward() + event2Question1.getKarmaReward();
ReputationEvent event1Question2 = new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved2, author);
ReputationEvent event2Question2 = new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved2, author);
Integer question2Karma = event1Question2.getKarmaReward() + event2Question2.getKarmaReward();
ReputationEvent eventOut = TimeMachine.goTo(new DateTime().minusHours(2)).andExecute(new Block<ReputationEvent>() {
@Override
public ReputationEvent run() {
return new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved3, author);
}
});
session.save(eventOut);
session.save(event1Question1);
session.save(event1Question2);
session.save(event2Question1);
session.save(event2Question2);
KarmaByContextHistory karmaByQuestion = reputationEvents.karmaWonByQuestion(author, new DateTime().minusHours(1));
List<KarmaAndContext> history = karmaByQuestion.getHistory();
assertEquals(2, history.size());
KarmaAndContext ck1 = Iterables.find(history, contextOf(questionInvolved1), null);
assertNotNull(ck1);
KarmaAndContext ck2 = Iterables.find(history, contextOf(questionInvolved2), null);
assertNotNull(ck2);
assertEquals(question1Karma.longValue(), ck1.getKarma().longValue());
assertEquals(question2Karma.longValue(), ck2.getKarma().longValue());
}
use of org.mamute.dto.KarmaAndContext in project mamute by caelum.
the class ReputationEventDAOTest method should_group_reputation_karma_reward_by_date.
@Test
public void should_group_reputation_karma_reward_by_date() throws Exception {
ReputationEvent event1 = TimeMachine.goTo(new DateTime().minusDays(1)).andExecute(new Block<ReputationEvent>() {
@Override
public ReputationEvent run() {
return new ReputationEvent(EventType.QUESTION_UPVOTE, questionInvolved1, author);
}
});
ReputationEvent event2 = new ReputationEvent(EventType.ANSWER_DOWNVOTE, questionInvolved1, author);
session.save(event2);
session.save(event1);
KarmaByContextHistory karmaByQuestion = reputationEvents.karmaWonByQuestion(author, new DateTime().minusDays(2));
List<KarmaAndContext> history = karmaByQuestion.getHistory();
assertEquals(2, history.size());
assertEquals(questionInvolved1, history.get(1).getContext());
assertEquals(event1.getKarmaReward().longValue(), history.get(1).getKarma().longValue());
assertEquals(questionInvolved1, history.get(0).getContext());
assertEquals(event2.getKarmaReward().longValue(), history.get(0).getKarma().longValue());
}
Aggregations