01: /*
02: * $Id: ProcessControllerFactoryTest.java,v 1.2 2004/11/30 15:05:26 fornp1 Exp $
03: *
04: * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
05: * Berne University of Applied Sciences
06: * School of Engineering and Information Technology
07: * All rights reserved.
08: */
09: package bexee.core;
10:
11: import junit.framework.TestCase;
12: import bexee.util.Constants;
13:
14: /**
15: * @version $Revision: 1.2 $, $Date: 2004/11/30 15:05:26 $
16: * @author Patric Fornasier
17: */
18: public class ProcessControllerFactoryTest extends TestCase {
19:
20: private static final String IMPL = "bexee.core.ProcessControllerFactoryTest$MockProcessController";
21:
22: protected void tearDown() throws Exception {
23: super .tearDown();
24:
25: // make sure to remove that system property again
26: System.getProperties().remove(Constants.OPT_CONTROLLER);
27: }
28:
29: /**
30: * Test if the factory returns the correct default implementation if no
31: * system property is set.
32: */
33: public void testGetInstance() {
34: ProcessController controller = ProcessControllerFactory
35: .createProcessController();
36: assertTrue(controller instanceof ProcessControllerImpl);
37: }
38:
39: /**
40: * Test whether the factory returns the default implementation if an invalid
41: * class name is provided.
42: */
43: public void testWrongClassName() {
44: // set an invalid class name
45: System
46: .setProperty(Constants.OPT_CONTROLLER,
47: "nonExistingClass");
48:
49: // check if the default implementation is created
50: ProcessController controller = ProcessControllerFactory
51: .createProcessController();
52: assertTrue(controller instanceof ProcessControllerImpl);
53: }
54:
55: /**
56: * Test whether the factory returns the right implementation based on a
57: * system property.
58: */
59: public void testGetInstanceBySystemProperty() {
60:
61: // set a different implementation
62: System.setProperty(Constants.OPT_CONTROLLER, IMPL);
63:
64: ProcessController controller = ProcessControllerFactory
65: .createProcessController();
66: assertTrue(controller instanceof ProcessControllerFactoryTest.MockProcessController);
67: }
68:
69: /**
70: * Mock class extending the <code>ProcessControllerImpl</code> for
71: * testing.
72: *
73: * @version $Revision: 1.2 $, $Date: 2004/11/30 15:05:26 $
74: * @author Patric Fornasier
75: */
76: public static class MockProcessController extends
77: ProcessControllerImpl {
78:
79: }
80: }
|