Search in sources :

Example 31 with QuizModelInterface

use of easytests.core.models.QuizModelInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    issueModel.setId(1);
    given(issueModel.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(Mockito.mock(QuizModelInterface.class));
    given(subjectsService.find(issueModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    given(quizzesService.findByIssue(issueModel, quizzesOptions)).willReturn(quizzesModels);
    final IssueModelInterface issueModelWithRelations = issuesOptions.withRelations(issueModel);
    Assert.assertEquals(issueModel, issueModelWithRelations);
    verify(subjectsService).find(1, subjectsOptions);
    verify(quizzesService).findByIssue(issueModel, quizzesOptions);
    verify(issueModel).setQuizzes(quizzesModels);
    verify(issueModel).setQuizzes(Mockito.anyList());
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with QuizModelInterface

use of easytests.core.models.QuizModelInterface in project easy-tests by malinink.

the class QuizEntityTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer quizId = 420;
    final Integer issueId = 2;
    final String inviteCode = "code";
    final Boolean codeExpired = false;
    final LocalDateTime startedAt = LocalDateTime.of(1, 1, 1, 1, 1);
    final LocalDateTime finishedAt = LocalDateTime.of(2, 1, 1, 1, 1);
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    Mockito.when(quizModel.getIssue()).thenReturn(new IssueModelEmpty(issueId));
    Mockito.when(quizModel.getStartedAt()).thenReturn(startedAt);
    Mockito.when(quizModel.getInviteCode()).thenReturn(inviteCode);
    Mockito.when(quizModel.getFinishedAt()).thenReturn(finishedAt);
    Mockito.when(quizModel.getCodeExpired()).thenReturn(codeExpired);
    final QuizEntity quizEntity = new QuizEntity();
    quizEntity.map(quizModel);
    Assert.assertEquals(quizId, quizEntity.getId());
    Assert.assertEquals(issueId, quizEntity.getIssueId());
    Assert.assertEquals(inviteCode, quizEntity.getInviteCode());
    Assert.assertEquals(startedAt, quizEntity.getStartedAt());
    Assert.assertEquals(finishedAt, quizEntity.getFinishedAt());
    Assert.assertEquals(codeExpired, quizEntity.getCodeExpired());
}
Also used : LocalDateTime(java.time.LocalDateTime) QuizModelInterface(easytests.core.models.QuizModelInterface) IssueModelEmpty(easytests.core.models.empty.IssueModelEmpty) Test(org.junit.Test)

Example 33 with QuizModelInterface

use of easytests.core.models.QuizModelInterface in project easy-tests by malinink.

the class QuizzesSupport method getModelMock.

private QuizModelInterface getModelMock(Integer id, Integer issueId, String inviteCode, Boolean codeExpired, LocalDateTime startedAt, LocalDateTime finishedAt) {
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(id);
    Mockito.when(quizModel.getInviteCode()).thenReturn(inviteCode);
    Mockito.when(quizModel.getCodeExpired()).thenReturn(codeExpired);
    Mockito.when(quizModel.getStartedAt()).thenReturn(startedAt);
    Mockito.when(quizModel.getFinishedAt()).thenReturn(finishedAt);
    Mockito.when(quizModel.getIssue()).thenReturn(new IssueModelEmpty(issueId));
    Mockito.when(quizModel.getPoints()).thenReturn(new ModelsListEmpty());
    Mockito.when(quizModel.getTestee()).thenReturn(new TesteeModelEmpty());
    return quizModel;
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) ModelsListEmpty(easytests.core.models.empty.ModelsListEmpty) TesteeModelEmpty(easytests.core.models.empty.TesteeModelEmpty) IssueModelEmpty(easytests.core.models.empty.IssueModelEmpty)

Example 34 with QuizModelInterface

use of easytests.core.models.QuizModelInterface in project easy-tests by malinink.

the class QuizzesSupport method assertModelsListEquals.

public void assertModelsListEquals(List<QuizModelInterface> expected, List<QuizModelInterface> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    Integer i = 0;
    for (QuizModelInterface quizModel : expected) {
        this.assertEquals(quizModel, actual.get(i));
        i++;
    }
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface)

Example 35 with QuizModelInterface

use of easytests.core.models.QuizModelInterface in project easy-tests by malinink.

the class QuizzesServiceTest method testSaveEntitiesList.

@Test
public void testSaveEntitiesList() throws Exception {
    final QuizModelInterface quizModelFirst = this.createQuizModel(null, "test1", 1);
    final QuizModelInterface quizModelSecond = this.createQuizModel(null, "test2", 2);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(quizModelFirst);
    quizzesModels.add(quizModelSecond);
    final QuizzesServiceInterface quizzesServiceSpy = Mockito.spy(quizzesService);
    quizzesServiceSpy.save(quizzesModels);
    verify(quizzesServiceSpy, times(1)).save(quizModelFirst);
    verify(quizzesServiceSpy, times(1)).save(quizModelSecond);
    quizzesServiceSpy.save(quizzesModels, quizzesOptions);
    verify(quizzesServiceSpy, times(1)).save(quizModelFirst, quizzesOptions);
    verify(quizzesServiceSpy, times(1)).save(quizModelSecond, quizzesOptions);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesOptionsInterface(easytests.core.options.QuizzesOptionsInterface) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

QuizModelInterface (easytests.core.models.QuizModelInterface)48 Test (org.junit.Test)42 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 ArrayList (java.util.ArrayList)17 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)15 IssueModelInterface (easytests.core.models.IssueModelInterface)11 PointModelInterface (easytests.core.models.PointModelInterface)11 TesteeModelInterface (easytests.core.models.TesteeModelInterface)11 QuizzesOptionsInterface (easytests.core.options.QuizzesOptionsInterface)9 InOrder (org.mockito.InOrder)8 QuizEntity (easytests.core.entities.QuizEntity)7 PointsServiceInterface (easytests.core.services.PointsServiceInterface)7 TesteesServiceInterface (easytests.core.services.TesteesServiceInterface)7 IssuesServiceInterface (easytests.core.services.IssuesServiceInterface)6 SolutionModelInterface (easytests.core.models.SolutionModelInterface)4 IssueModelEmpty (easytests.core.models.empty.IssueModelEmpty)4 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)4 SolutionsServiceInterface (easytests.core.services.SolutionsServiceInterface)4 QuestionModelInterface (easytests.core.models.QuestionModelInterface)3 QuizModel (easytests.core.models.QuizModel)2