Search in sources :

Example 6 with QuestionsOptionsInterface

use of easytests.core.options.QuestionsOptionsInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testFindWithOptions.

@Test
public void testFindWithOptions() throws Exception {
    final Integer id = 1;
    final QuestionEntity questionEntity = Entities.createQuestionEntityMock(id, "NewText", 1, 1);
    final QuestionModelInterface questionModel = this.mapQuestionModel(questionEntity);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    given(this.questionsMapper.find(id)).willReturn(questionEntity);
    given(questionsOptions.withRelations(questionModel)).willReturn(questionModel);
    final QuestionModelInterface foundedQuestionModel = this.questionsService.find(id, questionsOptions);
    Assert.assertEquals(questionModel, foundedQuestionModel);
    verify(questionsOptions).withRelations(questionModel);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface)

Example 7 with QuestionsOptionsInterface

use of easytests.core.options.QuestionsOptionsInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testSaveWithOptions.

@Test
public void testSaveWithOptions() throws Exception {
    final QuestionModelInterface questionModel = Models.createQuestionModel(null, "Text", 1, 1);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    this.questionsService.save(questionModel, questionsOptions);
    verify(questionsOptions).saveWithRelations(questionModel);
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface)

Example 8 with QuestionsOptionsInterface

use of easytests.core.options.QuestionsOptionsInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testFindByTopicWithOptions.

@Test
public void testFindByTopicWithOptions() throws Exception {
    final Integer topicId = 7;
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionEntity questionEntityFirst = Entities.createQuestionEntityMock(3, "test3", 1, topicId);
    final QuestionEntity questionEntitySecond = Entities.createQuestionEntityMock(12, "test12", 1, topicId);
    final List<QuestionEntity> questionsEntities = new ArrayList<>();
    questionsEntities.add(questionEntityFirst);
    questionsEntities.add(questionEntitySecond);
    given(topicModel.getId()).willReturn(topicId);
    given(this.questionsMapper.findByTopicId(topicId)).willReturn(questionsEntities);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    questionsModels.add(this.mapQuestionModel(questionEntityFirst));
    questionsModels.add(this.mapQuestionModel(questionEntitySecond));
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    given(questionOptions.withRelations(questionsModels)).willReturn(questionsModels);
    final List<QuestionModelInterface> foundedQuestionsModels = this.questionsService.findByTopic(topicModel, questionOptions);
    verify(this.questionsMapper).findByTopicId(topicId);
    verify(questionOptions).withRelations(questionsModels);
    Assert.assertEquals(questionsModels, foundedQuestionsModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 9 with QuestionsOptionsInterface

use of easytests.core.options.QuestionsOptionsInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testFindAllWithOptions.

@Test
public void testFindAllWithOptions() throws Exception {
    final List<QuestionEntity> questionsEntities = this.getQuestionsEntities();
    final List<QuestionModelInterface> questionsModels = this.getQuestionsModels();
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    given(this.questionsMapper.findAll()).willReturn(questionsEntities);
    given(questionsOptions.withRelations(Mockito.anyList())).willReturn(questionsModels);
    final List<QuestionModelInterface> foundedQuestionsModels = this.questionsService.findAll(questionsOptions);
    verify(questionsOptions).withRelations(questionsModels);
    Assert.assertEquals(questionsModels, foundedQuestionsModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface)

Example 10 with QuestionsOptionsInterface

use of easytests.core.options.QuestionsOptionsInterface in project easy-tests by malinink.

the class QuestionsServiceTest method testSaveEntitiesList.

@Test
public void testSaveEntitiesList() throws Exception {
    final QuestionModelInterface questionModelFirst = Models.createQuestionModel(null, "Text1", 1, 1);
    final QuestionModelInterface questionModelSecond = Models.createQuestionModel(null, "Text2", 2, 1);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    questionsModels.add(questionModelFirst);
    questionsModels.add(questionModelSecond);
    final QuestionsServiceInterface questionsServiceSpy = Mockito.spy(questionsService);
    questionsServiceSpy.save(questionsModels);
    verify(questionsServiceSpy, times(1)).save(questionModelFirst);
    verify(questionsServiceSpy, times(1)).save(questionModelSecond);
    questionsServiceSpy.save(questionsModels, questionsOptions);
    verify(questionsServiceSpy, times(1)).save(questionModelFirst, questionsOptions);
    verify(questionsServiceSpy, times(1)).save(questionModelSecond, questionsOptions);
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface)

Aggregations

QuestionsOptionsInterface (easytests.core.options.QuestionsOptionsInterface)10 QuestionModelInterface (easytests.core.models.QuestionModelInterface)9 QuestionEntity (easytests.core.entities.QuestionEntity)3 ArrayList (java.util.ArrayList)3 TopicModelInterface (easytests.core.models.TopicModelInterface)1 AnswersOptions (easytests.core.options.AnswersOptions)1