Search in sources :

Example 6 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testSaveDeleteWithSubject.

@Test
public void testSaveDeleteWithSubject() {
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final IssuesServiceInterface issuesService = Mockito.mock(IssuesServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    issuesOptions.setIssuesService(issuesService);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.withSubject(subjectsOptions);
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    final IssuesOptionsInterface issuesOptionsSpy = Mockito.spy(issuesOptions);
    issuesOptionsSpy.saveWithRelations(issueModel);
    verify(subjectsService, times(1)).save(issueModel.getSubject(), subjectsOptions);
    issuesOptionsSpy.deleteWithRelations(issueModel);
    verify(subjectsService, times(1)).delete(issueModel.getSubject(), subjectsOptions);
}
Also used : IssuesServiceInterface(easytests.core.services.IssuesServiceInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class IssuesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    issueModel.setId(1);
    given(issueModel.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(Mockito.mock(QuizModelInterface.class));
    given(subjectsService.find(issueModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    given(quizzesService.findByIssue(issueModel, quizzesOptions)).willReturn(quizzesModels);
    final IssueModelInterface issueModelWithRelations = issuesOptions.withRelations(issueModel);
    Assert.assertEquals(issueModel, issueModelWithRelations);
    verify(subjectsService).find(1, subjectsOptions);
    verify(quizzesService).findByIssue(issueModel, quizzesOptions);
    verify(issueModel).setQuizzes(quizzesModels);
    verify(issueModel).setQuizzes(Mockito.anyList());
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class TopicsOptionsTest method testWithRelationsSubjectOnList.

@Test
public void testWithRelationsSubjectOnList() throws Exception {
    final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = new ArrayList<>(2);
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    topicsOptions.setTopicsService(topicsService);
    topicsOptions.setSubjectsService(subjectsService);
    topicsOptions.withSubject(subjectsOptions);
    topicsModels.add(topicModelFirst);
    topicsModels.add(topicModelSecond);
    final SubjectModelInterface subjectModelFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithIdFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelSecond = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithIdSecond = Mockito.mock(SubjectModelInterface.class);
    given(topicModelFirst.getSubject()).willReturn(subjectModelWithIdFirst);
    given(topicModelSecond.getSubject()).willReturn(subjectModelWithIdSecond);
    given(topicModelFirst.getSubject().getId()).willReturn(1);
    given(topicModelSecond.getSubject().getId()).willReturn(2);
    given(subjectsService.find(topicModelFirst.getSubject().getId(), subjectsOptions)).willReturn(subjectModelFirst);
    given(subjectsService.find(topicModelSecond.getSubject().getId(), subjectsOptions)).willReturn(subjectModelSecond);
    final List<TopicModelInterface> topicsModelsWithRelations = topicsOptions.withRelations(topicsModels);
    Assert.assertEquals(topicsModelsWithRelations, topicsModels);
    subjectsService.find(1, subjectsOptions);
    subjectsService.find(2, subjectsOptions);
    verify(topicsModels.get(0)).setSubject(subjectModelFirst);
    verify(topicsModels.get(1)).setSubject(subjectModelSecond);
}
Also used : SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class TopicsOptionsTest method testDeleteWithRelationsSubject.

@Test
public void testDeleteWithRelationsSubject() 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(topicsService, subjectsService);
    topicsOptions.deleteWithRelations(topicModel);
    inOrder.verify(topicsService).delete(topicModel);
    inOrder.verify(subjectsService).save(topicModel.getSubject(), subjectsOptions);
}
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 10 with SubjectsServiceInterface

use of easytests.core.services.SubjectsServiceInterface in project easy-tests by malinink.

the class TopicsOptionsTest method testSaveDeleteWithRelationsSubject.

@Test
public void testSaveDeleteWithRelationsSubject() {
    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);
    topicsOptions.saveWithRelations(topicModel);
    verify(topicsService).save(topicModel);
    topicsOptions.deleteWithRelations(topicModel);
    verify(topicsService).delete(topicModel);
    verify(subjectsService, times(2)).save(topicModel.getSubject(), subjectsOptions);
}
Also used : 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)

Aggregations

SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)19 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 SubjectModelInterface (easytests.core.models.SubjectModelInterface)15 ArrayList (java.util.ArrayList)9 InOrder (org.mockito.InOrder)6 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)5 TopicModelInterface (easytests.core.models.TopicModelInterface)5 UserModelInterface (easytests.core.models.UserModelInterface)5 IssueStandardQuestionTypeOptionsServiceInterface (easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface)5 IssueStandardTopicPrioritiesServiceInterface (easytests.core.services.IssueStandardTopicPrioritiesServiceInterface)5 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)5 IssueModelInterface (easytests.core.models.IssueModelInterface)4 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)4 SubjectModel (easytests.core.models.SubjectModel)3 QuizzesServiceInterface (easytests.core.services.QuizzesServiceInterface)3 IssueStandardQuestionTypeOptionModelInterface (easytests.core.models.IssueStandardQuestionTypeOptionModelInterface)2 IssueStandardTopicPriorityModelInterface (easytests.core.models.IssueStandardTopicPriorityModelInterface)2 QuizModelInterface (easytests.core.models.QuizModelInterface)2 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)2