Search in sources :

Example 1 with Vote

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;
}
Also used : Vote(org.mamute.model.Vote)

Example 2 with Vote

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));
}
Also used : Answer(org.mamute.model.Answer) Comment(org.mamute.model.Comment) CommentsAndVotes(org.mamute.model.CommentsAndVotes) Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) SuspectMassiveVote(org.mamute.dto.SuspectMassiveVote) Question(org.mamute.model.Question) Test(org.junit.Test)

Example 3 with Vote

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());
}
Also used : Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) Test(org.junit.Test)

Example 4 with Vote

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());
}
Also used : Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) Test(org.junit.Test)

Example 5 with Vote

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");
}
Also used : Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) Test(org.junit.Test)

Aggregations

Vote (org.mamute.model.Vote)21 Test (org.junit.Test)13 MassiveVote (org.mamute.model.vote.MassiveVote)10 VotedAtSomethingEvent (org.mamute.reputation.rules.VotedAtSomethingEvent)4 SuspectMassiveVote (org.mamute.dto.SuspectMassiveVote)3 Question (org.mamute.model.Question)3 Answer (org.mamute.model.Answer)2 ReputationEvent (org.mamute.model.ReputationEvent)2 ReputationEventContext (org.mamute.model.ReputationEventContext)2 User (org.mamute.model.User)2 Votable (org.mamute.model.interfaces.Votable)2 ReceivedVoteEvent (org.mamute.reputation.rules.ReceivedVoteEvent)2 ArrayList (java.util.ArrayList)1 Query (org.hibernate.Query)1 DateTime (org.joda.time.DateTime)1 AnswerAndVotes (org.mamute.model.AnswerAndVotes)1 Comment (org.mamute.model.Comment)1 CommentsAndVotes (org.mamute.model.CommentsAndVotes)1