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 public class TemplateMethodFactoryTest extends TestCase {
21
22 static public class Bar {
23
24 @Override
25 public String toString() {
26 return "Bar";
27 }
28
29 }
30
31 class Foo {
32 public String createString() {
33 return "foo";
34 }
35 }
36
37 public void testCreateByMethod() {
38 try {
39 String foo = TemplateMethodFactory.createByMethod(new Foo(), String.class);
40 assertEquals("foo", foo);
41 } catch (Exception e) {
42 fail(e.getMessage());
43 }
44
45 }
46
47 public void testCreateByConstructor() {
48 Bar foo;
49 try {
50 foo = TemplateMethodFactory.createByConstructor(Bar.class);
51 assertEquals("Bar", foo.toString());
52 } catch (Exception e) {
53 e.printStackTrace();
54 fail(e.getMessage());
55 }
56
57 }
58
59 }