插件开发工具库,推荐依赖该工具库。
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.
 
 

65 lines
2.1 KiB

package com.fanruan.api.conf.xml;
import java.util.ArrayList;
import java.util.List;
import com.fanruan.api.conf.impl.xml.XmlColConf;
import com.fanruan.api.conf.impl.xml.XmlConf;
import com.fr.stable.xml.XMLable;
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({XmlHolderKit.class})
public class XmlHolderKitTest {
@Test
public void testOjb() throws Exception {
XMLable xmlable = EasyMock.createMock(XMLable.class);
XmlConf xmlConf = EasyMock.createMock(XmlConf.class);
PowerMock.expectNew(XmlConf.class, xmlable, XMLable.class, "A").andReturn(xmlConf);
EasyMock.replay(xmlable, xmlConf);
PowerMock.replay(XmlConf.class);
Assert.assertEquals(XmlHolderKit.obj(xmlable, XMLable.class, "A"), xmlConf);
EasyMock.verify(xmlable, xmlConf);
PowerMock.verify(XmlConf.class);
}
@Test
public void testCollection() throws Exception {
XmlColConf xmlColConf1 = EasyMock.createMock(XmlColConf.class);
XmlColConf xmlColConf2 = EasyMock.createMock(XmlColConf.class);
List<XMLable> list = new ArrayList<>();
PowerMock.expectNew(XmlColConf.class, list, XMLable.class, true).andReturn(xmlColConf1).times(2);
PowerMock.expectNew(XmlColConf.class, list, XMLable.class, false).andReturn(xmlColConf2).once();
EasyMock.replay(xmlColConf1, xmlColConf2);
PowerMock.replay(XmlColConf.class);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class), xmlColConf1);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class, true), xmlColConf1);
Assert.assertEquals(XmlHolderKit.collection(list, XMLable.class, false), xmlColConf2);
EasyMock.verify(xmlColConf1, xmlColConf2);
PowerMock.verify(XmlColConf.class);
}
}