use of easytests.core.services.AnswersServiceInterface 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());
}
use of easytests.core.services.AnswersServiceInterface in project easy-tests by malinink.
the class QuestionsOptionsTest method testDeleteWithRelations.
@Test
public void testDeleteWithRelations() throws Exception {
final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
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);
questionsOptions.setQuestionsService(questionsService);
questionsOptions.setAnswersService(answersService);
questionsOptions.withAnswers(answersOptions);
questionsOptions.setTopicsService(topicsService);
questionsOptions.withTopic(topicsOptions);
final List<AnswerModelInterface> answersModels = new ArrayList<>();
answersModels.add(Mockito.mock(AnswerModelInterface.class));
TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
given(questionModel.getAnswers()).willReturn(answersModels);
given(questionModel.getTopic()).willReturn(topicModel);
final InOrder inOrder = Mockito.inOrder(answersService, questionsService, topicsService);
questionsOptions.deleteWithRelations(questionModel);
inOrder.verify(answersService).delete(answersModels, answersOptions);
inOrder.verify(questionsService).delete(questionModel);
inOrder.verify(topicsService).delete(topicModel, topicsOptions);
}
use of easytests.core.services.AnswersServiceInterface in project easy-tests by malinink.
the class QuestionsOptionsTest method testWithRelationsOnModelsList.
@Test
public void testWithRelationsOnModelsList() throws Exception {
final QuestionModelInterface questionModelFirst = Mockito.mock(QuestionModelInterface.class);
questionModelFirst.setId(1);
given(questionModelFirst.getTopic()).willReturn(new TopicModelEmpty(1));
given(questionModelFirst.getQuestionType()).willReturn(new QuestionTypeModelEmpty(1));
final QuestionModelInterface questionModelSecond = Mockito.mock(QuestionModelInterface.class);
questionModelSecond.setId(2);
given(questionModelSecond.getTopic()).willReturn(new TopicModelEmpty(2));
given(questionModelSecond.getQuestionType()).willReturn(new QuestionTypeModelEmpty(2));
final List<QuestionModelInterface> questionsModels = new ArrayList<>(2);
questionsModels.add(questionModelFirst);
questionsModels.add(questionModelSecond);
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> answersModelsFirst = new ArrayList<>();
answersModelsFirst.add(Mockito.mock(AnswerModelInterface.class));
final List<AnswerModelInterface> answersModelsSecond = new ArrayList<>();
answersModelsSecond.add(Mockito.mock(AnswerModelInterface.class));
TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
QuestionTypeModelInterface questionTypeModelFirst = Mockito.mock(QuestionTypeModelInterface.class);
QuestionTypeModelInterface questionTypeModelSecond = Mockito.mock(QuestionTypeModelInterface.class);
given(answersService.findByQuestion(questionModelFirst, answersOptions)).willReturn(answersModelsFirst);
given(answersService.findByQuestion(questionModelSecond, answersOptions)).willReturn(answersModelsSecond);
given(topicsService.find(questionModelFirst.getTopic().getId(), topicsOptions)).willReturn(topicModelFirst);
given(topicsService.find(questionModelSecond.getTopic().getId(), topicsOptions)).willReturn(topicModelSecond);
given(questionTypesService.find(questionModelFirst.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelFirst);
given(questionTypesService.find(questionModelSecond.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelSecond);
final List<QuestionModelInterface> questionsModelsWithRelations = questionsOptions.withRelations(questionsModels);
Assert.assertEquals(questionsModelsWithRelations, questionsModels);
verify(answersService).findByQuestion(questionModelFirst, answersOptions);
verify(questionsModels.get(0)).setAnswers(answersModelsFirst);
verify(questionsModels.get(0)).setAnswers(Mockito.anyList());
verify(answersService).findByQuestion(questionModelSecond, answersOptions);
verify(questionsModels.get(1)).setAnswers(answersModelsSecond);
verify(questionsModels.get(1)).setAnswers(Mockito.anyList());
verify(topicsService).find(questionModelFirst.getTopic().getId(), topicsOptions);
verify(topicsService).find(questionModelSecond.getTopic().getId(), topicsOptions);
verify(questionsModels.get(0)).setTopic(topicModelFirst);
verify(questionsModels.get(1)).setTopic(topicModelSecond);
verify(questionTypesService).find(questionModelFirst.getQuestionType().getId(), questionTypesOptions);
verify(questionTypesService).find(questionModelSecond.getQuestionType().getId(), questionTypesOptions);
verify(questionModelFirst).setQuestionType(questionTypeModelFirst);
verify(questionModelSecond).setQuestionType(questionTypeModelSecond);
}
use of easytests.core.services.AnswersServiceInterface in project easy-tests by malinink.
the class SolutionsOptionsTest method testSaveDeleteWithPoint.
@Test
public void testSaveDeleteWithPoint() {
final SolutionModelInterface solutionModel = Mockito.mock(SolutionModelInterface.class);
final SolutionsOptionsInterface solutionsOptions = new SolutionsOptions();
final SolutionsServiceInterface solutionsService = Mockito.mock(SolutionsServiceInterface.class);
final PointsOptionsInterface pointsOptions = Mockito.mock(PointsOptionsInterface.class);
final PointsServiceInterface pointsService = Mockito.mock(PointsServiceInterface.class);
final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
solutionsOptions.setSolutionsService(solutionsService);
solutionsOptions.setPointsService(pointsService);
solutionsOptions.withPoint(pointsOptions);
solutionsOptions.setAnswersService(answersService);
solutionsOptions.withAnswer(answersOptions);
final SolutionsOptionsInterface solutionsOptionsSpy = Mockito.spy(solutionsOptions);
solutionsOptionsSpy.deleteWithRelations(solutionModel);
verify(pointsOptions, times(1)).deleteWithRelations(solutionModel.getPoint());
/* solutionsOptionsSpy.saveWithRelations(solutionModel);
verify(pointsOptions, times(1)).saveWithRelations(solutionModel.getPoint());*/
}
use of easytests.core.services.AnswersServiceInterface in project easy-tests by malinink.
the class SolutionsOptionsTest method testWithRelationsOnSingleModel.
@Test
public void testWithRelationsOnSingleModel() throws Exception {
final SolutionModelInterface solutionModel = Mockito.mock(SolutionModelInterface.class);
solutionModel.setId(1);
given(solutionModel.getPoint()).willReturn(new PointModelEmpty(1));
given(solutionModel.getAnswer()).willReturn(new AnswerModelEmpty(1));
final SolutionsOptionsInterface solutionsOptions = new SolutionsOptions();
final PointsOptionsInterface pointsOptions = Mockito.mock(PointsOptionsInterface.class);
final AnswersOptionsInterface answerOptions = Mockito.mock(AnswersOptionsInterface.class);
final PointsServiceInterface pointsService = Mockito.mock(PointsServiceInterface.class);
final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
solutionsOptions.setPointsService(pointsService);
solutionsOptions.setAnswersService(answersService);
solutionsOptions.withPoint(pointsOptions);
solutionsOptions.withAnswer(answerOptions);
final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
final AnswerModelInterface answerModel = Mockito.mock(AnswerModelInterface.class);
given(pointsService.find(solutionModel.getPoint().getId(), pointsOptions)).willReturn(pointModel);
given(answersService.find(solutionModel.getAnswer().getId(), answerOptions)).willReturn(answerModel);
final SolutionModelInterface solutionModelWithRelations = solutionsOptions.withRelations(solutionModel);
Assert.assertEquals(solutionModel, solutionModelWithRelations);
verify(pointsService).find(solutionModel.getPoint().getId(), pointsOptions);
verify(answersService).find(solutionModel.getAnswer().getId(), answerOptions);
verify(solutionModel).setPoint(pointModel);
verify(solutionModel).setAnswer(answerModel);
}
Aggregations