|
32 | 32 | import static org.testng.AssertJUnit.assertNotNull; |
33 | 33 | import static tech.units.tck.TCKRunner.SPEC_ID; |
34 | 34 | import static tech.units.tck.TCKRunner.SPEC_VERSION; |
| 35 | + |
| 36 | +import java.util.Set; |
| 37 | + |
| 38 | +import static org.testng.Assert.assertEquals; |
35 | 39 | import static org.testng.AssertJUnit.assertFalse; |
36 | 40 |
|
| 41 | +import javax.measure.BinaryPrefix; |
| 42 | +import javax.measure.MetricPrefix; |
| 43 | +import javax.measure.Prefix; |
| 44 | +import javax.measure.spi.FormatService; |
37 | 45 | import javax.measure.spi.ServiceProvider; |
38 | 46 | import javax.measure.spi.SystemOfUnitsService; |
39 | 47 | import javax.measure.spi.UnitFormatService; |
|
44 | 52 |
|
45 | 53 | /** |
46 | 54 | * Test class for Services. |
| 55 | + * |
47 | 56 | * @author Werner Keil |
48 | 57 | * @version 1.0, August 16, 2016 |
49 | 58 | * @since 1.0 |
50 | 59 | */ |
51 | 60 | @SpecVersion(spec = SPEC_ID, version = SPEC_VERSION) |
52 | 61 | public class ServicesTest { |
53 | | - private static final String SECTION = "5.4"; |
54 | | - private static final String DESCRIPTION = SECTION + " Services"; |
| 62 | + private static final String SECTION = "5.4"; |
| 63 | + private static final String DESCRIPTION = SECTION + " Services"; |
| 64 | + |
| 65 | + // ************************ 5.4 Services |
| 66 | + // ************************ |
| 67 | + /** |
| 68 | + * Access available UnitFormatServices. |
| 69 | + */ |
| 70 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 71 | + @SpecAssertion(section = SECTION, id = "54-A1") |
| 72 | + public void testFormatService() { |
| 73 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 74 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 75 | + UnitFormatService service = provider.getFormatService(); |
| 76 | + assertNotNull("Section " + SECTION + ": FormatService is null", service); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + // ************************ 5.4 Services |
| 81 | + // ************************ |
| 82 | + /** |
| 83 | + * Access default UnitFormats in UnitFormatServices. |
| 84 | + */ |
| 85 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 86 | + @SpecAssertion(section = SECTION, id = "54-A2") |
| 87 | + public void testFormatServiceDefaultFormat() { |
| 88 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 89 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 90 | + FormatService service = provider.getFormatService(); |
| 91 | + assertNotNull("Section " + SECTION + ": UnitFormatService is null", service); |
| 92 | + assertNotNull("Section " + SECTION + ": Default UnitFormat is null", service.getUnitFormat()); |
| 93 | + assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", |
| 94 | + service.getAvailableFormatNames()); |
| 95 | + assertFalse("Section " + SECTION + " No available UnitFormat names found", |
| 96 | + service.getAvailableFormatNames().isEmpty()); |
| 97 | + } |
| 98 | + } |
55 | 99 |
|
56 | | - // ************************ 5.4 Services |
57 | | - // ************************ |
58 | | - /** |
59 | | - * Access available UnitFormatServices. |
60 | | - */ |
61 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
62 | | - @SpecAssertion(section = SECTION, id = "54-A1") |
63 | | - public void testFormatService() { |
64 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
65 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
66 | | - UnitFormatService service = provider.getUnitFormatService(); |
67 | | - assertNotNull("Section " + SECTION + ": UnitFormatService is null", service); |
| 100 | + // ************************ 5.4 Services |
| 101 | + // ************************ |
| 102 | + /** |
| 103 | + * Access available UnitFormats in UnitFormatServices. |
| 104 | + */ |
| 105 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 106 | + @SpecAssertion(section = SECTION, id = "54-A3") |
| 107 | + public void testFormatServiceAvailableFormats() { |
| 108 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 109 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 110 | + FormatService service = provider.getFormatService(); |
| 111 | + assertNotNull("Section " + SECTION + ": FormatService is null", service); |
| 112 | + assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", |
| 113 | + service.getAvailableFormatNames()); |
| 114 | + assertFalse("Section " + SECTION + " No available UnitFormat names found", |
| 115 | + service.getAvailableFormatNames().isEmpty()); |
| 116 | + } |
68 | 117 | } |
69 | | - } |
70 | | - |
71 | | - // ************************ 5.4 Services |
72 | | - // ************************ |
73 | | - /** |
74 | | - * Access default UnitFormats in UnitFormatServices. |
75 | | - */ |
76 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
77 | | - @SpecAssertion(section = SECTION, id = "54-A2") |
78 | | - public void testFormatServiceDefaultFormat() { |
79 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
80 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
81 | | - UnitFormatService service = provider.getUnitFormatService(); |
82 | | - assertNotNull("Section " + SECTION + ": UnitFormatService is null", service); |
83 | | - assertNotNull("Section " + SECTION + ": Default UnitFormat is null", service.getUnitFormat()); |
84 | | - assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", service.getAvailableFormatNames()); |
85 | | - assertFalse("Section " + SECTION + " No available UnitFormat names found", service.getAvailableFormatNames().isEmpty()); |
| 118 | + |
| 119 | + // ************************ 5.4 Services |
| 120 | + // ************************ |
| 121 | + /** |
| 122 | + * Access available SystemOfUnitsServices. |
| 123 | + */ |
| 124 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 125 | + @SpecAssertion(section = SECTION, id = "54-A4") |
| 126 | + public void testSystemOfUnitsService() { |
| 127 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 128 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 129 | + SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
| 130 | + assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 131 | + } |
86 | 132 | } |
87 | | - } |
88 | | - |
89 | | - // ************************ 5.4 Services |
90 | | - // ************************ |
91 | | - /** |
92 | | - * Access available UnitFormats in UnitFormatServices. |
93 | | - */ |
94 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
95 | | - @SpecAssertion(section = SECTION, id = "54-A3") |
96 | | - public void testFormatServiceAvailableFormats() { |
97 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
98 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
99 | | - UnitFormatService service = provider.getUnitFormatService(); |
100 | | - assertNotNull("Section " + SECTION + ": UnitFormatService is null", service); |
101 | | - assertNotNull("Section " + SECTION + ": Available UnitFormat names are null", service.getAvailableFormatNames()); |
102 | | - assertFalse("Section " + SECTION + " No available UnitFormat names found", service.getAvailableFormatNames().isEmpty()); |
| 133 | + |
| 134 | + // ************************ 5.4 Services |
| 135 | + // ************************ |
| 136 | + /** |
| 137 | + * Access default SystemOfUnits in SystemOfUnitsService. |
| 138 | + */ |
| 139 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 140 | + @SpecAssertion(section = SECTION, id = "54-A5") |
| 141 | + public void testSystemOfUnitsServiceDefaultSystem() { |
| 142 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 143 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 144 | + SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
| 145 | + assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 146 | + assertNotNull("Section " + SECTION + ": Default SystemOfUnits is null", service.getSystemOfUnits()); |
| 147 | + } |
103 | 148 | } |
104 | | - } |
105 | | - |
106 | | - // ************************ 5.4 Services |
107 | | - // ************************ |
108 | | - /** |
109 | | - * Access available SystemOfUnitsServices. |
110 | | - */ |
111 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
112 | | - @SpecAssertion(section = SECTION, id = "54-A4") |
113 | | - public void testSystemOfUnitsService() { |
114 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
115 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
116 | | - SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
117 | | - assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 149 | + |
| 150 | + // ************************ 5.4 Services |
| 151 | + // ************************ |
| 152 | + /** |
| 153 | + * Access available Systems OfUnits in SystemOfUnitsService. |
| 154 | + */ |
| 155 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 156 | + @SpecAssertion(section = SECTION, id = "54-A6") |
| 157 | + public void testSystemOfUnitsServiceAvailableSystems() { |
| 158 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 159 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 160 | + SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
| 161 | + assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 162 | + assertNotNull("Section " + SECTION + ": Available SystemOfUnits are null", |
| 163 | + service.getAvailableSystemsOfUnits()); |
| 164 | + assertFalse("Section " + SECTION + " No available SystemOfUnits found", |
| 165 | + service.getAvailableSystemsOfUnits().isEmpty()); |
| 166 | + } |
118 | 167 | } |
119 | | - } |
120 | | - |
121 | | - // ************************ 5.4 Services |
122 | | - // ************************ |
123 | | - /** |
124 | | - * Access default SystemOfUnits in SystemOfUnitsService. |
125 | | - */ |
126 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
127 | | - @SpecAssertion(section = SECTION, id = "54-A5") |
128 | | - public void testSystemOfUnitsServiceDefaultSystem() { |
129 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
130 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
131 | | - SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
132 | | - assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
133 | | - assertNotNull("Section " + SECTION + ": Default SystemOfUnits is null", service.getSystemOfUnits()); |
| 168 | + |
| 169 | + /** |
| 170 | + * Access Binary Prefixes in SystemOfUnitsService. |
| 171 | + */ |
| 172 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 173 | + @SpecAssertion(section = SECTION, id = "54-A7") |
| 174 | + public void testSystemOfUnitsServicePrefixBinary() { |
| 175 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 176 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 177 | + final SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
| 178 | + assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 179 | + Set<Prefix> prefixes = service.getPrefixes(BinaryPrefix.class); |
| 180 | + assertNotNull("Section " + SECTION + ": Binary Prefixes are null", prefixes); |
| 181 | + assertFalse("Section " + SECTION + " No Binary Prefixes found", prefixes.isEmpty()); |
| 182 | + assertEquals(8, prefixes.size(), "Section " + SECTION + " Wrong Number of Binary Prefixes"); |
| 183 | + } |
134 | 184 | } |
135 | | - } |
136 | | - |
137 | | - // ************************ 5.4 Services |
138 | | - // ************************ |
139 | | - /** |
140 | | - * Access available Systems OfUnits in SystemOfUnitsService. |
141 | | - */ |
142 | | - @Test(groups = {"spi"}, description = DESCRIPTION) |
143 | | - @SpecAssertion(section = SECTION, id = "54-A6") |
144 | | - public void testSystemOfUnitsServiceAvailableSystems() { |
145 | | - for (ServiceProvider provider : ServiceProvider.available()) { |
146 | | - assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
147 | | - SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
148 | | - assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
149 | | - assertNotNull("Section " + SECTION + ": Available SystemOfUnits are null", service.getAvailableSystemsOfUnits()); |
150 | | - assertFalse("Section " + SECTION + " No available SystemOfUnits found", service.getAvailableSystemsOfUnits().isEmpty()); |
| 185 | + |
| 186 | + /** |
| 187 | + * Access Metric Prefixes in SystemOfUnitsService. |
| 188 | + */ |
| 189 | + @Test(groups = { "spi" }, description = DESCRIPTION) |
| 190 | + @SpecAssertion(section = SECTION, id = "54-A8") |
| 191 | + public void testSystemOfUnitsServicePrefixMetric() { |
| 192 | + for (ServiceProvider provider : ServiceProvider.available()) { |
| 193 | + assertNotNull("Section " + SECTION + ": ServiceProvider is null", provider); |
| 194 | + final SystemOfUnitsService service = provider.getSystemOfUnitsService(); |
| 195 | + assertNotNull("Section " + SECTION + ": SystemOfUnitsService is null", service); |
| 196 | + Set<Prefix> prefixes = service.getPrefixes(MetricPrefix.class); |
| 197 | + assertNotNull("Section " + SECTION + ": Metric Prefixes are null", prefixes); |
| 198 | + assertFalse("Section " + SECTION + " No Metric Prefixes found", prefixes.isEmpty()); |
| 199 | + assertEquals(20, prefixes.size(), "Section " + SECTION + " Wrong Number of Metric Prefixes"); |
| 200 | + } |
151 | 201 | } |
152 | | - } |
153 | 202 | } |
0 commit comments