use of easytests.core.services.TopicsServiceInterface in project easy-tests by malinink.
the class TopicsOptionsTest method testWithRelationsQuestionsOnSingleModel.
@Test
public void testWithRelationsQuestionsOnSingleModel() throws Exception {
final TopicsOptionsInterface topicsOptions = new TopicsOptions();
final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
topicsOptions.setQuestionsService(questionsService);
topicsOptions.setTopicsService(topicsService);
final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
topicsOptions.withQuestions(questionsOptions);
final List<QuestionModelInterface> questionsModels = new ArrayList<>();
questionsModels.add(Mockito.mock(QuestionModelInterface.class));
given(questionsService.findByTopic(topicModel, questionsOptions)).willReturn(questionsModels);
final TopicModelInterface topicModelWithRelations = topicsOptions.withRelations(topicModel);
Assert.assertEquals(topicModel, topicModelWithRelations);
verify(questionsService).findByTopic(topicModel, questionsOptions);
verify(topicModel).setQuestions(questionsModels);
}
use of easytests.core.services.TopicsServiceInterface in project easy-tests by malinink.
the class TopicsOptionsTest method testDeleteWithRelationsQuestion.
@Test
public void testDeleteWithRelationsQuestion() throws Exception {
final TopicsOptionsInterface topicsOptions = new TopicsOptions();
final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
topicsOptions.setQuestionsService(questionsService);
topicsOptions.setTopicsService(topicsService);
final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
topicsOptions.withQuestions(questionsOptions);
final List<QuestionModelInterface> questionsModels = new ArrayList<>();
topicModel.setQuestions(questionsModels);
final InOrder inOrder = Mockito.inOrder(questionsService, topicsService);
topicsOptions.deleteWithRelations(topicModel);
inOrder.verify(questionsService).save(topicModel.getQuestions(), questionsOptions);
inOrder.verify(topicsService).delete(topicModel);
}
use of easytests.core.services.TopicsServiceInterface 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.TopicsServiceInterface in project easy-tests by malinink.
the class IssueStandardTopicPrioritiesOptionsTest method testWithRelationsOnModelsList.
@Test
public void testWithRelationsOnModelsList() throws Exception {
final IssueStandardTopicPrioritiesOptionsInterface topicPrioritiesOptions = new IssueStandardTopicPrioritiesOptions();
final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
final IssueStandardsServiceInterface issueStandardsService = Mockito.mock(IssueStandardsServiceInterface.class);
final IssueStandardsOptionsInterface issueStandardsOptions = Mockito.mock(IssueStandardsOptionsInterface.class);
final Integer topicIdFirst = 3;
final Integer topicIdSecond = 5;
final Integer issueStandardIdFirst = 10;
final Integer issueStandardIdSecond = 20;
IssueStandardTopicPriorityModelInterface topicPriorityModelFirst = Mockito.mock(IssueStandardTopicPriorityModelInterface.class);
IssueStandardTopicPriorityModelInterface topicPriorityModelSecond = Mockito.mock(IssueStandardTopicPriorityModelInterface.class);
Mockito.when(topicPriorityModelFirst.getIssueStandard()).thenReturn(new IssueStandardModelEmpty(issueStandardIdFirst));
Mockito.when(topicPriorityModelFirst.getTopic()).thenReturn(new TopicModelEmpty(topicIdFirst));
Mockito.when(topicPriorityModelSecond.getIssueStandard()).thenReturn(new IssueStandardModelEmpty(issueStandardIdSecond));
Mockito.when(topicPriorityModelSecond.getTopic()).thenReturn(new TopicModelEmpty(topicIdSecond));
final List<IssueStandardTopicPriorityModelInterface> topicPriorityModels = new ArrayList<>(2);
topicPriorityModels.add(topicPriorityModelFirst);
topicPriorityModels.add(topicPriorityModelSecond);
final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
Mockito.when(topicModelFirst.getId()).thenReturn(topicIdFirst);
given(topicsService.find(topicIdFirst, topicsOptions)).willReturn(topicModelFirst);
final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
Mockito.when(topicModelSecond.getId()).thenReturn(topicIdSecond);
given(topicsService.find(topicIdSecond, topicsOptions)).willReturn(topicModelSecond);
final IssueStandardModelInterface issueStandardModelFirst = Mockito.mock(IssueStandardModelInterface.class);
Mockito.when(issueStandardModelFirst.getId()).thenReturn(issueStandardIdFirst);
given(issueStandardsService.find(issueStandardIdFirst, issueStandardsOptions)).willReturn(issueStandardModelFirst);
final IssueStandardModelInterface issueStandardModelSecond = Mockito.mock(IssueStandardModelInterface.class);
Mockito.when(issueStandardModelSecond.getId()).thenReturn(issueStandardIdSecond);
given(issueStandardsService.find(issueStandardIdSecond, issueStandardsOptions)).willReturn(issueStandardModelSecond);
// options не заданы
final List<IssueStandardTopicPriorityModelInterface> topicPriorityModelsWithoutRelations = topicPrioritiesOptions.withRelations(topicPriorityModels);
verify(topicsService, times(0)).find(topicIdFirst, topicsOptions);
verify(topicsService, times(0)).find(topicIdSecond, topicsOptions);
verify(issueStandardsService, times(0)).find(issueStandardIdFirst, issueStandardsOptions);
verify(issueStandardsService, times(0)).find(issueStandardIdSecond, issueStandardsOptions);
Assert.assertEquals(topicPriorityModels, topicPriorityModelsWithoutRelations);
Mockito.verify(topicPriorityModelFirst, times(0)).setTopic(topicModelFirst);
Mockito.verify(topicPriorityModelSecond, times(0)).setTopic(topicModelSecond);
Mockito.verify(topicPriorityModelFirst, times(0)).setIssueStandard(issueStandardModelFirst);
Mockito.verify(topicPriorityModelSecond, times(0)).setIssueStandard(issueStandardModelSecond);
topicPrioritiesOptions.setIssueStandardsService(issueStandardsService);
topicPrioritiesOptions.setTopicsService(topicsService);
topicPrioritiesOptions.withTopic(topicsOptions).withIssueStandard(issueStandardsOptions);
// теперь options заданы
final List<IssueStandardTopicPriorityModelInterface> topicPriorityModelsWithRelations = topicPrioritiesOptions.withRelations(topicPriorityModels);
verify(topicsService, times(1)).find(topicIdFirst, topicsOptions);
verify(topicsService, times(1)).find(topicIdSecond, topicsOptions);
verify(issueStandardsService, times(1)).find(issueStandardIdFirst, issueStandardsOptions);
verify(issueStandardsService, times(1)).find(issueStandardIdSecond, issueStandardsOptions);
Assert.assertEquals(topicPriorityModels, topicPriorityModelsWithRelations);
Mockito.verify(topicPriorityModelFirst, times(1)).setTopic(topicModelFirst);
Mockito.verify(topicPriorityModelSecond, times(1)).setTopic(topicModelSecond);
Mockito.verify(topicPriorityModelFirst, times(1)).setIssueStandard(issueStandardModelFirst);
Mockito.verify(topicPriorityModelSecond, times(1)).setIssueStandard(issueStandardModelSecond);
}
use of easytests.core.services.TopicsServiceInterface in project easy-tests by malinink.
the class QuestionsOptionsTest method testWithRelationsOnSingleModel.
@Test
public void testWithRelationsOnSingleModel() throws Exception {
final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
questionModel.setId(1);
given(questionModel.getTopic()).willReturn(new TopicModelEmpty(1));
given(questionModel.getQuestionType()).willReturn(new QuestionTypeModelEmpty(1));
final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
final QuestionTypesServiceInterface questionTypesService = Mockito.mock(QuestionTypesServiceInterface.class);
final QuestionTypesOptionsInterface questionTypesOptions = Mockito.mock(QuestionTypesOptionsInterface.class);
questionsOptions.setAnswersService(answersService);
questionsOptions.withAnswers(answersOptions);
questionsOptions.setTopicsService(topicsService);
questionsOptions.withTopic(topicsOptions);
questionsOptions.setQuestionTypesService(questionTypesService);
questionsOptions.withQuestionType(questionTypesOptions);
final List<AnswerModelInterface> answersModels = new ArrayList<>();
answersModels.add(Mockito.mock(AnswerModelInterface.class));
TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
QuestionTypeModelInterface questionTypeModel = Mockito.mock(QuestionTypeModelInterface.class);
given(answersService.findByQuestion(questionModel, answersOptions)).willReturn(answersModels);
given(topicsService.find(questionModel.getTopic().getId(), topicsOptions)).willReturn(topicModel);
given(questionTypesService.find(questionModel.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModel);
final QuestionModelInterface questionModelWithRelations = questionsOptions.withRelations(questionModel);
Assert.assertEquals(questionModel, questionModelWithRelations);
verify(answersService).findByQuestion(questionModel, answersOptions);
verify(topicsService).find(questionModel.getTopic().getId(), topicsOptions);
verify(questionTypesService).find(questionModel.getQuestionType().getId(), questionTypesOptions);
verify(questionModel).setAnswers(answersModels);
verify(questionModel).setTopic(topicModel);
verify(questionModel).setQuestionType(questionTypeModel);
verify(questionModel).setAnswers(Mockito.anyList());
}
Aggregations