|
|
|
package com.fanruan.api.decision;
|
|
|
|
|
|
|
|
import com.fr.base.Base64;
|
|
|
|
import com.fr.base.ServerConfig;
|
|
|
|
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.awt.*;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Lucian.Chen
|
|
|
|
* @version 10.0
|
|
|
|
* Created by Lucian.Chen on 2020/3/24
|
|
|
|
*/
|
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
|
@PrepareForTest(ServerConfig.class)
|
|
|
|
public class CommonKitTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testIsDefaultPassword() {
|
|
|
|
Assert.assertTrue(CommonKit.isDefaultPasswordHolderString("********"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testFetchDefaultPassword() {
|
|
|
|
Assert.assertEquals(CommonKit.fetchDefaultPasswordHolderString(), "********");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetBase64DecodeStr() throws UnsupportedEncodingException {
|
|
|
|
ServerConfig serverConfig = EasyMock.createMock(ServerConfig.class);
|
|
|
|
PowerMock.mockStatic(ServerConfig.class);
|
|
|
|
EasyMock.expect(ServerConfig.getInstance()).andReturn(serverConfig).anyTimes();
|
|
|
|
EasyMock.expect(serverConfig.getServerCharset()).andReturn("utf-8").anyTimes();
|
|
|
|
|
|
|
|
EasyMock.replay(serverConfig);
|
|
|
|
PowerMock.replay(ServerConfig.class);
|
|
|
|
String result = new String(Base64.decode("a"), "utf-8");
|
|
|
|
Assert.assertEquals(CommonKit.getBase64DecodeStr("a"), result);
|
|
|
|
Assert.assertEquals(CommonKit.getBase64DecodeStr(""), "");
|
|
|
|
|
|
|
|
EasyMock.verify(serverConfig);
|
|
|
|
PowerMock.verify(ServerConfig.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testEncode() {
|
|
|
|
Image im = new BufferedImage(1, 1, 1);
|
|
|
|
String result = Base64.encode(im, "");
|
|
|
|
Assert.assertEquals(result, CommonKit.encode(im, ""));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void ajaxRequest() throws Exception {
|
|
|
|
Class<?> classBook = Class.forName("com.fanruan.api.decision.CommonKit");
|
|
|
|
Assert.assertNotNull(classBook);
|
|
|
|
|
|
|
|
Method method1 = classBook.getDeclaredMethod("ajaxRequest", HttpServletRequest.class);
|
|
|
|
Assert.assertNotNull(method1);
|
|
|
|
}
|
|
|
|
}
|