001/*
002 * Units of Measurement TCK
003 * Copyright © 2005-2017, Jean-Marie Dautelle, Werner Keil, V2COM.
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;
034
035import javax.measure.Unit;
036import org.jboss.test.audit.annotations.SpecAssertion;
037import org.jboss.test.audit.annotations.SpecVersion;
038import org.testng.annotations.Test;
039
040import tech.units.tck.TCKSetup;
041import tech.units.tck.util.TestUtils;
042
043/**
044 * Testing the Unit Interface
045 *
046 * @author Werner Keil
047 * @author Almas Shaikh
048 * @version 1.0, August 16, 2016
049 * @since 1.0
050 */
051@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION)
052public class UnitInterfaceTest {
053
054    /**
055     * Test that Unit implementations override equals.
056     */
057    @SpecAssertion(section = "4.2.1", id = "421-A1")
058    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes override equals.")
059    public void testEquals() {
060        for (@SuppressWarnings("rawtypes")
061        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
062            TestUtils.testHasPublicMethod("Section 4.2.1", type, "equals", true);
063        }
064    }
065
066    /**
067     * Test that Unit implementations contain getters
068     */
069    @SpecAssertion(section = "4.2.1", id = "421-A2")
070    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes implement getDimension.")
071    public void testGetDimension() {
072        for (@SuppressWarnings("rawtypes")
073        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
074            TestUtils.testHasPublicMethod("Section 4.2.1", type, "getDimension");
075        }
076    }
077
078    /**
079     * Test that Unit implementations contain getSystemUnit
080     */
081    @SpecAssertion(section = "4.2.1", id = "421-A3")
082    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes implement getSystemUnit.")
083    public void testGetSystemUnit() {
084        for (@SuppressWarnings("rawtypes")
085        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
086            TestUtils.testHasPublicMethod("Section 4.2.1", type, "getSystemUnit");
087        }
088    }
089
090    /**
091     * Test that Unit implementations contain getBaseUnits
092     */
093    @SpecAssertion(section = "4.2.1", id = "421-A4")
094    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes implement getBaseUnits.")
095    public void testGetBaseUnits() {
096        for (@SuppressWarnings("rawtypes")
097        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
098            TestUtils.testHasPublicMethod("Section 4.2.1", type, "getBaseUnits");
099        }
100    }
101
102    /**
103     * Test that Unit implementations contain getters
104     */
105    @SuppressWarnings({"rawtypes"})
106    @SpecAssertion(section = "4.2.1", id = "421-A5")
107    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes implement getName.")
108    public void testGetName() {
109        for (Class type : TCKSetup.getConfiguration().getUnitClasses()) {
110            TestUtils.testHasPublicMethod("Section 4.2.1", type, "getName");
111        }
112    }
113
114    /**
115     * Test that Unit implementations contain getters
116     */
117    @SuppressWarnings({"rawtypes"})
118    @SpecAssertion(section = "4.2.1", id = "421-A6")
119    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes implement getSymbol.")
120    public void testGetSymbol() {
121        for (Class type : TCKSetup.getConfiguration().getUnitClasses()) {
122            TestUtils.testHasPublicMethod("Section 4.2.1", type, "getSymbol");
123        }
124    }
125
126    /**
127     * Test that Unit implementations override hashCode.
128     */
129    @SpecAssertion(section = "4.2.1", id = "421-A7")
130    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes override hashCode.")
131    public void testHashcode() {
132        for (@SuppressWarnings("rawtypes")
133        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
134            TestUtils.testHasPublicMethod("Section 4.2.1", type, "hashCode");
135        }
136    }
137
138    /**
139     * Test that Unit implementations override toString.
140     */
141    @SpecAssertion(section = "4.2.1", id = "421-A8")
142    @Test(groups = {"core"}, description = "4.2.1 Ensure registered Unit classes override toString.")
143    public void testToString() {
144        for (@SuppressWarnings("rawtypes")
145        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
146            TestUtils.testHasPublicMethod("Section 4.2.1", type, "toString");
147        }
148    }
149
150    /**
151     * Ensure the shift() operation is implemented.
152     */
153    @SpecAssertion(section = "4.2.1.2", id = "42121-A1")
154    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the shift() operation is implemented.")
155    public void testUnit42121Shift() {
156        for (@SuppressWarnings("rawtypes")
157        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
158            TestUtils.testHasPublicMethod("Section 4.2.1.2", type, "shift", true);
159        }
160    }
161
162    /**
163     * Ensure the multiply() operation is implemented.
164     */
165    @SpecAssertion(section = "4.2.1.2", id = "42121-A2")
166    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the multiply() operation is implemented.")
167    public void testUnit42121Multiply() {
168        for (@SuppressWarnings("rawtypes")
169        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
170            TestUtils.testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "multiply", Unit.class);
171        }
172    } 
173
174    /**
175     * Ensure the divide() operation is implemented.
176     */
177    @SpecAssertion(section = "4.2.1.2", id = "42121-A3")
178    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the divide() operation is implemented.")
179    public void testUnit42121Divide() {
180        for (@SuppressWarnings("rawtypes")
181        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
182            TestUtils.testHasPublicMethod("Section 4.2.1.4", type, Unit.class, "divide", Unit.class);
183        }
184    }
185
186    /**
187     * Ensure the multiply() operation is implemented.
188     */
189    @SpecAssertion(section = "4.2.1.2", id = "42121-A4")
190    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the multiply(double) operation is implemented.")
191    public void testUnit42121MultiplyByDouble() {
192        for (@SuppressWarnings("rawtypes")
193        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
194            TestUtils.testHasPublicMethod("Section 4.2.1.3", type, Unit.class, "multiply", double.class);
195        }
196    }
197    
198    /**
199     * Ensure the divide() operation is implemented.
200     */
201    @SpecAssertion(section = "4.2.1.2", id = "42121-A5")
202    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the divide(double) operation is implemented.")
203    public void testUnit42121DivideByDouble() {
204        for (@SuppressWarnings("rawtypes")
205        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
206            TestUtils.testHasPublicMethod("Section 4.2.1.2.1", type, Unit.class, "divide", double.class);
207        }
208    }
209
210    /**
211     * Ensure the alternate() operation is implemented.
212     */
213    @SpecAssertion(section = "4.2.1.2", id = "42121-A6")
214    @Test(groups = {"core"}, description = "4.2.1.2.1 Ensure the alternate() operation is implemented.")
215    public void testUnit42121Alternate() {
216        for (@SuppressWarnings("rawtypes")
217        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
218            TestUtils.testHasPublicMethod("Section 4.2.1.2.1", type, "alternate", true);
219        }
220    }
221    
222    /**
223     * Ensure the pow() operation is implemented.
224     */
225    @SpecAssertion(section = "4.2.1.2", id = "42122-A1")
226    @Test(groups = {"core"}, description = "4.2.1.2.2 Ensure the pow() operation is implemented.")
227    public void testUnit42122Pow() {
228        for (@SuppressWarnings("rawtypes")
229        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
230            TestUtils.testHasPublicMethod("Section 4.2.1.2.2", type, "pow", true);
231        }
232    }
233    
234    /**
235     * Ensure the root() operation is implemented.
236     */
237    @SpecAssertion(section = "4.2.1.2", id = "42122-A2")
238    @Test(groups = {"core"}, description = "4.2.1.2.2 Ensure the root() operation is implemented.")
239    public void testUnit42122Root() {
240        for (@SuppressWarnings("rawtypes")
241        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
242            TestUtils.testHasPublicMethod("Section 4.2.1.2.2", type, "root", true);
243        }
244    }
245
246    /**
247     * Ensure the transform() operation is implemented.
248     */
249    @SpecAssertion(section = "4.2.1.2", id = "42122-A3")
250    @Test(groups = {"core"}, description = "4.2.1.2.2 Ensure the transform() operation is implemented.")
251    public void testUnit42122Transform() {
252        for (@SuppressWarnings("rawtypes")
253        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
254            TestUtils.testHasPublicMethod("Section 4.2.1.2.2", type, "transform", true);
255        }
256    }
257    
258    /**
259     * Ensure the inverse() operation is implemented.
260     */
261    @SpecAssertion(section = "4.2.1.2", id = "42123-A1")
262    @Test(groups = {"core"}, description = "4.2.1.2.3 Ensure the inverse() operation is implemented.")
263    public void testUnit42123Inverse() {
264        for (@SuppressWarnings("rawtypes")
265        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
266            TestUtils.testHasPublicMethod("Section 4.2.1.2.3", type, "inverse", false);
267        }
268    }
269
270    /**
271     * Ensure the isCompatible() operation is implemented.
272     */
273    @SpecAssertion(section = "4.2.2", id = "422-A1")
274    @Test(groups = {"core"}, description = "4.2.2 Ensure the isCompatible() operation is implemented.")
275    public void testUnit422IsCompatible() {
276        for (@SuppressWarnings("rawtypes")
277        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
278            TestUtils.testHasPublicMethod("Section 4.2.3", type, "isCompatible", true);
279        }
280    }
281
282    /**
283     * Ensure the asType() operation is implemented.
284     */
285    @SpecAssertion(section = "4.2.2", id = "422-A2")
286    @Test(groups = {"core"}, description = "4.2.2 Ensure the asType() operation is implemented.")
287    public void testUnit423AsType() {
288        for (@SuppressWarnings("rawtypes")
289        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
290            TestUtils.testHasPublicMethod("Section 4.2.2", type, "asType", true);
291        }
292    }
293    
294    /**
295     * Ensure the getConverterTo() operation is implemented.
296     */
297    @SpecAssertion(section = "4.2.3", id = "423-A1")
298    @Test(groups = {"core"}, description = "4.2.3 Ensure the getConverterTo() operation is implemented.")
299    public void testUnit423GetConverterTo() {
300        for (@SuppressWarnings("rawtypes")
301        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
302            TestUtils.testHasPublicMethod("Section 4.2.3", type, "getConverterTo", true);
303        }
304    }
305
306    /**
307     * Ensure the getConverterToAny() operation is implemented.
308     */
309    @SpecAssertion(section = "4.2.3", id = "423-A2")
310    @Test(groups = {"core"}, description = "4.2.3 Ensure the getConverterToAny() operation is implemented.")
311    public void testUnit423GetConverterToAny() {
312        for (@SuppressWarnings("rawtypes")
313        Class type : TCKSetup.getConfiguration().getUnitClasses()) {
314            TestUtils.testHasPublicMethod("Section 4.2.3", type, "getConverterToAny", true);
315        }
316    }
317}