You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.2 KiB
62 lines
2.2 KiB
package com.fanruan.api.util; |
|
|
|
import com.fanruan.api.json.JSONKit; |
|
import com.fr.js.HyperlinkUtils; |
|
import com.fr.js.NameJavaScriptGroup; |
|
import com.fr.json.JSONArray; |
|
import com.fr.stable.web.Repository; |
|
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; |
|
|
|
/** |
|
* @author Lucian.Chen |
|
* @version 10.0 |
|
* Created by Lucian.Chen on 2020/3/24 |
|
*/ |
|
@RunWith(PowerMockRunner.class) |
|
@PrepareForTest({HyperlinkUtils.class}) |
|
public class HyperKitTest { |
|
|
|
@Test |
|
public void testWriteJS() { |
|
NameJavaScriptGroup g = EasyMock.createMock(NameJavaScriptGroup.class); |
|
Repository repo = EasyMock.createMock(Repository.class); |
|
PowerMock.mockStatic(HyperlinkUtils.class); |
|
EasyMock.expect(HyperlinkUtils.writeJSLinkContent(g, repo)).andReturn("A").once(); |
|
EasyMock.expect(HyperlinkUtils.writeJSLinkContent(g, repo)).andReturn("B").once(); |
|
|
|
EasyMock.replay(g, repo); |
|
PowerMock.replay(HyperlinkUtils.class); |
|
|
|
Assert.assertEquals(HyperKit.writeJSLinkContent(g, repo), "A"); |
|
Assert.assertEquals(HyperKit.writeJSLinkContent(g, repo), "B"); |
|
|
|
EasyMock.verify(g, repo); |
|
PowerMock.verify(HyperlinkUtils.class); |
|
} |
|
|
|
@Test |
|
public void testCreateJSLink() { |
|
JSONArray array1 = JSONKit.createJSONArray("[]"); |
|
JSONArray array2 = JSONKit.createJSONArray("[{\"1\":\"a\"}, {\"1\":\"b\"}]"); |
|
NameJavaScriptGroup g = EasyMock.createMock(NameJavaScriptGroup.class); |
|
Repository repo = EasyMock.createMock(Repository.class); |
|
PowerMock.mockStatic(HyperlinkUtils.class); |
|
EasyMock.expect(HyperlinkUtils.createJSLink(g, repo)).andReturn(array1).once(); |
|
EasyMock.expect(HyperlinkUtils.createJSLink(g, repo)).andReturn(array2).once(); |
|
|
|
EasyMock.replay(g, repo); |
|
PowerMock.replay(HyperlinkUtils.class); |
|
|
|
Assert.assertEquals(HyperKit.createJSLink(g, repo), array1); |
|
Assert.assertEquals(HyperKit.createJSLink(g, repo), array2); |
|
|
|
EasyMock.verify(g, repo); |
|
PowerMock.verify(HyperlinkUtils.class); |
|
} |
|
}
|
|
|