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