1 /*
2 * Copyright 2011 FatWire Corporation. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 }