/*
* $Id: ProcessControllerFactoryTest.java,v 1.2 2004/11/30 15:05:26 fornp1 Exp $
*
* Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
* Berne University of Applied Sciences
* School of Engineering and Information Technology
* All rights reserved.
*/
package bexee.core;
import junit.framework.TestCase;
import bexee.util.Constants;
/**
* @version $Revision: 1.2 $, $Date: 2004/11/30 15:05:26 $
* @author Patric Fornasier
*/
public class ProcessControllerFactoryTest extends TestCase {
private static final String IMPL = "bexee.core.ProcessControllerFactoryTest$MockProcessController";
protected void tearDown() throws Exception {
super.tearDown();
// make sure to remove that system property again
System.getProperties().remove(Constants.OPT_CONTROLLER);
}
/**
* Test if the factory returns the correct default implementation if no
* system property is set.
*/
public void testGetInstance() {
ProcessController controller = ProcessControllerFactory
.createProcessController();
assertTrue(controller instanceof ProcessControllerImpl);
}
/**
* Test whether the factory returns the default implementation if an invalid
* class name is provided.
*/
public void testWrongClassName()
{
// set an invalid class name
System.setProperty(Constants.OPT_CONTROLLER, "nonExistingClass");
// check if the default implementation is created
ProcessController controller = ProcessControllerFactory.createProcessController();
assertTrue(controller instanceof ProcessControllerImpl);
}
/**
* Test whether the factory returns the right implementation based on a
* system property.
*/
public void testGetInstanceBySystemProperty() {
// set a different implementation
System.setProperty(Constants.OPT_CONTROLLER, IMPL);
ProcessController controller = ProcessControllerFactory
.createProcessController();
assertTrue(controller instanceof ProcessControllerFactoryTest.MockProcessController);
}
/**
* Mock class extending the <code>ProcessControllerImpl</code> for
* testing.
*
* @version $Revision: 1.2 $, $Date: 2004/11/30 15:05:26 $
* @author Patric Fornasier
*/
public static class MockProcessController extends ProcessControllerImpl {
}
}
|