//registry Class
public class Registry
{
private static final Logger logger = LogFactory
.getLogger(Registry.class);
protected Service service = new serviceMLImpl();
private static Registry instance = new Registry();
public static Registry getInstance()
{
return instance;
}
public static void setInstance(Registry instance)
{
Registry.instance = instance;
}
public Helper getHelper()
{
return new Helper();
}
}
//Helper Class
public class Helper
{
protected Service service = ServiceRegistry
.getService();
public Helper()
{
}
public void sendInfo(Info info)
throws Exception
{
service.sendInfo(info);
}
public void sendFacilitySFPListNotification(
List<GcpFacilitySFPInfo> esfpPortList)
{
gfpGcpService.sendFacilitySFPListNotification(esfpPortList);
}
}
//Test Class
public class RegistryTest
{
Registry registry = new Registry();
Helper helper = createMock(Helper.class);
@Before
public void setUp() throws Exception
{
}
@After
public void tearDown() throws Exception
{
registry = null;
}
@Test
public void testGetInstance()
{
replayAll();
registry.getInstance();
verifyAll();
}
@Test
public void testSetInstance()
{
replayAll();
registry.setInstance(registry);
verifyAll();
}
@Test
public void testGetHelper()
{
**replayAll();
new Helper();
registry.getHelper(); // getting InitializationExceptionError here
verifyAll();** //
}
}
有两个类,帮助程序和注册表类。我尝试为注册表类编写junit,但在测试类中得到了 InitializationException 。
这是我在registry.getHelper()中遇到的错误:
java.lang.ExceptionInInitializerError at java.lang.Class.forName0(Native Method) at
java.lang.Class.forName(Class.java:169) at
javassist.runtime.Desc.getClassObject(Desc.java:44) at
javassist.runtime.Desc.getClassType(Desc.java:153) at
javassist.runtime.Desc.getType(Desc.java:123) at
javassist.runtime.Desc.getType(Desc.java:79) at
com.att.bbnms.cim.gfpgcp.service.ServiceRegistry.getService(ServiceRegistry.java:41) at
com.att.bbnms.cim.nc.service.link.Helper.(Helper.java:14) at
com.att.bbnms.cim.nc.service.link.Registry.getHelper(Registry.java:26) at
com.att.bbnms.cim.nc.service.link.egistryTest.testGetHelper(RegistryTest.java:63) at
org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66) at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:312) at
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:86) at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94) at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296) at
在为 Helper 编写测试用例时,我无法上课。 请告诉您是否有任何解决方案。