Search in sources :

Example 6 with AnswerEntity

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

the class AnswersServiceTest method testSaveCreatesEntity.

@Test
public void testSaveCreatesEntity() throws Exception {
    final AnswerModelInterface answerModel = this.createAnswerModel(null, "Answer11", 1, 1, true);
    doAnswer(invocation -> {
        final AnswerEntity answerEntity = (AnswerEntity) invocation.getArguments()[0];
        answerEntity.setId(100);
        return null;
    }).when(this.answersMapper).insert(Mockito.any(AnswerEntity.class));
    this.answersService.save(answerModel);
    verify(this.answersMapper, times(1)).insert(this.mapAnswerEntity(answerModel));
    Assert.assertEquals((Integer) 100, answerModel.getId());
}
Also used : AnswerModelInterface(easytests.core.models.AnswerModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity)

Example 7 with AnswerEntity

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

the class AnswersService method delete.

@Override
public void delete(AnswerModelInterface answerModel) {
    final AnswerEntity answerEntity = this.map(answerModel);
    if (answerEntity.getId() == null) {
        throw new DeleteUnidentifiedModelException();
    }
    this.answersMapper.delete(answerEntity);
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity) DeleteUnidentifiedModelException(easytests.core.services.exceptions.DeleteUnidentifiedModelException)

Example 8 with AnswerEntity

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

the class AnswerModelTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer id = 3;
    final String txt = "Text";
    final Integer questionId = 5;
    final Integer serialNumber = 3;
    final Boolean right = true;
    final AnswerEntity answerEntity = Mockito.mock(AnswerEntity.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    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);
    final AnswerModel answerModel = new AnswerModel();
    answerModel.map(answerEntity);
    Assert.assertEquals(id, answerModel.getId());
    Assert.assertEquals(txt, answerModel.getTxt());
    Assert.assertEquals(right, answerModel.getRight());
    Assert.assertEquals(serialNumber, answerModel.getSerialNumber());
    Assert.assertEquals(new QuestionModelEmpty(questionId), answerModel.getQuestion());
}
Also used : QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) AnswerEntity(easytests.core.entities.AnswerEntity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with AnswerEntity

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

the class AnswersMapperTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final Integer id = 1;
    final String txt = "Answer1";
    final Integer questionId = 1;
    final Boolean right = true;
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    AnswerEntity answerEntity = this.answersMapper.find(id);
    Assert.assertNotNull(answerEntity);
    Assert.assertEquals(id, answerEntity.getId());
    Assert.assertEquals(txt, answerEntity.getTxt());
    Assert.assertEquals(questionId, answerEntity.getQuestionId());
    Assert.assertEquals(right, answerEntity.getRight());
    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.getRight()).thenReturn(right);
    this.answersMapper.update(answerEntity);
    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 : QuestionModelInterface(easytests.core.models.QuestionModelInterface) AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with AnswerEntity

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

the class AnswersMapperTest method testDelete.

@Test
public void testDelete() throws Exception {
    AnswerEntity answerEntity = this.answersMapper.find(1);
    Assert.assertNotNull(answerEntity);
    this.answersMapper.delete(answerEntity);
    answerEntity = this.answersMapper.find(1);
    Assert.assertNull(answerEntity);
}
Also used : AnswerEntity(easytests.core.entities.AnswerEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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