Search in sources :

Example 6 with TopicModelInterface

use of easytests.core.models.TopicModelInterface in project easy-tests by malinink.

the class TopicsServiceTest method testFindWithOptions.

@Test
public void testFindWithOptions() throws Exception {
    final ArgumentCaptor<TopicModelInterface> topicModelCaptor = ArgumentCaptor.forClass(TopicModelInterface.class);
    final TopicEntity topicEntity = this.topicsSupport.getEntityFixtureMock(0);
    final TopicModelInterface topicModel = this.topicsSupport.getModelFixtureMock(0);
    final TopicsOptionsInterface topicOptions = mock(TopicsOptionsInterface.class);
    when(this.topicsMapper.find(topicModel.getId())).thenReturn(topicEntity);
    when(topicOptions.withRelations(topicModelCaptor.capture())).thenReturn(topicModel);
    final TopicModelInterface topicFoundedModel = this.topicsService.find(topicModel.getId(), topicOptions);
    this.topicsSupport.assertEquals(topicModel, topicModelCaptor.getValue());
    Assert.assertSame(topicModel, topicFoundedModel);
    this.assertServicesSet(topicOptions);
}
Also used : TopicsOptionsInterface(easytests.core.options.TopicsOptionsInterface) TopicEntity(easytests.core.entities.TopicEntity) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with TopicModelInterface

use of easytests.core.models.TopicModelInterface in project easy-tests by malinink.

the class TopicsServiceTest method testFindBySubjectAbsentList.

@Test
public void testFindBySubjectAbsentList() throws Exception {
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelFixtureMock(0);
    when(this.topicsMapper.findBySubjectId(subjectModel.getId())).thenReturn(new ArrayList<>(0));
    final List<TopicModelInterface> topicFoundedModels = this.topicsService.findBySubject(subjectModel);
    Assert.assertNotNull(topicFoundedModels);
    Assert.assertEquals(0, topicFoundedModels.size());
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with TopicModelInterface

use of easytests.core.models.TopicModelInterface in project easy-tests by malinink.

the class TopicsServiceTest method testSaveModelsListWithOptions.

@Test
public void testSaveModelsListWithOptions() throws Exception {
    final ArgumentCaptor<TopicModelInterface> topicModelCaptor = ArgumentCaptor.forClass(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = this.getTopicsFixturesModels();
    final TopicsOptionsInterface topicsOptions = mock(TopicsOptionsInterface.class);
    this.topicsService.save(topicsModels, topicsOptions);
    this.assertServicesSet(topicsOptions, topicsModels.size());
    verify(topicsOptions, times(topicsModels.size())).saveWithRelations(topicModelCaptor.capture());
    this.topicsSupport.assertModelsListEquals(topicsModels, topicModelCaptor.getAllValues());
    verifyNoMoreInteractions(this.topicsMapper);
}
Also used : TopicsOptionsInterface(easytests.core.options.TopicsOptionsInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with TopicModelInterface

use of easytests.core.models.TopicModelInterface in project easy-tests by malinink.

the class TopicsServiceTest method testFindBySubjectWithOptions.

@Test
public void testFindBySubjectWithOptions() throws Exception {
    final ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    final List<TopicEntity> topicsEntities = this.getTopicsFixturesEntities();
    final List<TopicModelInterface> topicsModels = this.getTopicsFixturesModels();
    final TopicsOptionsInterface topicOptions = mock(TopicsOptionsInterface.class);
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelFixtureMock(0);
    when(this.topicsMapper.findBySubjectId(subjectModel.getId())).thenReturn(topicsEntities);
    when(topicOptions.withRelations(listCaptor.capture())).thenReturn(topicsModels);
    final List<TopicModelInterface> topicsFoundedModels = this.topicsService.findBySubject(subjectModel, topicOptions);
    this.topicsSupport.assertModelsListEquals(topicsModels, listCaptor.getValue());
    Assert.assertSame(topicsModels, topicsFoundedModels);
    this.assertServicesSet(topicOptions);
}
Also used : TopicsOptionsInterface(easytests.core.options.TopicsOptionsInterface) TopicEntity(easytests.core.entities.TopicEntity) ArrayList(java.util.ArrayList) List(java.util.List) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with TopicModelInterface

use of easytests.core.models.TopicModelInterface in project easy-tests by malinink.

the class TopicsServiceTest method testSaveUpdatesEntityIdOnCreation.

@Test
public void testSaveUpdatesEntityIdOnCreation() throws Exception {
    final TopicModelInterface topicAdditionalModel = this.topicsSupport.getModelAdditionalMock(0);
    final Integer updatedId = 10;
    doAnswer(invocation -> {
        final TopicEntity topicEntity = invocation.getArgument(0);
        topicEntity.setId(updatedId);
        return null;
    }).when(this.topicsMapper).insert(any(TopicEntity.class));
    this.topicsService.save(topicAdditionalModel);
    verify(topicAdditionalModel, times(1)).setId(updatedId);
}
Also used : TopicEntity(easytests.core.entities.TopicEntity) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TopicModelInterface (easytests.core.models.TopicModelInterface)52 Test (org.junit.Test)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 SubjectModelInterface (easytests.core.models.SubjectModelInterface)18 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)16 ArrayList (java.util.ArrayList)15 QuestionModelInterface (easytests.core.models.QuestionModelInterface)14 TopicsOptionsInterface (easytests.core.options.TopicsOptionsInterface)9 TopicEntity (easytests.core.entities.TopicEntity)8 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)7 InOrder (org.mockito.InOrder)6 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)5 AnswerModelInterface (easytests.core.models.AnswerModelInterface)4 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)4 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 QuestionEntity (easytests.core.entities.QuestionEntity)3 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)3 SubjectModel (easytests.core.models.SubjectModel)3 TopicModel (easytests.core.models.TopicModel)3