001/* 002 * Units of Measurement TCK 003 * Copyright © 2005-2020, 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.TCKRunner.SECTION_PREFIX; 035import static tech.units.tck.util.TestGroups.CORE; 036import static tech.units.tck.util.TestUtils.testHasPublicMethod; 037 038import javax.measure.Prefix; 039import javax.measure.Unit; 040import org.jboss.test.audit.annotations.SpecAssertion; 041import org.jboss.test.audit.annotations.SpecVersion; 042import org.testng.annotations.Test; 043 044import tech.units.tck.TCKSetup; 045 046/** 047 * Testing the Unit Interface 048 * 049 * @author <a href="mailto:[email protected]">Werner Keil</a> 050 * @author Almas Shaikh 051 * @version 2.1.1, December 2, 2020 052 * @since 1.0 053 */ 054@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION) 055public class UnitInterfaceTest { 056 /** Section constants */ 057 private static final String SECTION_NUM1 = "4.2.1"; 058 private static final String SECTION_NUM2 = "4.2.1.2"; 059 060 /** 061 * Test that Unit implementations override equals. 062 */ 063 @SpecAssertion(section = SECTION_NUM1, id = "421-A1") 064 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes override equals.") 065 public void testEquals() { 066 for (@SuppressWarnings("rawtypes") 067 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 068 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "equals", true); 069 } 070 } 071 072 /** 073 * Test that Unit implementations contain getters 074 */ 075 @SpecAssertion(section = SECTION_NUM1, id = "421-A2") 076 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement getDimension.") 077 public void testGetDimension() { 078 for (@SuppressWarnings("rawtypes") 079 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 080 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "getDimension"); 081 } 082 } 083 084 /** 085 * Test that Unit implementations contain getSystemUnit 086 */ 087 @SpecAssertion(section = SECTION_NUM1, id = "421-A3") 088 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement getSystemUnit.") 089 public void testGetSystemUnit() { 090 for (@SuppressWarnings("rawtypes") 091 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 092 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "getSystemUnit"); 093 } 094 } 095 096 /** 097 * Test that Unit implementations contain getBaseUnits 098 */ 099 @SpecAssertion(section = SECTION_NUM1, id = "421-A4") 100 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement getBaseUnits.") 101 public void testGetBaseUnits() { 102 for (@SuppressWarnings("rawtypes") 103 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 104 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "getBaseUnits"); 105 } 106 } 107 108 /** 109 * Test that Unit implementations contain getters 110 */ 111 @SuppressWarnings({"rawtypes"}) 112 @SpecAssertion(section = SECTION_NUM1, id = "421-A5") 113 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement getName.") 114 public void testGetName() { 115 for (Class type : TCKSetup.getConfiguration().getUnitClasses()) { 116 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "getName"); 117 } 118 } 119 120 /** 121 * Test that Unit implementations contain getters 122 */ 123 @SuppressWarnings({"rawtypes"}) 124 @SpecAssertion(section = SECTION_NUM1, id = "421-A6") 125 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement getSymbol.") 126 public void testGetSymbol() { 127 for (Class type : TCKSetup.getConfiguration().getUnitClasses()) { 128 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "getSymbol"); 129 } 130 } 131 132 /** 133 * Test that Unit implementations override hashCode. 134 */ 135 @SpecAssertion(section = SECTION_NUM1, id = "421-A7") 136 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes override hashCode.") 137 public void testHashcode() { 138 for (@SuppressWarnings("rawtypes") 139 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 140 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "hashCode"); 141 } 142 } 143 144 /** 145 * Test that Unit implementations implement isEquivalentTo. 146 */ 147 @SpecAssertion(section = SECTION_NUM1, id = "421-A8") 148 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes implement isEquivalentTo.") 149 public void testIsEquivalentTo() { 150 for (@SuppressWarnings("rawtypes") 151 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 152 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "isEquivalentTo", true); 153 } 154 } 155 156 /** 157 * Test that Unit implementations override toString. 158 */ 159 @SpecAssertion(section = SECTION_NUM1, id = "421-A9") 160 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure registered Unit classes override toString.") 161 public void testToString() { 162 for (@SuppressWarnings("rawtypes") 163 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 164 testHasPublicMethod(SECTION_PREFIX + SECTION_NUM1, type, "toString"); 165 } 166 } 167 168 /** 169 * Ensure the alternate() operation is implemented. 170 */ 171 @SpecAssertion(section = SECTION_NUM2, id = "42121-A1") 172 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the alternate() operation is implemented.") 173 public void testUnit42121A1_Alternate() { 174 for (@SuppressWarnings("rawtypes") 175 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 176 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, "alternate", true); 177 } 178 } 179 180 /** 181 * Ensure the divide(Unit) operation is implemented. 182 */ 183 @SpecAssertion(section = SECTION_NUM2, id = "42121-A2") 184 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(Unit) operation is implemented.") 185 public void testUnit42121A2_Divide() { 186 for (@SuppressWarnings("rawtypes") 187 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 188 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "divide", Unit.class); 189 } 190 } 191 192 /** 193 * Ensure the divide(double) operation is implemented. 194 */ 195 @SpecAssertion(section = SECTION_NUM2, id = "42121-A3") 196 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(double) operation is implemented.") 197 public void testUnit42121A3_DivideByDouble() { 198 for (@SuppressWarnings("rawtypes") 199 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 200 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "divide", double.class); 201 } 202 } 203 204 /** 205 * Ensure the divide(Number) operation is implemented. 206 */ 207 @SpecAssertion(section = SECTION_NUM2, id = "42121-A4") 208 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the divide(Number) operation is implemented.") 209 public void testUnit42121A4_DivideByNumber() { 210 for (@SuppressWarnings("rawtypes") 211 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 212 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "divide", Number.class); 213 } 214 } 215 216 /** 217 * Ensure the multiply() operation is implemented. 218 */ 219 @SpecAssertion(section = SECTION_NUM2, id = "42121-A5") 220 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply() operation is implemented.") 221 public void testUnit42121A5_Multiply() { 222 for (@SuppressWarnings("rawtypes") 223 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 224 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "multiply", Unit.class); 225 } 226 } 227 228 /** 229 * Ensure the multiply(double) operation is implemented. 230 */ 231 @SpecAssertion(section = SECTION_NUM2, id = "42121-A6") 232 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply(double) operation is implemented.") 233 public void testUnit42121A6_MultiplyByDouble() { 234 for (@SuppressWarnings("rawtypes") 235 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 236 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "multiply", double.class); 237 } 238 } 239 240 /** 241 * Ensure the multiply(Number) operation is implemented. 242 */ 243 @SpecAssertion(section = SECTION_NUM2, id = "42121-A7") 244 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the multiply(Number) operation is implemented.") 245 public void testUnit42121A7_MultiplyByNumber() { 246 for (@SuppressWarnings("rawtypes") 247 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 248 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "multiply", Number.class); 249 } 250 } 251 252 /** 253 * Ensure the prefix() operation is implemented. 254 * @since 2.0 255 */ 256 @SpecAssertion(section = SECTION_NUM2, id = "42121-A8") 257 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the prefix() operation is implemented.") 258 public void testUnit42121A8_Prefix() { 259 for (@SuppressWarnings("rawtypes") 260 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 261 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, false, Unit.class, "prefix", Prefix.class); 262 } 263 } 264 265 /** 266 * Ensure the shift() operation is implemented. 267 */ 268 @SpecAssertion(section = SECTION_NUM2, id = "42121-A9") 269 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the shift(double) operation is implemented.") 270 public void testUnit42121A9_ShiftByDouble() { 271 for (@SuppressWarnings("rawtypes") 272 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 273 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "shift", double.class); 274 } 275 } 276 277 /** 278 * Ensure the shift(Number) operation is implemented. 279 */ 280 @SpecAssertion(section = SECTION_NUM2, id = "42121-A10") 281 @Test(groups = { CORE }, description = "4.2.1.2.1 Ensure the shift(Number) operation is implemented.") 282 public void testUnit42121A10_ShiftByNumber() { 283 for (@SuppressWarnings("rawtypes") 284 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 285 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.1", type, Unit.class, "shift", Number.class); 286 } 287 } 288 289 /** 290 * Ensure the pow() operation is implemented. 291 */ 292 @SpecAssertion(section = SECTION_NUM2, id = "42122-A1") 293 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the pow() operation is implemented.") 294 public void testUnit42122Pow() { 295 for (@SuppressWarnings("rawtypes") 296 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 297 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.2", type, "pow", true); 298 } 299 } 300 301 /** 302 * Ensure the root() operation is implemented. 303 */ 304 @SpecAssertion(section = SECTION_NUM2, id = "42122-A2") 305 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the root() operation is implemented.") 306 public void testUnit42122Root() { 307 for (@SuppressWarnings("rawtypes") 308 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 309 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.2", type, "root", true); 310 } 311 } 312 313 /** 314 * Ensure the transform() operation is implemented. 315 */ 316 @SpecAssertion(section = SECTION_NUM2, id = "42122-A3") 317 @Test(groups = { CORE }, description = "4.2.1.2.2 Ensure the transform() operation is implemented.") 318 public void testUnit42122Transform() { 319 for (@SuppressWarnings("rawtypes") 320 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 321 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.2", type, "transform", true); 322 } 323 } 324 325 /** 326 * Ensure the inverse() operation is implemented. 327 */ 328 @SpecAssertion(section = SECTION_NUM2, id = "42123-A1") 329 @Test(groups = { CORE }, description = "4.2.1.2.3 Ensure the inverse() operation is implemented.") 330 public void testUnit42123Inverse() { 331 for (@SuppressWarnings("rawtypes") 332 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 333 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.3", type, "inverse", false); 334 } 335 } 336 337 /** 338 * Ensure the isCompatible() operation is implemented. 339 */ 340 @SpecAssertion(section = SECTION_NUM2, id = "42124-A1") 341 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure the isCompatible() operation is implemented.") 342 public void testUnit4221IsCompatible() { 343 for (@SuppressWarnings("rawtypes") 344 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 345 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.4", type, "isCompatible", true); 346 } 347 } 348 349 /** 350 * Ensure the asType() operation is implemented. 351 */ 352 @SpecAssertion(section = SECTION_NUM2, id = "42124-A2") 353 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure the asType() operation is implemented.") 354 public void testUnit4222AsType() { 355 for (@SuppressWarnings("rawtypes") 356 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 357 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.4", type, "asType", true); 358 } 359 } 360 361 /** 362 * Ensure the getConverterTo() operation is implemented. 363 */ 364 @SpecAssertion(section = SECTION_NUM2, id = "42124-A3") 365 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure the getConverterTo() operation is implemented.") 366 public void testUnit4223GetConverterTo() { 367 for (@SuppressWarnings("rawtypes") 368 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 369 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.4", type, "getConverterTo", true); 370 } 371 } 372 373 /** 374 * Ensure the getConverterToAny() operation is implemented. 375 */ 376 @SpecAssertion(section = SECTION_NUM2, id = "42124-A4") 377 @Test(groups = { CORE }, description = SECTION_NUM1 + " Ensure the getConverterToAny() operation is implemented.") 378 public void testUnit4224GetConverterToAny() { 379 for (@SuppressWarnings("rawtypes") 380 Class type : TCKSetup.getConfiguration().getUnitClasses()) { 381 testHasPublicMethod(SECTION_PREFIX + "4.2.1.2.4", type, "getConverterToAny", true); 382 } 383 } 384}