|
|
@@ -0,0 +1,68 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.ActivityRegistration;
|
|
|
+import com.etotem.cfc.mapper.ActivityRegistrationMapper;
|
|
|
+import com.etotem.cfc.service.ActivityRegistrationService;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.*;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.*;
|
|
|
+
|
|
|
+class ActivityRegistrationRejectTest {
|
|
|
+
|
|
|
+ private ActivityRegistrationService serviceWith(ActivityRegistrationMapper mapper) throws Exception {
|
|
|
+ ActivityRegistrationService svc = new ActivityRegistrationService();
|
|
|
+ Field f = ActivityRegistrationService.class.getDeclaredField("registrationMapper");
|
|
|
+ f.setAccessible(true);
|
|
|
+ f.set(svc, mapper);
|
|
|
+ return svc;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 驳回写入状态与原因() throws Exception {
|
|
|
+ ActivityRegistrationMapper mapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(mapper);
|
|
|
+ ActivityRegistration reg = new ActivityRegistration();
|
|
|
+ reg.setId(1L);
|
|
|
+ reg.setStatus("pending");
|
|
|
+ when(mapper.selectById(1L)).thenReturn(reg);
|
|
|
+ when(mapper.updateById(any())).thenReturn(1);
|
|
|
+
|
|
|
+ svc.reject(1L, 9L, "信息不完整");
|
|
|
+
|
|
|
+ assertEquals("rejected", reg.getStatus());
|
|
|
+ assertEquals("信息不完整", reg.getRejectReason());
|
|
|
+ verify(mapper).updateById(reg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 非待审状态不允许驳回() throws Exception {
|
|
|
+ ActivityRegistrationMapper mapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(mapper);
|
|
|
+ ActivityRegistration reg = new ActivityRegistration();
|
|
|
+ reg.setId(2L);
|
|
|
+ reg.setStatus("approved");
|
|
|
+ when(mapper.selectById(2L)).thenReturn(reg);
|
|
|
+
|
|
|
+ Result<Void> result = svc.reject(2L, 9L, "x");
|
|
|
+
|
|
|
+ assertEquals(500, result.getCode());
|
|
|
+ verify(mapper, never()).updateById(any());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void 记录不存在返回错误() throws Exception {
|
|
|
+ ActivityRegistrationMapper mapper = mock(ActivityRegistrationMapper.class);
|
|
|
+ ActivityRegistrationService svc = serviceWith(mapper);
|
|
|
+ when(mapper.selectById(3L)).thenReturn(null);
|
|
|
+
|
|
|
+ Result<Void> result = svc.reject(3L, 9L, "x");
|
|
|
+
|
|
|
+ assertEquals(500, result.getCode());
|
|
|
+ verify(mapper, never()).updateById(any());
|
|
|
+ }
|
|
|
+}
|