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());
}
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);
}
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());
}
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());
}
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);
}
Aggregations