Skip to content

Commit

Permalink
MONDRIAN
Browse files Browse the repository at this point in the history
   Better example of a test case in documentation.

[git-p4: depot-paths = "//open/mondrian/": change = 8669]
  • Loading branch information
Richard Emberson committed Feb 5, 2007
1 parent e5eeefe commit 48f7713
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/main/mondrian/util/ObjectFactory.java
Expand Up @@ -178,26 +178,42 @@
* boolean getValue();
* .......
* }
* class MyCode {
* private Boo boo;
* MyCode() {
* boo = BooFactory.instance().getObject();
* }
* .......
* int getValue() {
* if (boo.getValue()) {
* return 1;
* } else {
* return 0;
* }
*
* }
* }
*
* class MyTest {
* class MyCodeTest {
* private static boolean testValue;
* static class BooTest implements Boo {
* public boolean getValue() {
* return MyTest.testValue;
* }
* }
* public void test() {
* BooFactory bf = BooFactory.instance();
* try {
* BooFactory.setThreadLocalClassName("MyTest.BooTest");
*
*
* MyTest.testValue = true;
* Boo boo1 = bf.getObject();
* assertTrue("Value not true", boo1.getValue());
* MyCode myCode = new MyCode();
* int value = myCode.getValue();
* assertTrue("Value not 1", (value == 1));
*
* MyTest.testValue = false;
* Boo boo2 = bf.getObject();
* assertTrue("Value is true", ! boo2.getValue());
* myCode = new MyCode();
* value = myCode.getValue();
* assertTrue("Value not 0", (value == 0));
* } finally {
* BooFactory.clearThreadLocalClassName();
* }
Expand All @@ -207,7 +223,10 @@
* </pre>
* <p>
* While this is a very simple example, it shows how using such factories
* can aid in creating testable code.
* can aid in creating testable code. The MyCode method is a client of
* the Boo implementation. How to test the two different code branches the
* method can take? Because the Boo object is generated by a factory,
* one can override what object the factory returns.
*
* @author <a>Richard M. Emberson</a>
* @since Feb 01 2007
Expand Down

0 comments on commit 48f7713

Please sign in to comment.