Browse Source

Merge branch 'theme2course' into 'Develop'

增加单测



See merge request !1146

menduo 5 years ago
parent
commit
f9d352e7d6

+ 88 - 0
mooctest-site-server/src/test/java/cn/iselab/mooctest/site/web/logic/impl/ThemeLogicImplTest.java

@@ -0,0 +1,88 @@
+package cn.iselab.mooctest.site.web.logic.impl;
+
+import cn.iselab.mooctest.site.common.enums.EntityTypeEnum;
+import cn.iselab.mooctest.site.models.CourseResource;
+import cn.iselab.mooctest.site.models.ThemeDetail;
+import cn.iselab.mooctest.site.models.ThemeEntityRelations;
+import cn.iselab.mooctest.site.service.CourseResourceService;
+import cn.iselab.mooctest.site.service.ThemeService;
+import cn.iselab.mooctest.site.web.data.CourseResourceVO;
+import cn.iselab.mooctest.site.web.data.ThemeVO;
+import cn.iselab.mooctest.site.web.data.wrapper.CourseResourceVOWrapper;
+import cn.iselab.mooctest.site.web.data.wrapper.ThemeVOWrapper;
+import cn.iselab.mooctest.site.web.logic.ThemeLogic;
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.when;
+
+/**
+ * @program: mooctest-site
+ * @mail: menduo96@gmail.com
+ * @author: duomen
+ * @create: 2020/2/2
+ **/
+
+@RunWith(MockitoJUnitRunner.class)
+@WebAppConfiguration
+public class ThemeLogicImplTest {
+
+    @InjectMocks
+    private ThemeLogic themeLogic = new ThemeLogicImpl();
+    @Mock
+    private CourseResourceService courseResourceService;
+    @Mock
+    private CourseResourceVOWrapper courseResourceVOWrapper;
+    @Mock
+    private ThemeService themeService;
+    @Mock
+    private ThemeVOWrapper themeVOWrapper;
+
+
+    @Test
+    public void test_getTheme() {
+        ThemeDetail themeDetail = new ThemeDetail();
+        themeDetail.setId(1L);
+        themeDetail.setOwnerId(2L);
+        themeDetail.setIntroduce("哈哈哈");
+        themeDetail.setPublicStatus(0);
+        themeDetail.setType(0);
+
+        ThemeEntityRelations themeEntityRelations1 = new ThemeEntityRelations();
+        themeEntityRelations1.setId(1L);
+        themeEntityRelations1.setEntityId(1L);
+        themeEntityRelations1.setEntityType(EntityTypeEnum.COURSE_RESOURCE);
+        themeEntityRelations1.setThemeId(1L);
+        List<ThemeEntityRelations> themeEntityRelations = Lists.newArrayList(themeEntityRelations1);
+
+        CourseResource courseResource = new CourseResource();
+        courseResource.setId(1L);
+        List<CourseResource> courseResources  = Lists.newArrayList(courseResource);
+        when(themeService.getThemeDetailById(anyLong())).thenReturn(themeDetail);
+        when(themeService.getThemeEntityRelations(anyLong())).thenReturn(themeEntityRelations);
+        when(courseResourceService.getCourseResourceById(anyList())).thenReturn(courseResources);
+        ThemeVO result = new ThemeVO();
+        when(themeVOWrapper.wrapper(any())).thenReturn(result);
+        ThemeVO themeVO = themeLogic.getTheme(1L);
+        assertNotNull(themeVO);
+    }
+
+    @Test
+    public void test_getCourseResourceById() {
+        CourseResource courseResource = new CourseResource();
+        CourseResourceVO courseResourceVO = new CourseResourceVO();
+        when(courseResourceService.getCourseResourceByResourceId(1L)).thenReturn(courseResource);
+        when(courseResourceVOWrapper.wrap(courseResource)).thenReturn(courseResourceVO);
+        CourseResourceVO courseResource1 = themeLogic.getCourseResourceById(1L);
+        assertEquals(courseResource.getId(),courseResource1.getId());
+    }
+}