1   /*
2    * $Id: ProcessControllerFactoryTest.java,v 1.1 2004/12/15 14:18:12 patforna Exp $
3    *
4    * Copyright (c) 2004 Patric Fornasier, Pawel Kowalski
5    * Berne University of Applied Sciences
6    * School of Engineering and Information Technology
7    * All rights reserved.
8    */
9   package bexee.core;
10  
11  import junit.framework.TestCase;
12  import bexee.util.Constants;
13  
14  /***
15   * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:12 $
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      {
45          // set an invalid class name
46          System.setProperty(Constants.OPT_CONTROLLER, "nonExistingClass");
47          
48          // check if the default implementation is created
49          ProcessController controller = ProcessControllerFactory.createProcessController();
50          assertTrue(controller instanceof ProcessControllerImpl);
51      }
52  
53      /***
54       * Test whether the factory returns the right implementation based on a
55       * system property.
56       */
57      public void testGetInstanceBySystemProperty() {
58  
59          // set a different implementation
60          System.setProperty(Constants.OPT_CONTROLLER, IMPL);
61  
62          ProcessController controller = ProcessControllerFactory
63                  .createProcessController();
64          assertTrue(controller instanceof ProcessControllerFactoryTest.MockProcessController);
65      }
66  
67      /***
68       * Mock class extending the <code>ProcessControllerImpl</code> for
69       * testing.
70       * 
71       * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:12 $
72       * @author Patric Fornasier
73       */
74      public static class MockProcessController extends ProcessControllerImpl {
75  
76      }
77  }