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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations