001/* 002 * Units of Measurement TCK 003 * Copyright © 2005-2019, Jean-Marie Dautelle, Werner Keil, Otavio Santana. 004 * 005 * All rights reserved. 006 * 007 * Redistribution and use in source and binary forms, with or without modification, 008 * are permitted provided that the following conditions are met: 009 * 010 * 1. Redistributions of source code must retain the above copyright notice, 011 * this list of conditions and the following disclaimer. 012 * 013 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions 014 * and the following disclaimer in the documentation and/or other materials provided with the distribution. 015 * 016 * 3. Neither the name of JSR-385 nor the names of its contributors may be used to endorse or promote products 017 * derived from this software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 021 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 026 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 028 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package tech.units.tck.tests.unit; 031 032import static tech.units.tck.TCKRunner.SPEC_ID; 033import static tech.units.tck.TCKRunner.SPEC_VERSION; 034import static tech.units.tck.util.TestGroups.CORE; 035import static tech.units.tck.util.TestUtils.testHasPublicMethod; 036 037import javax.measure.Prefix; 038import javax.measure.Unit; 039import org.jboss.test.audit.annotations.SpecAssertion; 040import org.jboss.test.audit.annotations.SpecVersion; 041import org.testng.annotations.Test; 042 043import tech.units.tck.TCKSetup; 044 045/** 046 * Testing the Unit Interface 047 * 048 * @author <a href="mailto:[email protected]">Werner Keil</a> 049 * @author Almas Shaikh 050 * @version 1.2, April 21, 2019 051 * @since 1.0 052 */ 053@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION) 054public class UnitInterfaceTest { 055 056 /** 057 * Test that Unit implementations override equals. 058 */ 059 @SpecAssertion(section = "4.2.1", id = "421-A1") 060 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes override equals.") 061 public void testEquals() { 062 for (@SuppressWarnings("rawtypes") 063 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 064 testHasPublicMethod("Section 4.2.1", type, "equals", true); 065 } 066 } 067 068 /** 069 * Test that Unit implementations contain getters 070 */ 071 @SpecAssertion(section = "4.2.1", id = "421-A2") 072 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes implement getDimension.") 073 public void testGetDimension() { 074 for (@SuppressWarnings("rawtypes") 075 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 076 testHasPublicMethod("Section 4.2.1", type, "getDimension"); 077 } 078 } 079 080 /** 081 * Test that Unit implementations contain getSystemUnit 082 */ 083 @SpecAssertion(section = "4.2.1", id = "421-A3") 084 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes implement getSystemUnit.") 085 public void testGetSystemUnit() { 086 for (@SuppressWarnings("rawtypes") 087 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 088 testHasPublicMethod("Section 4.2.1", type, "getSystemUnit"); 089 } 090 } 091 092 /** 093 * Test that Unit implementations contain getBaseUnits 094 */ 095 @SpecAssertion(section = "4.2.1", id = "421-A4") 096 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes implement getBaseUnits.") 097 public void testGetBaseUnits() { 098 for (@SuppressWarnings("rawtypes") 099 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 100 testHasPublicMethod("Section 4.2.1", type, "getBaseUnits"); 101 } 102 } 103 104 /** 105 * Test that Unit implementations contain getters 106 */ 107 @SuppressWarnings({"rawtypes"}) 108 @SpecAssertion(section = "4.2.1", id = "421-A5") 109 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes implement getName.") 110 public void testGetName() { 111 for (Class type : TCKSetup.getConfiguration().getUnitClasses()) { 112 testHasPublicMethod("Section 4.2.1", type, "getName"); 113 } 114 } 115 116 /** 117 * Test that Unit implementations contain getters 118 */ 119 @SuppressWarnings({"rawtypes"}) 120 @SpecAssertion(section = "4.2.1", id = "421-A6") 121 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes implement getSymbol.") 122 public void testGetSymbol() { 123 for (Class type : TCKSetup.getConfiguration().getUnitClasses()) { 124 testHasPublicMethod("Section 4.2.1", type, "getSymbol"); 125 } 126 } 127 128 /** 129 * Test that Unit implementations override hashCode. 130 */ 131 @SpecAssertion(section = "4.2.1", id = "421-A7") 132 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes override hashCode.") 133 public void testHashcode() { 134 for (@SuppressWarnings("rawtypes") 135 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 136 testHasPublicMethod("Section 4.2.1", type, "hashCode"); 137 } 138 } 139 140 /** 141 * Test that Unit implementations override toString. 142 */ 143 @SpecAssertion(section = "4.2.1", id = "421-A8") 144 @Test(groups = { CORE }, description = "4.2.1 Ensure registered Unit classes override toString.") 145 public void testToString() { 146 for (@SuppressWarnings("rawtypes") 147 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 148 testHasPublicMethod("Section 4.2.1", type, "toString"); 149 } 150 } 151 152 /** 153 * Ensure the alternate() operation is implemented. 154 */ 155 @SpecAssertion(section = "4.2.1.2", id = "42121-A1") 156 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the alternate() operation is implemented.") 157 public void testUnit42121A1_Alternate() { 158 for (@SuppressWarnings("rawtypes") 159 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 160 testHasPublicMethod("Section 4.2.1.2.1", type, "alternate", true); 161 } 162 } 163 164 /** 165 * Ensure the divide(Unit) operation is implemented. 166 */ 167 @SpecAssertion(section = "4.2.1.2", id = "42121-A2") 168 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(Unit) operation is implemented.") 169 public void testUnit42121A2_Divide() { 170 for (@SuppressWarnings("rawtypes") 171 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 172 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "divide", Unit.class); 173 } 174 } 175 176 /** 177 * Ensure the divide(double) operation is implemented. 178 */ 179 @SpecAssertion(section = "4.2.1.2", id = "42121-A3") 180 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(double) operation is implemented.") 181 public void testUnit42121A3_DivideByDouble() { 182 for (@SuppressWarnings("rawtypes") 183 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 184 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "divide", double.class); 185 } 186 } 187 188 /** 189 * Ensure the divide(Number) operation is implemented. 190 */ 191 @SpecAssertion(section = "4.2.1.2", id = "42121-A4") 192 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(Number) operation is implemented.") 193 public void testUnit42121A4_DivideByNumber() { 194 for (@SuppressWarnings("rawtypes") 195 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 196 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "divide", Number.class); 197 } 198 } 199 200 /** 201 * Ensure the multiply() operation is implemented. 202 */ 203 @SpecAssertion(section = "4.2.1.2", id = "42121-A5") 204 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply() operation is implemented.") 205 public void testUnit42121A5_Multiply() { 206 for (@SuppressWarnings("rawtypes") 207 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 208 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "multiply", Unit.class); 209 } 210 } 211 212 /** 213 * Ensure the multiply(double) operation is implemented. 214 */ 215 @SpecAssertion(section = "4.2.1.2", id = "42121-A6") 216 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply(double) operation is implemented.") 217 public void testUnit42121A6_MultiplyByDouble() { 218 for (@SuppressWarnings("rawtypes") 219 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 220 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "multiply", double.class); 221 } 222 } 223 224 /** 225 * Ensure the multiply(Number) operation is implemented. 226 */ 227 @SpecAssertion(section = "4.2.1.2", id = "42121-A7") 228 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply(Number) operation is implemented.") 229 public void testUnit42121A7_MultiplyByNumber() { 230 for (@SuppressWarnings("rawtypes") 231 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 232 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "multiply", Number.class); 233 } 234 } 235 236 /** 237 * Ensure the prefix() operation is implemented. 238 * @since 2.0 239 */ 240 @SpecAssertion(section = "4.2.1.2", id = "42121-A8") 241 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the prefix() operation is implemented.") 242 public void testUnit42121A8_Prefix() { 243 for (@SuppressWarnings("rawtypes") 244 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 245 //testHasPublicMethod("Section 4.2.1.2.1", type, "prefix", true); 246 testHasPublicMethod("Section 4.2.1.2.1", type, false, Unit.class, "prefix", Prefix.class); 247 } 248 } 249 250 /** 251 * Ensure the shift() operation is implemented. 252 */ 253 @SpecAssertion(section = "4.2.1.2", id = "42121-A9") 254 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the shift(double) operation is implemented.") 255 public void testUnit42121A9_ShiftByDouble() { 256 for (@SuppressWarnings("rawtypes") 257 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 258 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "shift", double.class); 259 } 260 } 261 262 /** 263 * Ensure the shift(Number) operation is implemented. 264 */ 265 @SpecAssertion(section = "4.2.1.2", id = "42121-A10") 266 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the shift(Number) operation is implemented.") 267 public void testUnit42121A10_ShiftByNumber() { 268 for (@SuppressWarnings("rawtypes") 269 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 270 testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "shift", Number.class); 271 } 272 } 273 274 /** 275 * Ensure the pow() operation is implemented. 276 */ 277 @SpecAssertion(section = "4.2.1.2", id = "42122-A1") 278 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the pow() operation is implemented.") 279 public void testUnit42122Pow() { 280 for (@SuppressWarnings("rawtypes") 281 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 282 testHasPublicMethod("Section 4.2.1.2.2", type, "pow", true); 283 } 284 } 285 286 /** 287 * Ensure the root() operation is implemented. 288 */ 289 @SpecAssertion(section = "4.2.1.2", id = "42122-A2") 290 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the root() operation is implemented.") 291 public void testUnit42122Root() { 292 for (@SuppressWarnings("rawtypes") 293 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 294 testHasPublicMethod("Section 4.2.1.2.2", type, "root", true); 295 } 296 } 297 298 /** 299 * Ensure the transform() operation is implemented. 300 */ 301 @SpecAssertion(section = "4.2.1.2", id = "42122-A3") 302 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the transform() operation is implemented.") 303 public void testUnit42122Transform() { 304 for (@SuppressWarnings("rawtypes") 305 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 306 testHasPublicMethod("Section 4.2.1.2.2", type, "transform", true); 307 } 308 } 309 310 /** 311 * Ensure the inverse() operation is implemented. 312 */ 313 @SpecAssertion(section = "4.2.1.2", id = "42123-A1") 314 @Test(groups = { CORE }, description = "4.2.1.2.3 Ensure the inverse() operation is implemented.") 315 public void testUnit42123Inverse() { 316 for (@SuppressWarnings("rawtypes") 317 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 318 testHasPublicMethod("Section 4.2.1.2.3", type, "inverse", false); 319 } 320 } 321 322 /** 323 * Ensure the isCompatible() operation is implemented. 324 */ 325 @SpecAssertion(section = "4.2.2", id = "422-A1") 326 @Test(groups = { CORE }, description = "4.2.2 Ensure the isCompatible() operation is implemented.") 327 public void testUnit422IsCompatible() { 328 for (@SuppressWarnings("rawtypes") 329 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 330 testHasPublicMethod("Section 4.2.3", type, "isCompatible", true); 331 } 332 } 333 334 /** 335 * Ensure the asType() operation is implemented. 336 */ 337 @SpecAssertion(section = "4.2.2", id = "422-A2") 338 @Test(groups = { CORE }, description = "4.2.2 Ensure the asType() operation is implemented.") 339 public void testUnit423AsType() { 340 for (@SuppressWarnings("rawtypes") 341 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 342 testHasPublicMethod("Section 4.2.2", type, "asType", true); 343 } 344 } 345 346 /** 347 * Ensure the getConverterTo() operation is implemented. 348 */ 349 @SpecAssertion(section = "4.2.3", id = "423-A1") 350 @Test(groups = { CORE }, description = "4.2.3 Ensure the getConverterTo() operation is implemented.") 351 public void testUnit423GetConverterTo() { 352 for (@SuppressWarnings("rawtypes") 353 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 354 testHasPublicMethod("Section 4.2.3", type, "getConverterTo", true); 355 } 356 } 357 358 /** 359 * Ensure the getConverterToAny() operation is implemented. 360 */ 361 @SpecAssertion(section = "4.2.3", id = "423-A2") 362 @Test(groups = { CORE }, description = "4.2.3 Ensure the getConverterToAny() operation is implemented.") 363 public void testUnit423GetConverterToAny() { 364 for (@SuppressWarnings("rawtypes") 365 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 366 testHasPublicMethod("Section 4.2.3", type, "getConverterToAny", true); 367 } 368 } 369}