1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.tomgibara.pronto.util;
19
20 import java.util.HashMap;
21
22 import junit.framework.TestCase;
23
24 public class FactoryHelperTest extends TestCase {
25
26 public void testCreateClassOnly() throws Exception {
27 FactoryHelper<HashMap> factory = new FactoryHelper<HashMap>("java.util.HashMap", null, null);
28 HashMap map = factory.getInstance();
29 }
30
31 public void testCreatePropertyOnly() {
32 System.setProperty("factory.test", "java.util.HashMap");
33 new FactoryHelper(null, null, "factory.test");
34 }
35
36 public void testCreateBadClass() throws Exception {
37 FactoryHelper<HashMap> factory = new FactoryHelper<HashMap>("non.package.NonClass123", null, null);
38 try {
39 HashMap map = factory.getInstance();
40 } catch (Exception e) {
41
42 return;
43 }
44 fail("Did not fail to create non-existent class");
45 }
46
47 public void testCreateNonProperty() throws Exception {
48 FactoryHelper<HashMap> factory = new FactoryHelper<HashMap>(null, null, "non.package.NonProperty123");
49 try {
50 HashMap map = factory.getInstance();
51 } catch (Exception e) {
52
53 return;
54 }
55 fail("Did not fail to create non-existent class");
56 }
57
58 public void testCreateBadProperty() throws Exception {
59 System.setProperty("factory.test", "non.package.NonClass123");
60 FactoryHelper<HashMap> factory = new FactoryHelper<HashMap>(null, null, "factory.test");
61 try {
62 HashMap map = factory.getInstance();
63 } catch (Exception e) {
64
65 return;
66 }
67 fail("Did not fail to create non-existent class");
68 }
69
70 public void testNullCheck() {
71 try {
72 new FactoryHelper(null, null, null);
73 } catch (IllegalArgumentException e) {
74
75 return;
76 }
77 fail("Accepted null parameters");
78
79 }
80
81 }