Search in sources :

Example 36 with SubjectModelInterface

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

the class TopicsOptionsTest method testSaveWithRelationsSubject.

@Test
public void testSaveWithRelationsSubject() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final SubjectModelInterface subjectModelId = Mockito.mock(SubjectModelInterface.class);
    given(topicModel.getSubject()).willReturn(subjectModelId);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setSubjectsService(subjectsService);
    topicsOptions.setTopicsService(topicsService);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    topicsOptions.withSubject(subjectsOptions);
    final SubjectModelInterface subjectModel = new SubjectModel();
    topicModel.setSubject(subjectModel);
    final InOrder inOrder = Mockito.inOrder(subjectsService, topicsService);
    topicsOptions.saveWithRelations(topicModel);
    inOrder.verify(subjectsService).save(topicModel.getSubject(), subjectsOptions);
    inOrder.verify(topicsService).save(topicModel);
}
Also used : InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) SubjectModel(easytests.core.models.SubjectModel) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 37 with SubjectModelInterface

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

the class SubjectsServiceTest method testFindByUserAbsentList.

@Test
public void testFindByUserAbsentList() throws Exception {
    final UserModelInterface userModel = this.usersSupport.getModelFixtureMock(0);
    when(this.subjectsMapper.findByUserId(userModel.getId())).thenReturn(new ArrayList<>(0));
    final List<SubjectModelInterface> subjectsFoundedModels = this.subjectsService.findByUser(userModel);
    Assert.assertEquals(0, subjectsFoundedModels.size());
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface)

Example 38 with SubjectModelInterface

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

the class SubjectsServiceTest method testSaveUpdateEntityIdOnCreation.

@Test
public void testSaveUpdateEntityIdOnCreation() throws Exception {
    final Integer id = 5;
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelAdditionalMock(0);
    doAnswer(invocation -> {
        final SubjectEntity subjectEntity = (SubjectEntity) invocation.getArguments()[0];
        subjectEntity.setId(id);
        return null;
    }).when(this.subjectsMapper).insert(any());
    this.subjectsService.save(subjectModel);
    verify(subjectModel, times(1)).setId(id);
}
Also used : SubjectEntity(easytests.core.entities.SubjectEntity) SubjectModelInterface(easytests.core.models.SubjectModelInterface)

Example 39 with SubjectModelInterface

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

the class SubjectsSupport method assertModelsListEquals.

public void assertModelsListEquals(List<SubjectModelInterface> expected, List<SubjectModelInterface> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    Integer i = 0;
    for (SubjectModelInterface subjectModel : expected) {
        this.assertEquals(subjectModel, actual.get(i));
        i++;
    }
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface)

Example 40 with SubjectModelInterface

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

the class SubjectsSupport method getModelMock.

private SubjectModelInterface getModelMock(Integer id, String name, String description, Integer userId) {
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    Mockito.when(subjectModel.getId()).thenReturn(id);
    Mockito.when(subjectModel.getName()).thenReturn(name);
    Mockito.when(subjectModel.getDescription()).thenReturn(description);
    Mockito.when(subjectModel.getUser()).thenReturn(new UserModelEmpty(userId));
    Mockito.when(subjectModel.getTopics()).thenReturn(new ModelsListEmpty());
    Mockito.when(subjectModel.getIssueStandard()).thenReturn(new IssueStandardModelEmpty());
    Mockito.when(subjectModel.getIssues()).thenReturn(new ModelsListEmpty());
    return subjectModel;
}
Also used : ModelsListEmpty(easytests.core.models.empty.ModelsListEmpty) UserModelEmpty(easytests.core.models.empty.UserModelEmpty) IssueStandardModelEmpty(easytests.core.models.empty.IssueStandardModelEmpty) SubjectModelInterface(easytests.core.models.SubjectModelInterface)

Aggregations

SubjectModelInterface (easytests.core.models.SubjectModelInterface)64 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)21 TopicModelInterface (easytests.core.models.TopicModelInterface)18 ArrayList (java.util.ArrayList)16 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)15 SubjectsOptionsInterface (easytests.core.options.SubjectsOptionsInterface)11 UserModelInterface (easytests.core.models.UserModelInterface)9 SubjectEntity (easytests.core.entities.SubjectEntity)7 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)7 SubjectModel (easytests.core.models.SubjectModel)6 InOrder (org.mockito.InOrder)6 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)5 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 TopicEntity (easytests.core.entities.TopicEntity)4 IssueModelInterface (easytests.core.models.IssueModelInterface)4 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)4 IssueStandardQuestionTypeOptionsServiceInterface (easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface)4 IssueStandardTopicPrioritiesServiceInterface (easytests.core.services.IssueStandardTopicPrioritiesServiceInterface)4