use of org.mamute.model.Vote in project mamute by caelum.
the class TestCase method vote.
protected Vote vote(User author, VoteType type, Long id) {
Vote v = new Vote(author, type);
setId(v, id);
return v;
}
use of org.mamute.model.Vote in project mamute by caelum.
the class VoteDAOTest method should_return_right_comments_and_currentUser_votes_map.
@Test
public void should_return_right_comments_and_currentUser_votes_map() {
Question question = question(currentUser, tags);
Answer answer = answer("blablablablablablablablablablbalblabla", question, currentUser);
Comment answerComment1 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(1));
Comment answerComment2 = comment(currentUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(2));
Comment answerComment3 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(3));
answer.add(answerComment1);
answer.add(answerComment2);
answer.add(answerComment3);
Comment questionComment1 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(4));
Comment questionComment2 = comment(currentUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(5));
Comment questionComment3 = comment(otherUser, "comentariocomentariocomentariocomentariocomentario", DateTime.now().minusHours(6));
question.add(questionComment1);
question.add(questionComment2);
question.add(questionComment3);
Vote currentUserUpVote1 = upvote(answerComment1, currentUser);
Vote currentUserUpVote2 = upvote(questionComment1, currentUser);
upvote(answerComment2, otherUser);
upvote(questionComment2, otherUser);
session.save(question);
session.save(answer);
session.save(answerComment1);
session.save(answerComment2);
session.save(answerComment3);
CommentsAndVotes commentsAndVotes = votes.previousVotesForComments(question, currentUser);
assertEquals(currentUserUpVote1, commentsAndVotes.getVotes(answerComment1));
assertEquals(currentUserUpVote2, commentsAndVotes.getVotes(questionComment1));
assertEquals(null, commentsAndVotes.getVotes(questionComment2));
assertEquals(null, commentsAndVotes.getVotes(answerComment2));
assertEquals(null, commentsAndVotes.getVotes(questionComment3));
assertEquals(null, commentsAndVotes.getVotes(answerComment3));
}
use of org.mamute.model.Vote in project mamute by caelum.
the class VotingMachineTest method should_recalculate_karma_of_downvoter.
@Test
public void should_recalculate_karma_of_downvoter() throws Exception {
Vote previousVote = new Vote(voter, VoteType.DOWN);
votingMachine.register(votable, previousVote, Question.class);
when(votes.previousVoteFor(votable.getId(), voter, Question.class)).thenReturn(previousVote);
assertEquals(-2l, voter.getKarma());
votingMachine.register(votable, new Vote(voter, VoteType.UP), Question.class);
assertEquals(0l, voter.getKarma());
}
use of org.mamute.model.Vote in project mamute by caelum.
the class VotingMachineTest method should_substitute_vote.
@Test
public void should_substitute_vote() {
Vote previousVote = vote(voter, VoteType.UP, 1l);
votingMachine.register(votable, previousVote, Question.class);
when(votes.previousVoteFor(votable.getId(), voter, Question.class)).thenReturn(previousVote);
Vote newVote = new Vote(voter, VoteType.UP);
votingMachine.register(votable, newVote, Question.class);
assertEquals(1, votable.getVoteCount());
}
use of org.mamute.model.Vote in project mamute by caelum.
the class VotingMachineTest method should_disallow_author_to_vote.
@Test(expected = IllegalArgumentException.class)
public void should_disallow_author_to_vote() throws Exception {
Vote newVote = new Vote(author, VoteType.DOWN);
votingMachine.register(votable, newVote, Question.class);
fail("should throw illegal argument exception");
}
Aggregations