1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.dbutils;
18
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.ServiceLoader;
22
23 import org.apache.commons.dbutils.handlers.columns.TestColumnHandler;
24 import org.apache.commons.dbutils.handlers.properties.TestPropertyHandler;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 public class ServiceLoaderTest {
29 private ServiceLoader<ColumnHandler> columns;
30 private ServiceLoader<PropertyHandler> properties;
31
32 @Before
33 public void setUp() {
34 columns = ServiceLoader.load(ColumnHandler.class);
35 properties = ServiceLoader.load(PropertyHandler.class);
36 }
37
38
39
40
41
42 @Test
43 public void testFindMoreThanLocalColumns() {
44 int count = 0;
45 for (final ColumnHandler<?> handler : columns) {
46 count++;
47 }
48
49 assertTrue(count > 1);
50 }
51
52
53
54
55
56 @Test
57 public void testFindMoreThanLocalProperties() {
58 int count = 0;
59 for (final PropertyHandler handler : properties) {
60 count++;
61 }
62
63 assertTrue(count > 1);
64 }
65
66 @Test
67 public void testFindsLocalColumnHandler() {
68 boolean found = false;
69 for (final ColumnHandler<?> handler : columns) {
70
71 if (handler instanceof TestColumnHandler) {
72 found = true;
73 }
74 }
75
76 assertTrue(found);
77 }
78
79 @Test
80 public void testFindsLocalPropertyHandler() {
81 boolean found = false;
82 for (final PropertyHandler handler : properties) {
83
84 if (handler instanceof TestPropertyHandler) {
85 found = true;
86 }
87 }
88
89 assertTrue(found);
90 }
91
92 }