Search in sources :

Example 1 with ElectionResult

use of com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResult in project popstellar by dedis.

the class ElectionHandlerTest method testHandleElectionResult.

@Test
public void testHandleElectionResult() throws DataHandlingException {
    // Create the result Election message
    QuestionResult questionResult = new QuestionResult(electionQuestion.getBallotOptions().get(0), 2);
    ElectionResultQuestion electionResultQuestion = new ElectionResultQuestion("id", Collections.singletonList(questionResult));
    ElectionResult electionResult = new ElectionResult(Collections.singletonList(electionResultQuestion));
    MessageGeneral message = new MessageGeneral(SENDER_KEY, electionResult, GSON);
    // Call the message handler
    messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL.subChannel(election.getId()), message);
    // Check the Election is present with state RESULTS_READY and the results
    Optional<Election> electionOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getElection(election.getId());
    assertTrue(electionOpt.isPresent());
    assertEquals(EventState.RESULTS_READY, electionOpt.get().getState());
    assertEquals(Collections.singletonList(questionResult), electionOpt.get().getResultsForQuestionId("id"));
}
Also used : MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ElectionResult(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResult) ElectionResultQuestion(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion) Election(com.github.dedis.popstellar.model.objects.Election) QuestionResult(com.github.dedis.popstellar.model.network.method.message.data.election.QuestionResult) Test(org.junit.Test)

Aggregations

MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)1 ElectionResult (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResult)1 ElectionResultQuestion (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion)1 QuestionResult (com.github.dedis.popstellar.model.network.method.message.data.election.QuestionResult)1 Election (com.github.dedis.popstellar.model.objects.Election)1 Test (org.junit.Test)1