Search in sources :

Example 1 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class TopicsOptionsTest method testWithRelationsSubjectOnSingleModel.

@Test
public void testWithRelationsSubjectOnSingleModel() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setSubjectsService(subjectsService);
    topicsOptions.setTopicsService(topicsService);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    topicsOptions.withSubject(subjectsOptions);
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithId = Mockito.mock(SubjectModelInterface.class);
    given(topicModel.getSubject()).willReturn(subjectModelWithId);
    given(subjectsService.find(topicModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    final TopicModelInterface topicModelWithRelations = topicsOptions.withRelations(topicModel);
    Assert.assertEquals(topicModel, topicModelWithRelations);
    subjectsService.find(1, subjectsOptions);
    verify(topicModel).setSubject(subjectModel);
}
Also used : SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class UsersOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() throws Exception {
    final UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
    final UsersOptionsInterface usersOptions = new UsersOptions();
    final UsersServiceInterface usersService = Mockito.mock(UsersServiceInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    usersOptions.setUsersService(usersService);
    usersOptions.setSubjectsService(subjectsService);
    usersOptions.withSubjects(subjectsOptions);
    final List<SubjectModelInterface> subjectsModels = new ArrayList<>();
    subjectsModels.add(Mockito.mock(SubjectModelInterface.class));
    given(userModel.getSubjects()).willReturn(subjectsModels);
    final InOrder inOrder = Mockito.inOrder(subjectsService, usersService);
    usersOptions.saveWithRelations(userModel);
    inOrder.verify(usersService).save(userModel);
    inOrder.verify(subjectsService).save(subjectsModels, subjectsOptions);
}
Also used : UsersServiceInterface(easytests.core.services.UsersServiceInterface) UserModelInterface(easytests.core.models.UserModelInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class UsersOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    final UserModelInterface userModel = null;
    final UsersOptionsInterface usersOptions = new UsersOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    usersOptions.setSubjectsService(subjectsService);
    usersOptions.withSubjects(subjectsOptions);
    final UserModelInterface userModelWithRelations = usersOptions.withRelations(userModel);
    Assert.assertEquals(null, userModelWithRelations);
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class IssueStandardOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() throws Exception {
    final IssueStandardsOptionsInterface issueStandardsOptions = new IssueStandardsOptions();
    final IssueStandardsServiceInterface issueStandardsService = Mockito.mock(IssueStandardsServiceInterface.class);
    final IssueStandardTopicPrioritiesServiceInterface topicPrioritiesService = Mockito.mock(IssueStandardTopicPrioritiesServiceInterface.class);
    final IssueStandardTopicPrioritiesOptionsInterface topicPrioritiesOptions = Mockito.mock(IssueStandardTopicPrioritiesOptionsInterface.class);
    final IssueStandardQuestionTypeOptionsServiceInterface questionTypeOptionsService = Mockito.mock(IssueStandardQuestionTypeOptionsServiceInterface.class);
    final IssueStandardQuestionTypeOptionsOptionsInterface questionTypeOptionsOptions = Mockito.mock(IssueStandardQuestionTypeOptionsOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final Integer subjectId = 3;
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    Mockito.when(subjectModel.getId()).thenReturn(subjectId);
    final IssueStandardModelInterface issueStandardModel = Mockito.mock(IssueStandardModelInterface.class);
    Mockito.when(issueStandardModel.getTopicPriorities()).thenReturn(new ArrayList<>());
    Mockito.when(issueStandardModel.getQuestionTypeOptions()).thenReturn(new ArrayList<>());
    Mockito.when(issueStandardModel.getSubject()).thenReturn(subjectModel);
    issueStandardsOptions.setIssueStandardsService(issueStandardsService);
    issueStandardsOptions.setTopicPrioritiesService(topicPrioritiesService);
    issueStandardsOptions.setQuestionTypeOptionsService(questionTypeOptionsService);
    issueStandardsOptions.setSubjectsService(subjectsService);
    issueStandardsOptions.withTopicPriorities(topicPrioritiesOptions).withQuestionTypeOptions(questionTypeOptionsOptions).withSubject(subjectsOptions);
    final InOrder inOrder = Mockito.inOrder(subjectsService, issueStandardsService, topicPrioritiesService, questionTypeOptionsService);
    issueStandardsOptions.saveWithRelations(issueStandardModel);
    inOrder.verify(subjectsService, times(1)).save(issueStandardModel.getSubject(), subjectsOptions);
    inOrder.verify(issueStandardsService, times(1)).save(issueStandardModel);
    inOrder.verify(topicPrioritiesService, times(1)).save(issueStandardModel.getTopicPriorities(), topicPrioritiesOptions);
    inOrder.verify(questionTypeOptionsService, times(1)).save(issueStandardModel.getQuestionTypeOptions(), questionTypeOptionsOptions);
}
Also used : IssueStandardsServiceInterface(easytests.core.services.IssueStandardsServiceInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) IssueStandardTopicPrioritiesServiceInterface(easytests.core.services.IssueStandardTopicPrioritiesServiceInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) IssueStandardModelInterface(easytests.core.models.IssueStandardModelInterface) IssueStandardQuestionTypeOptionsServiceInterface(easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final IssueModelInterface issueModelFirst = Mockito.mock(IssueModelInterface.class);
    issueModelFirst.setId(1);
    given(issueModelFirst.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssueModelInterface issueModelSecond = Mockito.mock(IssueModelInterface.class);
    issueModelSecond.setId(2);
    given(issueModelSecond.getSubject()).willReturn(new SubjectModelEmpty(2));
    final List<IssueModelInterface> issuesModels = new ArrayList<>(2);
    issuesModels.add(issueModelFirst);
    issuesModels.add(issueModelSecond);
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final List<QuizModelInterface> quizzesModelsFirst = new ArrayList<>();
    quizzesModelsFirst.add(Mockito.mock(QuizModelInterface.class));
    final List<QuizModelInterface> quizzesModelsSecond = new ArrayList<>();
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    given(quizzesService.findByIssue(issueModelFirst, quizzesOptions)).willReturn(quizzesModelsFirst);
    given(quizzesService.findByIssue(issueModelSecond, quizzesOptions)).willReturn(quizzesModelsSecond);
    final SubjectModelInterface subjectModelFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelSecond = Mockito.mock(SubjectModelInterface.class);
    given(subjectsService.find(1, subjectsOptions)).willReturn(subjectModelFirst);
    given(subjectsService.find(2, subjectsOptions)).willReturn(subjectModelSecond);
    final List<IssueModelInterface> issuesModelsWithRelations = issuesOptions.withRelations(issuesModels);
    Assert.assertEquals(issuesModelsWithRelations, issuesModels);
    verify(quizzesService).findByIssue(issueModelFirst, quizzesOptions);
    verify(subjectsService).find(1, subjectsOptions);
    verify(issuesModels.get(0)).setQuizzes(quizzesModelsFirst);
    verify(issuesModels.get(0)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(0)).setSubject(subjectModelFirst);
    verify(quizzesService).findByIssue(issueModelSecond, quizzesOptions);
    verify(subjectsService).find(2, subjectsOptions);
    verify(issuesModels.get(1)).setQuizzes(quizzesModelsSecond);
    verify(issuesModels.get(1)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(1)).setSubject(subjectModelSecond);
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)19 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 SubjectModelInterface (easytests.core.models.SubjectModelInterface)15 ArrayList (java.util.ArrayList)9 InOrder (org.mockito.InOrder)6 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)5 TopicModelInterface (easytests.core.models.TopicModelInterface)5 UserModelInterface (easytests.core.models.UserModelInterface)5 IssueStandardQuestionTypeOptionsServiceInterface (easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface)5 IssueStandardTopicPrioritiesServiceInterface (easytests.core.services.IssueStandardTopicPrioritiesServiceInterface)5 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)5 IssueModelInterface (easytests.core.models.IssueModelInterface)4 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)4 SubjectModel (easytests.core.models.SubjectModel)3 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)3 IssueStandardQuestionTypeOptionModelInterface (easytests.core.models.IssueStandardQuestionTypeOptionModelInterface)2 IssueStandardTopicPriorityModelInterface (easytests.core.models.IssueStandardTopicPriorityModelInterface)2 QuizModelInterface (easytests.core.models.QuizModelInterface)2 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)2