Search in sources :

Example 16 with AnswerEntity

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

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

Example 18 with AnswerEntity

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

the class AnswersMapperTest method testFind.

@Test
public void testFind() throws Exception {
    final AnswerEntity answer = this.answersMapper.find(1);
    Assert.assertEquals((Integer) 1, answer.getId());
    Assert.assertEquals("Answer1", answer.getTxt());
    Assert.assertEquals((Integer) 1, answer.getQuestionId());
    Assert.assertEquals(true, answer.getRight());
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with AnswerEntity

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

the class AnswersMapperTest method testFindByQuestionId.

@Test
public void testFindByQuestionId() throws Exception {
    final List<AnswerEntity> answers = this.answersMapper.findByQuestionId(1);
    Assert.assertEquals((Integer) 1, (Integer) answers.size());
    final AnswerEntity answer = answers.get(0);
    Assert.assertEquals((Integer) 1, answer.getId());
    Assert.assertEquals("Answer1", answer.getTxt());
    Assert.assertEquals((Integer) 1, answer.getQuestionId());
    Assert.assertEquals(true, answer.getRight());
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with AnswerEntity

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

the class AnswersService method save.

@Override
public void save(AnswerModelInterface answerModel) {
    final AnswerEntity answerEntity = this.map(answerModel);
    if (answerEntity.getId() == null) {
        this.answersMapper.insert(answerEntity);
        answerModel.setId(answerEntity.getId());
        return;
    }
    this.answersMapper.update(answerEntity);
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity)

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