Search in sources :

Example 11 with AnswerEntity

use of easytests.core.entities.AnswerEntity in project easy-tests by malinink.

the class AnswersMapperTest method testInsert.

@Test
public void testInsert() throws Exception {
    final Integer id = this.answersMapper.findAll().size() + 1;
    final String txt = "Text";
    final Integer questionId = 1;
    final Boolean right = true;
    AnswerEntity answerEntity = Mockito.mock(AnswerEntity.class);
    Mockito.when(answerEntity.getTxt()).thenReturn(txt);
    Mockito.when(answerEntity.getQuestionId()).thenReturn(questionId);
    Mockito.when(answerEntity.getRight()).thenReturn(right);
    this.answersMapper.insert(answerEntity);
    verify(answerEntity, times(1)).setId(id);
    answerEntity = this.answersMapper.find(id);
    Assert.assertEquals(id, answerEntity.getId());
    Assert.assertEquals(txt, answerEntity.getTxt());
    Assert.assertEquals(questionId, answerEntity.getQuestionId());
    Assert.assertEquals(right, answerEntity.getRight());
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with AnswerEntity

use of easytests.core.entities.AnswerEntity in project easy-tests by malinink.

the class AnswersSupport method getEntityMock.

private AnswerEntity getEntityMock(Integer id, String txt, Integer questionId, Integer serialNumber, Boolean right) {
    final AnswerEntity answerEntity = Mockito.mock(AnswerEntity.class);
    Mockito.when(answerEntity.getId()).thenReturn(id);
    Mockito.when(answerEntity.getTxt()).thenReturn(txt);
    Mockito.when(answerEntity.getQuestionId()).thenReturn(questionId);
    Mockito.when(answerEntity.getSerialNumber()).thenReturn(serialNumber);
    Mockito.when(answerEntity.getRight()).thenReturn(right);
    return answerEntity;
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity)

Example 13 with AnswerEntity

use of easytests.core.entities.AnswerEntity 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 14 with AnswerEntity

use of easytests.core.entities.AnswerEntity 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 15 with AnswerEntity

use of easytests.core.entities.AnswerEntity 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)

Aggregations

AnswerEntity (easytests.core.entities.AnswerEntity)23 AnswerModelInterface (easytests.core.models.AnswerModelInterface)10 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 AnswersOptionsInterface (easytests.core.options.AnswersOptionsInterface)3 ArrayList (java.util.ArrayList)3 List (java.util.List)2 QuestionModelInterface (easytests.core.models.QuestionModelInterface)1 QuestionModelEmpty (easytests.core.models.empty.QuestionModelEmpty)1 DeleteUnidentifiedModelException (easytests.core.services.exceptions.DeleteUnidentifiedModelException)1