Search in sources :

Example 21 with AnswerModelInterface

use of easytests.core.models.AnswerModelInterface in project easy-tests by malinink.

the class AnswersServiceTest method testDeleteModelList.

@Test
public void testDeleteModelList() throws Exception {
    final ArgumentCaptor<AnswerEntity> answerEntityCaptor = ArgumentCaptor.forClass(AnswerEntity.class);
    final List<AnswerModelInterface> answersModels = getAnswersFixturesModels();
    this.answersService.delete(answersModels);
    verify(this.answersMapper, times(2)).delete(answerEntityCaptor.capture());
    final List<AnswerEntity> capturedEntities = answerEntityCaptor.getAllValues();
    Integer index = 0;
    for (AnswerModelInterface answerModel : answersModels) {
        this.answersSupport.assertEquals(answerModel, capturedEntities.get(index));
        index++;
    }
}
Also used : AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity)

Example 22 with AnswerModelInterface

use of easytests.core.models.AnswerModelInterface in project easy-tests by malinink.

the class AnswersServiceTest method testSaveUpdateEntityIdOnCreation.

@Test
public void testSaveUpdateEntityIdOnCreation() throws Exception {
    final AnswerModelInterface answerAdditionalModel = this.answersSupport.getModelAdditionalMock(0);
    doAnswer(invocation -> {
        final AnswerEntity answerEntity = (AnswerEntity) invocation.getArguments()[0];
        answerEntity.setId(5);
        return null;
    }).when(this.answersMapper).insert(Mockito.any(AnswerEntity.class));
    this.answersService.save(answerAdditionalModel);
    verify(answerAdditionalModel, times(1)).setId(5);
}
Also used : AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity)

Example 23 with AnswerModelInterface

use of easytests.core.models.AnswerModelInterface in project easy-tests by malinink.

the class AnswersServiceTest method testFindByQuestionWithOptions.

@Test
public void testFindByQuestionWithOptions() throws Exception {
    final ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    final List<AnswerModelInterface> answersModels = getAnswersFixturesModels();
    final List<AnswerEntity> answersEntities = getAnswersFixturesEntities();
    final AnswersOptionsInterface answerOptions = mock(AnswersOptionsInterface.class);
    when(this.answersMapper.findByQuestionId(answersModels.get(0).getQuestion().getId())).thenReturn(answersEntities);
    when(answerOptions.withRelations(listCaptor.capture())).thenReturn(answersModels);
    final List<AnswerModelInterface> answersFoundedModels = this.answersService.findByQuestion(answersModels.get(0).getQuestion(), answerOptions);
    this.assertEquals(answersFoundedModels, listCaptor.getValue());
    Assert.assertSame(answersModels, answersFoundedModels);
    verify(this.answersMapper, times(1)).findByQuestionId(answersModels.get(0).getQuestion().getId());
    verifyNoMoreInteractions(this.answersMapper);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity) AnswersOptionsInterface(easytests.core.options.AnswersOptionsInterface)

Example 24 with AnswerModelInterface

use of easytests.core.models.AnswerModelInterface in project easy-tests by malinink.

the class AnswersServiceTest method testFindAllWithOptions.

@Test
public void testFindAllWithOptions() throws Exception {
    final ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    final List<AnswerEntity> answersEntities = getAnswersFixturesEntities();
    final List<AnswerModelInterface> answersModels = getAnswersFixturesModels();
    final AnswersOptionsInterface answersOptions = mock(AnswersOptionsInterface.class);
    when(this.answersMapper.findAll()).thenReturn(answersEntities);
    when(answersOptions.withRelations(listCaptor.capture())).thenReturn(answersModels);
    final List<AnswerModelInterface> answersFoundedModels = this.answersService.findAll(answersOptions);
    this.assertEquals(answersFoundedModels, listCaptor.getValue());
    Assert.assertSame(answersModels, answersFoundedModels);
    verify(this.answersMapper, times(1)).findAll();
    verifyNoMoreInteractions(this.answersMapper);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity) AnswersOptionsInterface(easytests.core.options.AnswersOptionsInterface)

Example 25 with AnswerModelInterface

use of easytests.core.models.AnswerModelInterface in project easy-tests by malinink.

the class AnswersServiceTest method testSaveCreatesListEntities.

@Test
public void testSaveCreatesListEntities() throws Exception {
    final ArgumentCaptor<AnswerEntity> answerEntityCaptor = ArgumentCaptor.forClass(AnswerEntity.class);
    final List<AnswerModelInterface> answersModels = getAnswersAdditionalModels();
    this.answersService.save(answersModels);
    verify(this.answersMapper, times(2)).insert(answerEntityCaptor.capture());
    final List<AnswerEntity> capturedEntities = answerEntityCaptor.getAllValues();
    Integer index = 0;
    for (AnswerModelInterface answerModel : answersModels) {
        this.answersSupport.assertEquals(answersModels.get(index), capturedEntities.get(index));
        index++;
    }
}
Also used : AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity)

Aggregations

AnswerModelInterface (easytests.core.models.AnswerModelInterface)36 AnswerEntity (easytests.core.entities.AnswerEntity)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)7 AnswerModel (easytests.core.models.AnswerModel)6 QuestionModelInterface (easytests.core.models.QuestionModelInterface)6 AnswersOptionsInterface (easytests.core.options.AnswersOptionsInterface)6 PointModelInterface (easytests.core.models.PointModelInterface)5 SolutionModelInterface (easytests.core.models.SolutionModelInterface)5 TopicModelInterface (easytests.core.models.TopicModelInterface)4 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)4 InOrder (org.mockito.InOrder)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 PointsServiceInterface (easytests.core.services.PointsServiceInterface)3 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)2 QuestionTypeModelEmpty (easytests.core.models.empty.QuestionTypeModelEmpty)2 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)2 QuestionTypesServiceInterface (easytests.core.services.QuestionTypesServiceInterface)2 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)2