001/*
002 * Units of Measurement TCK
003 * Copyright © 2005-2023, 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.SECTION_PREFIX;
033import static tech.units.tck.TCKRunner.SPEC_ID;
034import static tech.units.tck.TCKRunner.SPEC_VERSION;
035
036import java.util.Map;
037
038import javax.measure.Dimension;
039
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;
045import tech.units.tck.util.TestUtils;
046
047/**
048 * Unit Dimension Tests
049 *
050 * @author Werner Keil
051 * @author Almas Shaikh
052 * @version 2.0, November 15, 2020
053 * @since 1.0
054 */
055@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION)
056public class UnitDimensionTest {
057    private static final String SECTION = "4.2.5";
058    
059    /**
060     * Test that Dimension implementations override equals.
061     */
062    @SpecAssertion(section = SECTION, id = "425-A1")
063    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override equals.")
064    public void testEquals() {
065        for (@SuppressWarnings("rawtypes")
066        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
067            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, boolean.class, "equals", Object.class);
068        }
069    }
070
071    /**
072     * Test that Dimension implementations override hashCode.
073     */
074    @SpecAssertion(section = SECTION, id = "425-A2")
075    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override hashCode.")
076    public void testHashcode() {
077        for (@SuppressWarnings("rawtypes")
078        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
079            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, int.class, "hashCode");
080        }
081    }
082
083    /**
084     * Test that Dimension implementations override multiply.
085     */
086    @SpecAssertion(section = SECTION, id = "425-A3")
087    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override multiply.")
088    public void testMultiply() {
089        for (@SuppressWarnings("rawtypes")
090        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
091            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, Dimension.class, "multiply", Dimension.class);
092        }
093    }
094
095    /**
096     * Test that Dimension implementations override divide.
097     */
098    @SpecAssertion(section = SECTION, id = "425-A4")
099    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override divide.")
100    public void testDivide() {
101        for (@SuppressWarnings("rawtypes")
102        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
103            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, Dimension.class, "divide", Dimension.class);
104        }
105    }
106
107    /**
108     * Test that Dimension implementations override root.
109     */
110    @SpecAssertion(section = SECTION, id = "425-A5")
111    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override root.")
112    public void testRoot() {
113        for (@SuppressWarnings("rawtypes")
114        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
115            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, Dimension.class, "root", int.class);
116        }
117    }
118
119    /**
120     * Test that Dimension implementations override pow.
121     */
122    @SpecAssertion(section = SECTION, id = "425-A6")
123    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override pow.")
124    public void testPow() {
125        for (@SuppressWarnings("rawtypes")
126        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
127            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, Dimension.class, "pow", int.class);
128        }
129    }
130
131    /**
132     * Test that Dimension implementations override getBaseDimensions.
133     */
134    @SpecAssertion(section = SECTION, id = "425-A7")
135    @Test(groups = {"core"}, description = SECTION + " Ensure registered Dimension classes override getBaseDimensions.")
136    public void testGetBaseDimensions() {
137        for (@SuppressWarnings("rawtypes")
138        Class type : TCKSetup.getConfiguration().getDimensionClasses()) {
139            TestUtils.testHasPublicMethod(SECTION_PREFIX + SECTION, type, Map.class, "getBaseDimensions");
140        }
141    }
142}