1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j;
17
18 import static org.junit.Assert.*;
19
20 import org.junit.Test;
21
22 public class ServiceFinderTest
23 {
24 static final String DUMMY = "dummy";
25 static final String DUMMY_SERVICE = "org.ini4j.Dummy";
26 static final String BAD_CONFIG_SERVICE = "org.ini4j.BadConfig";
27 static final String EMPTY_CONFIG_SERVICE = "org.ini4j.EmptyConfig";
28 static final String DUMMY_IMPL = "DummyImpl";
29
30 @Test public void testFindService() throws Exception
31 {
32 boolean flag = false;
33
34 System.setProperty(IniParser.class.getName(), Helper.class.getName());
35 try
36 {
37 ServiceFinder.findService(IniParser.class);
38 }
39 catch (IllegalArgumentException x)
40 {
41 flag = true;
42 }
43
44
45 System.getProperties().remove(IniParser.class.getName());
46 assertTrue(flag);
47 }
48
49
50
51
52
53
54 @Test public void testFindServiceClass() throws Exception
55 {
56 boolean flag = false;
57
58 System.setProperty(IniParser.class.getName(), DUMMY);
59 try
60 {
61 ServiceFinder.findServiceClass(IniParser.class);
62 }
63 catch (IllegalArgumentException x)
64 {
65 flag = true;
66 }
67
68
69 System.getProperties().remove(IniParser.class.getName());
70 assertTrue(flag);
71 }
72
73
74
75
76
77
78 @Test public void testFindServiceClassName() throws Exception
79 {
80 boolean flag = false;
81
82 try
83 {
84 ServiceFinder.findServiceClassName(IniParser.class.getName(), null);
85 }
86 catch (IllegalArgumentException x)
87 {
88 flag = true;
89 }
90
91 assertTrue(flag);
92 System.setProperty(IniParser.class.getName(), DUMMY);
93 assertEquals(DUMMY, ServiceFinder.findServiceClassName(IniParser.class.getName(), IniParser.class.getName()));
94
95
96 System.getProperties().remove(IniParser.class.getName());
97 assertEquals(IniParser.class.getName(), ServiceFinder.findServiceClassName(IniParser.class.getName(), IniParser.class.getName()));
98 assertEquals(DUMMY_IMPL, ServiceFinder.findServiceClassName(DUMMY_SERVICE, ""));
99 assertEquals(DUMMY, ServiceFinder.findServiceClassName(BAD_CONFIG_SERVICE, DUMMY));
100 assertEquals(DUMMY, ServiceFinder.findServiceClassName(EMPTY_CONFIG_SERVICE, DUMMY));
101 }
102 }