Search in sources :

Example 16 with QuizModelInterface

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

the class QuizzesServiceTest method testFindWithOptions.

@Test
public void testFindWithOptions() throws Exception {
    final Integer id = 1;
    final Integer issueId = 1;
    final QuizEntity quizEntity = this.createQuizEntityMock(4, "test3", issueId);
    final QuizModelInterface quizModel = this.mapQuizModel(quizEntity);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    given(this.quizzesMapper.find(id)).willReturn(quizEntity);
    given(quizzesOptions.withRelations(quizModel)).willReturn(quizModel);
    final QuizModelInterface foundedQuizModel = this.quizzesService.find(id, quizzesOptions);
    Assert.assertEquals(quizModel, foundedQuizModel);
    verify(quizzesOptions).withRelations(quizModel);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesOptionsInterface(easytests.core.options.QuizzesOptionsInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with QuizModelInterface

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

the class QuizzesServiceTest method testFindByIssue.

@Test
public void testFindByIssue() throws Exception {
    final Integer issueId = 7;
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    final QuizEntity quizEntityFirst = this.createQuizEntityMock(3, "test3", issueId);
    final QuizEntity quizEntitySecond = this.createQuizEntityMock(12, "test12", issueId);
    final List<QuizEntity> quizzesEntities = new ArrayList<>();
    quizzesEntities.add(quizEntityFirst);
    quizzesEntities.add(quizEntitySecond);
    Mockito.when(issueModel.getId()).thenReturn(issueId);
    given(this.quizzesMapper.findByIssueId(issueId)).willReturn(quizzesEntities);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(this.mapQuizModel(quizEntityFirst));
    quizzesModels.add(this.mapQuizModel(quizEntitySecond));
    final List<QuizModelInterface> foundedQuizzesModels = this.quizzesService.findByIssue(issueModel);
    verify(this.quizzesMapper).findByIssueId(issueId);
    Assert.assertEquals(quizzesModels, foundedQuizzesModels);
}
Also used : QuizEntity(easytests.core.entities.QuizEntity) QuizModelInterface(easytests.core.models.QuizModelInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with QuizModelInterface

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

the class QuizzesServiceTest method testFindAbsentModel.

@Test
public void testFindAbsentModel() throws Exception {
    final Integer id = 10;
    given(this.quizzesMapper.find(id)).willReturn(null);
    final QuizModelInterface quizModel = this.quizzesService.find(id);
    Assert.assertEquals(null, quizModel);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with QuizModelInterface

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

the class PointsOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    pointModel.setId(1);
    given(pointModel.getQuiz()).willReturn(new QuizModelEmpty(1));
    given(pointModel.getQuestion()).willReturn(new QuestionModelEmpty(1));
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final SolutionsServiceInterface solutionsService = Mockito.mock(SolutionsServiceInterface.class);
    pointsOptions.setQuizzesService(quizzesService);
    pointsOptions.setQuestionsService(questionsService);
    pointsOptions.setSolutionsService(solutionsService);
    final QuizzesOptionsInterface quizOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    final SolutionsOptionsInterface solutionsOptions = Mockito.mock(SolutionsOptionsInterface.class);
    pointsOptions.withQuiz(quizOptions);
    pointsOptions.withQuestion(questionOptions);
    pointsOptions.withSolutions(solutionsOptions);
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    final List<SolutionModelInterface> solutionsModels = new ArrayList<>();
    solutionsModels.add(Mockito.mock(SolutionModelInterface.class));
    given(quizzesService.find(pointModel.getQuiz().getId(), quizOptions)).willReturn(quizModel);
    given(questionsService.find(pointModel.getQuestion().getId(), questionOptions)).willReturn(questionModel);
    given(solutionsService.findByPoint(pointModel, solutionsOptions)).willReturn(solutionsModels);
    final PointModelInterface pointModelWithRelations = pointsOptions.withRelations(pointModel);
    Assert.assertEquals(pointModel, pointModelWithRelations);
    verify(quizzesService).find(1, quizOptions);
    verify(questionsService).find(1, questionOptions);
    verify(solutionsService).findByPoint(pointModel, solutionsOptions);
    verify(pointModel).setQuiz(quizModel);
    verify(pointModel).setQuestion(questionModel);
    verify(pointModel).setSolutions(solutionsModels);
}
Also used : SolutionModelInterface(easytests.core.models.SolutionModelInterface) QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) SolutionsServiceInterface(easytests.core.services.SolutionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with QuizModelInterface

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

the class PointsOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final PointsServiceInterface pointsService = Mockito.mock(PointsServiceInterface.class);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final SolutionsServiceInterface solutionsService = Mockito.mock(SolutionsServiceInterface.class);
    pointsOptions.setPointsService(pointsService);
    pointsOptions.setQuizzesService(quizzesService);
    pointsOptions.setSolutionsService(solutionsService);
    final QuizzesOptionsInterface quizOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final SolutionsOptionsInterface solutionsOptions = Mockito.mock(SolutionsOptionsInterface.class);
    pointsOptions.withQuiz(quizOptions);
    pointsOptions.withSolutions(solutionsOptions);
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    final List<SolutionModelInterface> solutionsModels = new ArrayList<>();
    solutionsModels.add(Mockito.mock(SolutionModelInterface.class));
    given(pointModel.getQuiz()).willReturn(quizModel);
    given(pointModel.getSolutions()).willReturn(solutionsModels);
    final InOrder inOrder = Mockito.inOrder(solutionsService, pointsService, quizzesService);
    pointsOptions.deleteWithRelations(pointModel);
    inOrder.verify(solutionsService).delete(solutionsModels, solutionsOptions);
    inOrder.verify(pointsService).delete(pointModel);
    inOrder.verify(quizzesService).delete(quizModel, quizOptions);
}
Also used : SolutionModelInterface(easytests.core.models.SolutionModelInterface) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) PointsServiceInterface(easytests.core.services.PointsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) SolutionsServiceInterface(easytests.core.services.SolutionsServiceInterface) 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