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.quantity;
031
032import static tech.units.tck.TCKRunner.SPEC_ID;
033import static tech.units.tck.TCKRunner.SPEC_VERSION;
034
035import javax.measure.Quantity;
036import javax.measure.Unit;
037
038import org.jboss.test.audit.annotations.SpecAssertion;
039import org.jboss.test.audit.annotations.SpecVersion;
040import org.testng.annotations.Test;
041
042import tech.units.tck.TCKSetup;
043import tech.units.tck.util.TestUtils;
044
045/**
046 * Tests for The Quantity Interface
047 *
048 * @author <a href="mailto:[email protected]">Werner Keil</a>
049 * @author Almas Shaikh
050 * @version 1.2, February 21, 2019
051 * @since 1.0
052 */
053@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION)
054public class QuantityInterfaceTest {
055    private static final String SECTION = "4.3.1";
056    
057    /**
058     * Test that Quantity implementations override asType method.
059     */
060    @SpecAssertion(section = SECTION, id = "431-A1")
061    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes implement asType method.")
062    public void testQuantityCastAsType() {
063        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
064            TestUtils.testHasPublicMethod("Section 4.3.1", type, Quantity.class, "asType", Class.class);
065        }
066    }
067    /**
068     * Test that Quantity implementations override equals.
069     */
070    @SpecAssertion(section = SECTION, id = "431-A2")
071    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes override equals.")
072    public void testQuantityEquals() {
073        for (Class<?> type : TCKSetup.getConfiguration().getQuantityClasses()) {
074            TestUtils.testHasPublicMethod("Section " + SECTION, type, "equals", true);
075        }
076    }
077    
078    /**
079     * Test that Quantity implementations override getScale.
080     */
081    @SpecAssertion(section = SECTION, id = "431-A3")
082    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes implement getScale method.")
083    public void testQuantityGetScale() {
084        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
085            TestUtils.testHasPublicMethod("Section 4.3.1", type, "getScale");
086        }
087    }
088
089
090    /**
091     * Test that Quantity implementations override getUnit.
092     */
093    @SpecAssertion(section = SECTION, id = "431-A4")
094    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes implement getUnit.")
095    public void testQuantityGetUnit() {
096        for (Class<?> type : TCKSetup.getConfiguration().getQuantityClasses()) {
097            TestUtils.testHasPublicMethod("Section 4.3.1", type, "getUnit");
098        }
099    }
100
101    /**
102     * Test that Quantity implementations override getValue.
103     */
104    @SpecAssertion(section = "4.3.1", id = "431-A5")
105    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes implement getValue.")
106    public void testQuantityGetValue() {
107        for (Class<?> type : TCKSetup.getConfiguration().getQuantityClasses()) {
108            TestUtils.testHasPublicMethod("Section 4.3.1", type, "getValue");
109        }
110    }
111
112    /**
113     * Test that Quantity implementations override hashCode.
114     */
115    @SpecAssertion(section = SECTION, id = "431-A6")
116    @Test(groups = {"core"}, description = SECTION + " Ensure registered Quantity classes override hashCode.")
117    public void testQuantityHashcode() {
118        for (Class<?> type : TCKSetup.getConfiguration().getQuantityClasses()) {
119            TestUtils.testHasPublicMethod("Section 4.3.1", type, "hashCode");
120        }
121    }
122    
123    /**
124     * Test that Quantity implementations override add.
125     */
126    @SpecAssertion(section = "4.3.1.1", id = "4411-A1")
127    @Test(groups = {"core"}, description = "4.3.1.1 Ensure registered Quantity classes implement add.")
128    public void testQuantityOp1Add() {
129        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
130            TestUtils.testHasPublicMethod("Section 4.3.1.1", type, Quantity.class, "add", Quantity.class);
131        }
132    }
133
134    /**
135     * Test that Quantity implementations override multiply.
136     */
137    @SpecAssertion(section = "4.3.1.2", id = "4412-A1")
138    @Test(groups = {"core"}, description = "4.3.1.2 Ensure registered Quantity classes implement multiply.")
139    public void testQuantityOp2Multiply() {
140        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
141            TestUtils.testHasPublicMethod("Section 4.3.1.2", type, Quantity.class, "multiply", Quantity.class);
142        }
143    }
144
145    /**
146     * Test that Quantity implementations override divide.
147     */
148    @SpecAssertion(section = "4.3.1.2", id = "4412-A2")
149    @Test(groups = {"core"}, description = "4.3.1.2 Ensure registered Quantity classes implement divide.")
150    public void testQuantityOp2Divide() {
151        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
152            TestUtils.testHasPublicMethod("Section 4.3.1.2", type, Quantity.class, "divide", Quantity.class);
153        }
154    }
155
156    /**
157     * Test that Quantity implementations override multiply with number as argument.
158     */
159    @SpecAssertion(section = "4.3.1.1", id = "4411-A4")
160    @Test(groups = {"core"}, description = "4.3.1.1 Ensure registered Quantity classes implement multiply by number.")
161    public void testQuantityOp1MultiplyByNumber() {
162        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
163            TestUtils.testHasPublicMethod("Section 4.3.1.1", type, Quantity.class, "multiply", Number.class);
164        }
165    }
166
167    /**
168     * Test that Quantity implementations override divide with number as argument.
169     */
170    @SpecAssertion(section = "4.3.1.1", id = "4411-A5")
171    @Test(groups = {"core"}, description = "4.3.1.1 Ensure registered Quantity classes implement divide by number.")
172    public void testQuantityOp1DivideByNumber() {
173        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
174            TestUtils.testHasPublicMethod("Section 4.3.1.1", type, Quantity.class, "divide", Number.class);
175        }
176    }
177
178    /**
179     * Test that Quantity implementations override subtract.
180     */
181    @SpecAssertion(section = "4.3.1.1", id = "4411-A6")
182    @Test(groups = {"core"}, description = "4.3.1.1 Ensure registered Quantity classes implement subtract.")
183    public void testQuantityOp1Subtract() {
184        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
185            TestUtils.testHasPublicMethod("Section 4.3.1.1", type, Quantity.class, "subtract", Quantity.class);
186        }
187    }
188
189    /**
190     * Test that Quantity implementations override to method.
191     */
192    @SpecAssertion(section = "4.3.1.2", id = "4412-A3")
193    @Test(groups = {"core"}, description = "4.3.1.2 Ensure registered Quantity classes implement to method.")
194    public void testQuantityOp2To() {
195        for (Class type : TCKSetup.getConfiguration().getQuantityClasses()) {
196            TestUtils.testHasPublicMethod("Section 4.3.1.2", type, Quantity.class, "to", Unit.class);
197        }
198    }
199
200    /**
201     * Test that Quantity implementations override getUnit.
202     */
203    @SpecAssertion(section = "4.3.1.3", id = "431-A8")
204    @Test(groups = {"core"}, description = "4.3.1.3 Ensure registered Quantity classes implement inverse method.")
205    public void testQuantityOp3Inverse() {
206        for (Class<?> type : TCKSetup.getConfiguration().getQuantityClasses()) {
207            TestUtils.testHasPublicMethod("Section 4.3.1.3", type, "inverse");
208        }
209    }
210}