|
|
|
package com.fanruan.api.decision.user;
|
|
|
|
|
|
|
|
import com.fr.decision.webservice.v10.user.UserService;
|
|
|
|
import org.easymock.EasyMock;
|
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.powermock.api.easymock.PowerMock;
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Zed
|
|
|
|
* @version 10.0
|
|
|
|
* Created by Zed on 2020/4/30
|
|
|
|
*/
|
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
|
@PrepareForTest({UserService.class})
|
|
|
|
public class UserKitTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getCurrentUserId() throws Exception {
|
|
|
|
|
|
|
|
Class<?> classBook = Class.forName("com.fanruan.api.decision.user.UserKit");
|
|
|
|
Assert.assertNotNull(classBook);
|
|
|
|
|
|
|
|
Method method1 = classBook.getDeclaredMethod("getCurrentUserId", HttpServletRequest.class);
|
|
|
|
Assert.assertNotNull(method1);
|
|
|
|
|
|
|
|
Method method2 = classBook.getDeclaredMethod("getCurrentUserIdFromCookie", HttpServletRequest.class);
|
|
|
|
Assert.assertNotNull(method2);
|
|
|
|
|
|
|
|
Method method3 = classBook.getDeclaredMethod("existUsername", String.class);
|
|
|
|
Assert.assertNotNull(method3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetAdminUserIdList() throws Exception {
|
|
|
|
List<String> adminUserIdList = new ArrayList<>();
|
|
|
|
adminUserIdList.add("1");
|
|
|
|
|
|
|
|
UserService userService = EasyMock.createMock(UserService.class);
|
|
|
|
EasyMock.expect(userService.getAdminUserIdList()).andReturn(adminUserIdList);
|
|
|
|
EasyMock.replay(userService);
|
|
|
|
|
|
|
|
PowerMock.mockStatic(UserService.class);
|
|
|
|
EasyMock.expect(UserService.getInstance()).andReturn(userService);
|
|
|
|
PowerMock.replay(UserService.class);
|
|
|
|
|
|
|
|
Assert.assertEquals(UserKit.getAdminUserIdList(), adminUserIdList);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|