Search in sources :

Example 6 with Vote

use of org.mamute.model.Vote in project mamute by caelum.

the class VotingMachineTest method should_add_vote.

@Test
public void should_add_vote() {
    votingMachine.register(votable, new Vote(voter, VoteType.UP), Question.class);
    assertEquals(1, votable.getVoteCount());
}
Also used : Vote(org.mamute.model.Vote) MassiveVote(org.mamute.model.vote.MassiveVote) Test(org.junit.Test)

Example 7 with Vote

use of org.mamute.model.Vote in project mamute by caelum.

the class VotedAtSomethingEventTest method should_calculate_karma_for_downvote.

@Test
public void should_calculate_karma_for_downvote() {
    VotedAtSomethingEvent votedAtSomething = new VotedAtSomethingEvent(new Vote(null, VoteType.DOWN), null);
    assertEquals(KarmaCalculator.DOWNVOTED_QUESTION_OR_ANSWER, votedAtSomething.reward());
}
Also used : Vote(org.mamute.model.Vote) VotedAtSomethingEvent(org.mamute.reputation.rules.VotedAtSomethingEvent) Test(org.junit.Test)

Example 8 with Vote

use of org.mamute.model.Vote in project mamute by caelum.

the class VotedAtSomethingEventTest method should_calculate_karma_for_upvote.

@Test
public void should_calculate_karma_for_upvote() {
    VotedAtSomethingEvent votedAtSomething = new VotedAtSomethingEvent(new Vote(null, VoteType.UP), null);
    assertEquals(0, votedAtSomething.reward());
}
Also used : Vote(org.mamute.model.Vote) VotedAtSomethingEvent(org.mamute.reputation.rules.VotedAtSomethingEvent) Test(org.junit.Test)

Example 9 with Vote

use of org.mamute.model.Vote in project mamute by caelum.

the class AnswerAndVotesTest method should_fill_value_with_null_only_answers_that_has_no_currentUserVote.

@Test
public void should_fill_value_with_null_only_answers_that_has_no_currentUserVote() {
    Question q = question.build();
    Object[] first = new Object[] { answerFor(q, 1), mock(Vote.class) };
    Object[] second = new Object[] { answerFor(q, 2), mock(Vote.class) };
    Answer third = answerFor(q, 3);
    List<Object[]> voteList = new ArrayList<>();
    voteList.add(first);
    voteList.add(second);
    List<Answer> answers = new ArrayList<>();
    answers.add((Answer) first[0]);
    answers.add((Answer) second[0]);
    answers.add(third);
    AnswerAndVotes votes = new AnswerAndVotes(q, answers, voteList);
    Map<Answer, Vote> map = votes.getVotes();
    assertEquals(first[1], map.get(first[0]));
    assertEquals(second[1], map.get(second[0]));
    assertEquals(null, map.get(third));
    assertTrue(map.containsKey(third));
}
Also used : Answer(org.mamute.model.Answer) Vote(org.mamute.model.Vote) ArrayList(java.util.ArrayList) Question(org.mamute.model.Question) AnswerAndVotes(org.mamute.model.AnswerAndVotes) Test(org.junit.Test)

Example 10 with Vote

use of org.mamute.model.Vote in project mamute by caelum.

the class MassiveVoteTest method should_count_karma_if_vote_was_created_before_min_date.

@Test
public void should_count_karma_if_vote_was_created_before_min_date() throws Exception {
    DateTime antantonte = new DateTime().minusDays(3);
    TimeMachine.goTo(antantonte).andExecute(new Block<Vote>() {

        @Override
        public Vote run() {
            for (int i = 0; i < massiveVote.getMaxVotesAllowed(); i++) {
                massiveVote.shouldCountKarma(massiveVoter, author, vote(massiveVoter, VoteType.DOWN, 1l));
            }
            return null;
        }
    });
    Vote acceptedVote = vote(massiveVoter, VoteType.DOWN, 1l);
    assertTrue(massiveVote.shouldCountKarma(massiveVoter, author, acceptedVote));
}
Also used : MassiveVote(org.mamute.model.vote.MassiveVote) Vote(org.mamute.model.Vote) DateTime(org.joda.time.DateTime) 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