答案 0 :(得分:0)
总策略是这样的:
public class ProcessHome {
private static ProcessHome instance = new ProcessHome();
//default Constructor
private ProcessHome() {
}
public static ProcessHome getInstance() {
return instance;
}
public IProcessObj getProcessObj() throws POException {
return ProcessObj.getInstance(); //this is below
}
}
public class ProcessObj implements IProcessObj {
// instance
private static IProcessObj instance;
...
//constuctor
private ProcessObj() throws POException {
init();
}
static IProcessObj getInstance() throws POException {
if (instance == null) {
instance = new ProcessObj();
}
return instance;
}
//jUnit test class
public class ProcessHomeTest {
private IProcessObj iPO = ProcessHome.getInstance()
.ProcessObj();
@Test
public void testIProcessObj() throws Exception {
//use iPO heretest iPO
assertEquals("some","some");
}