Search in sources :

Example 31 with TesteeModelInterface

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

the class QuizzesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    quizModel.setId(1);
    given(quizModel.getIssue()).willReturn(new IssueModelEmpty(1));
    final QuizzesOptionsInterface quizzesOptions = new QuizzesOptions();
    final PointsServiceInterface pointsService = Mockito.mock(PointsServiceInterface.class);
    final TesteesServiceInterface testeeService = Mockito.mock(TesteesServiceInterface.class);
    final IssuesServiceInterface issuesService = Mockito.mock(IssuesServiceInterface.class);
    final PointsOptionsInterface pointsOptions = Mockito.mock(PointsOptionsInterface.class);
    final TesteesOptionsInterface testeeOptions = Mockito.mock(TesteesOptionsInterface.class);
    final IssuesOptionsInterface issuesOptions = Mockito.mock(IssuesOptionsInterface.class);
    quizzesOptions.setPointsService(pointsService);
    quizzesOptions.setIssuesService(issuesService);
    quizzesOptions.setTesteesService(testeeService);
    quizzesOptions.withTestee(testeeOptions);
    quizzesOptions.withPoints(pointsOptions);
    quizzesOptions.withIssue(issuesOptions);
    final List<PointModelInterface> pointsModels = new ArrayList<>();
    pointsModels.add(Mockito.mock(PointModelInterface.class));
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    final TesteeModelInterface testeeModel = Mockito.mock(TesteeModelInterface.class);
    given(testeeService.findByQuiz(quizModel, testeeOptions)).willReturn(testeeModel);
    given(pointsService.findByQuiz(quizModel, pointsOptions)).willReturn(pointsModels);
    given(issuesService.find(quizModel.getIssue().getId(), issuesOptions)).willReturn(issueModel);
    final QuizModelInterface quizModelWithRelations = quizzesOptions.withRelations(quizModel);
    Assert.assertEquals(quizModel, quizModelWithRelations);
    verify(testeeService).findByQuiz(quizModel, testeeOptions);
    verify(pointsService).findByQuiz(quizModel, pointsOptions);
    verify(issuesService).find(1, issuesOptions);
    verify(quizModel).setTestee(testeeModel);
    verify(quizModel).setPoints(pointsModels);
    verify(quizModel).setIssue(issueModel);
}
Also used : IssuesServiceInterface(easytests.core.services.IssuesServiceInterface) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) IssueModelEmpty(easytests.core.models.empty.IssueModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) PointsServiceInterface(easytests.core.services.PointsServiceInterface) TesteesServiceInterface(easytests.core.services.TesteesServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 32 with TesteeModelInterface

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

the class TesteesOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    final TesteeModelInterface testeeModel = null;
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final TesteeModelInterface testeeModelWithRelations = testeesOptions.withRelations(testeeModel);
    Assert.assertEquals(null, testeeModelWithRelations);
}
Also used : QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with TesteeModelInterface

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

the class TesteesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final TesteeModelInterface testeeModelFirst = Mockito.mock(TesteeModelInterface.class);
    testeeModelFirst.setId(1);
    final TesteeModelInterface testeeModelSecond = Mockito.mock(TesteeModelInterface.class);
    testeeModelSecond.setId(2);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final Integer quizIdFirst = 3;
    final Integer quizIdSecond = 5;
    Mockito.when(testeeModelFirst.getQuiz()).thenReturn(new QuizModelEmpty(quizIdFirst));
    Mockito.when(testeeModelSecond.getQuiz()).thenReturn(new QuizModelEmpty(quizIdSecond));
    final List<TesteeModelInterface> testeesModels = new ArrayList<>(2);
    testeesModels.add(testeeModelFirst);
    testeesModels.add(testeeModelSecond);
    final TesteesOptionsInterface testeesOptions = new TesteesOptions();
    final QuizModelInterface quizModelFirst = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModelFirst.getId()).thenReturn(quizIdFirst);
    final QuizModelInterface quizModelSecond = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModelSecond.getId()).thenReturn(quizIdSecond);
    given(quizzesService.find(quizIdFirst, quizzesOptions)).willReturn(quizModelFirst);
    given(quizzesService.find(quizIdSecond, quizzesOptions)).willReturn(quizModelSecond);
    // options не заданы
    List<TesteeModelInterface> testeeModelsWithoutRelations = testeesOptions.withRelations(testeesModels);
    verify(quizzesService, times(0)).find(quizIdFirst, quizzesOptions);
    verify(quizzesService, times(0)).find(quizIdSecond, quizzesOptions);
    Assert.assertEquals(testeesModels, testeeModelsWithoutRelations);
    verify(testeeModelFirst, times(0)).setQuiz(quizModelFirst);
    verify(testeeModelSecond, times(0)).setQuiz(quizModelSecond);
    testeesOptions.setQuizzesService(quizzesService);
    testeesOptions.withQuiz(quizzesOptions);
    final List<TesteeModelInterface> testeesModelsWithRelations = testeesOptions.withRelations(testeesModels);
    verify(quizzesService, times(1)).find(quizIdFirst, quizzesOptions);
    verify(quizzesService, times(1)).find(quizIdSecond, quizzesOptions);
    Assert.assertEquals(testeesModelsWithRelations, testeesModels);
    verify(testeeModelFirst, times(1)).setQuiz(quizModelFirst);
    verify(testeeModelSecond, times(1)).setQuiz(quizModelSecond);
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) ArrayList(java.util.ArrayList) TesteeModelInterface(easytests.core.models.TesteeModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TesteeModelInterface (easytests.core.models.TesteeModelInterface)33 Test (org.junit.Test)28 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)27 QuizModelInterface (easytests.core.models.QuizModelInterface)11 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)7 TesteeEntity (easytests.core.entities.TesteeEntity)6 TesteesServiceInterface (easytests.core.services.TesteesServiceInterface)6 TesteesOptionsInterface (easytests.core.options.TesteesOptionsInterface)5 ArrayList (java.util.ArrayList)5 PointModelInterface (easytests.core.models.PointModelInterface)4 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)4 PointsServiceInterface (easytests.core.services.PointsServiceInterface)4 InOrder (org.mockito.InOrder)4 IssueModelInterface (easytests.core.models.IssueModelInterface)2 TesteeModel (easytests.core.models.TesteeModel)2 IssueModelEmpty (easytests.core.models.empty.IssueModelEmpty)2 IssuesServiceInterface (easytests.core.services.IssuesServiceInterface)2 QuizzesOptions (easytests.core.options.QuizzesOptions)1 TesteesOptions (easytests.core.options.TesteesOptions)1