Search in sources :

Example 16 with Election

use of com.github.dedis.popstellar.model.objects.Election 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

Election (com.github.dedis.popstellar.model.objects.Election)16 Lao (com.github.dedis.popstellar.model.objects.Lao)8 Channel (com.github.dedis.popstellar.model.objects.Channel)5 LAORepository (com.github.dedis.popstellar.repository.LAORepository)5 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 TextView (android.widget.TextView)3 ElectionQuestion (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionQuestion)3 LaoDetailViewModel (com.github.dedis.popstellar.ui.detail.LaoDetailViewModel)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ArrayAdapter (android.widget.ArrayAdapter)2 ViewPager2 (androidx.viewpager2.widget.ViewPager2)2 R (com.github.dedis.popstellar.R)2 CastVoteFragmentBinding (com.github.dedis.popstellar.databinding.CastVoteFragmentBinding)2 CastVote (com.github.dedis.popstellar.model.network.method.message.data.election.CastVote)2 ElectionResultQuestion (com.github.dedis.popstellar.model.network.method.message.data.election.ElectionResultQuestion)2 QuestionResult (com.github.dedis.popstellar.model.network.method.message.data.election.QuestionResult)2