1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.controller.support;
17
18 import junit.framework.TestCase;
19
20
21
22
23 public class TemplateMethodFactoryTest extends TestCase {
24
25 static public class Bar {
26
27 @Override
28 public String toString() {
29 return "Bar";
30 }
31
32 }
33
34 class Foo {
35 public String createString() {
36 return "foo";
37 }
38 }
39
40 public void testCreateByMethod() {
41 try {
42 String foo = TemplateMethodFactory.createByMethod(new Foo(), String.class);
43 assertEquals("foo", foo);
44 } catch (Exception e) {
45 fail(e.getMessage());
46 }
47
48 }
49
50 public void testCreateByConstructor() {
51 Bar foo;
52 try {
53 foo = TemplateMethodFactory.createByConstructor(Bar.class);
54 assertEquals("Bar", foo.toString());
55 } catch (Exception e) {
56 e.printStackTrace();
57 fail(e.getMessage());
58 }
59
60 }
61
62 }