Skip to content

Commit

Permalink
Add missing test cases to rank candidate edemo#257
Browse files Browse the repository at this point in the history
  • Loading branch information
szirbucz committed Apr 30, 2019
1 parent 7f9e54c commit e17f073
Showing 1 changed file with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.rulez.demokracia.pdengine.votecalculator;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.rulez.demokracia.pdengine.testhelpers.BeatTableTestHelper.*;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour;
import org.rulez.demokracia.pdengine.annotations.TestedFeature;
import org.rulez.demokracia.pdengine.annotations.TestedOperation;
import org.rulez.demokracia.pdengine.beattable.BeatTable;

@TestedFeature("Schulze method")
@TestedOperation("rank candidates")
@TestedBehaviour("calculates winners until all choices are ignored")
@RunWith(MockitoJUnitRunner.class)
public class VoteResultComposerIgnoreTest {

@InjectMocks
private VoteResultComposerImpl voteResultComposer;
@Mock
private WinnerCalculatorService winnerCalculatorService;

@Test
public void
winner_calculation_ends_in_one_step_when_all_choices_ignored_at_once() {
when(winnerCalculatorService.calculateWinners(any(), any()))
.thenReturn(List.of(CHOICE1, CHOICE2, CHOICE3));

voteResultComposer
.composeResult(createNewBeatTableWithComplexData());

verify(winnerCalculatorService, times(1)).calculateWinners(any(), any());
}

@Test
public void
winner_calculation_ends_in_n_steps_when_choices_ignored_one_by_one() {
when(winnerCalculatorService.calculateWinners(any(), any()))
.thenReturn(List.of(CHOICE1))
.thenReturn(List.of(CHOICE2))
.thenReturn(List.of(CHOICE3));

voteResultComposer
.composeResult(createNewBeatTableWithComplexData());

verify(winnerCalculatorService, times(3)).calculateWinners(any(), any());
}

@Test
public void winner_calculation_ends_in_zero_step_when_beat_table_is_empty() {
voteResultComposer
.composeResult(new BeatTable());

verify(winnerCalculatorService, never()).calculateWinners(any(), any());
}
}

0 comments on commit e17f073

Please sign in to comment.