Search in sources :

Example 11 with PointEntity

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

the class PointsServiceTest method testFindByQuiz.

@Test
public void testFindByQuiz() throws Exception {
    final Integer quizId = 5;
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    final PointEntity pointEntityFirst = Entities.createPointEntityMock(1, 1, 1);
    final PointEntity pointEntitySecond = Entities.createPointEntityMock(4, 4, 4);
    final List<PointEntity> pointsEntities = new ArrayList<>();
    pointsEntities.add(pointEntityFirst);
    pointsEntities.add(pointEntitySecond);
    given(this.pointsMapper.findByQuizId(quizId)).willReturn(pointsEntities);
    final List<PointModelInterface> pointsModels = new ArrayList<>();
    pointsModels.add(this.mapPointModel(pointEntityFirst));
    pointsModels.add(this.mapPointModel(pointEntitySecond));
    final List<PointModelInterface> foundPointsModels = this.pointsService.findByQuiz(quizModel);
    verify(this.pointsMapper).findByQuizId(quizId);
    Assert.assertEquals(pointsModels, foundPointsModels);
}
Also used : ArrayList(java.util.ArrayList) PointEntity(easytests.core.entities.PointEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with PointEntity

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

the class PointsServiceTest method testSaveUpdatesEntity.

@Test
public void testSaveUpdatesEntity() throws Exception {
    final ArgumentCaptor<PointEntity> pointEntityCaptor = ArgumentCaptor.forClass(PointEntity.class);
    final PointModelInterface pointModel = this.pointsSupport.getModelFixtureMock(0);
    this.pointsService.save(pointModel);
    verify(this.pointsMapper, times(1)).update(pointEntityCaptor.capture());
    this.pointsSupport.assertEquals(this.pointsSupport.getEntityFixtureMock(0), pointEntityCaptor.getValue());
}
Also used : PointEntity(easytests.core.entities.PointEntity) PointModelInterface(easytests.core.models.PointModelInterface) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with PointEntity

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

the class PointsServiceTest method testSaveUpdateEntityIdOnCreation.

@Test
public void testSaveUpdateEntityIdOnCreation() throws Exception {
    final Integer id = 5;
    final PointModelInterface pointModel = this.pointsSupport.getModelAdditionalMock(0);
    doAnswer(invocation -> {
        final PointEntity answerEntity = (PointEntity) invocation.getArguments()[0];
        answerEntity.setId(id);
        return null;
    }).when(this.pointsMapper).insert(any());
    this.pointsService.save(pointModel);
    verify(pointModel, times(1)).setId(id);
}
Also used : PointEntity(easytests.core.entities.PointEntity) PointModelInterface(easytests.core.models.PointModelInterface) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with PointEntity

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

the class PointsSupport method getEntityMock.

private PointEntity getEntityMock(Integer id, Integer quizId, Integer questionId) {
    final PointEntity pointEntity = Mockito.mock(PointEntity.class);
    Mockito.when(pointEntity.getId()).thenReturn(id);
    Mockito.when(pointEntity.getQuizId()).thenReturn(quizId);
    Mockito.when(pointEntity.getQuestionId()).thenReturn(questionId);
    return pointEntity;
}
Also used : PointEntity(easytests.core.entities.PointEntity)

Example 15 with PointEntity

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

the class PointsMapperTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final PointEntity pointChangedEntity = this.pointsSupport.getEntityAdditionalMock(1);
    final PointEntity pointBeforeUpdateEntity = this.pointsMapper.find(pointChangedEntity.getId());
    Assert.assertNotNull(pointBeforeUpdateEntity);
    this.pointsSupport.assertNotEqualsWithoutId(pointChangedEntity, pointBeforeUpdateEntity);
    this.pointsMapper.update(pointChangedEntity);
    final PointEntity pointUpdatedEntity = this.pointsMapper.find(pointChangedEntity.getId());
    this.pointsSupport.assertEquals(pointChangedEntity, pointUpdatedEntity);
}
Also used : PointEntity(easytests.core.entities.PointEntity) Test(org.junit.Test)

Aggregations

PointEntity (easytests.core.entities.PointEntity)23 Test (org.junit.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ArrayList (java.util.ArrayList)4 PointModelInterface (easytests.core.models.PointModelInterface)3 PointsOptionsInterface (easytests.core.options.PointsOptionsInterface)3 QuizModelInterface (easytests.core.models.QuizModelInterface)1 QuestionModelEmpty (easytests.core.models.empty.QuestionModelEmpty)1 QuizModelEmpty (easytests.core.models.empty.QuizModelEmpty)1 DeleteUnidentifiedModelException (easytests.core.services.exceptions.DeleteUnidentifiedModelException)1 Ignore (org.junit.Ignore)1