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.format;
031
032import static tech.units.tck.TCKRunner.SPEC_ID;
033import static tech.units.tck.TCKRunner.SPEC_VERSION;
034import static tech.units.tck.util.TestGroups.FORMAT;
035import static org.testng.AssertJUnit.assertFalse;
036import static org.testng.AssertJUnit.assertNotNull;
037import static tech.units.tck.util.TestUtils.testHasPublicMethod;
038
039import javax.measure.Unit;
040import javax.measure.format.UnitFormat;
041
042import org.jboss.test.audit.annotations.SpecAssertion;
043import org.jboss.test.audit.annotations.SpecVersion;
044import org.testng.annotations.Test;
045
046import tech.units.tck.TCKSetup;
047
048/**
049 * Tests for UnitFormat
050 * @version 1.2, March 5, 2019
051 * @since 1.0
052 * @author  <a href="mailto:[email protected]">Werner Keil</a>
053 */
054@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION)
055public class UnitFormatTest {
056
057    /**
058     * Ensure at least one UnitFormat implementation
059     * is available/registered.
060     */
061    @SpecAssertion(section = "4.5", id = "45-A1")
062    @Test(groups = { FORMAT }, description = "4.5 Ensure at least one UnitFormat implementation is available/registered.")
063    public void testEnsureGotUnitFormat() {
064        assertNotNull("TCK Configuration not available.", TCKSetup.getConfiguration());
065        assertFalse(TCKSetup.getConfiguration().getUnitFormats4Test().isEmpty());
066    }
067    
068    /**
069     * Ensure the format() operation is implemented.
070     */
071    @SpecAssertion(section = "4.5", id = "45-A2")
072    @Test(groups = { FORMAT }, description = "4.5 Ensure the format() operation is implemented.")
073    public void testUnitFormatFormat() {
074        for (UnitFormat format : TCKSetup.getConfiguration().getUnitFormats4Test()) {
075                Class<?> type = format.getClass();
076            testHasPublicMethod("Section 4.5", type, false, String.class, "format", Unit.class);
077        }
078    }
079    
080    /**
081     * Ensure the appendable format() operation is implemented.
082     */
083    @SpecAssertion(section = "4.5", id = "45-A3")
084    @Test(groups = { FORMAT }, description = "4.5 Ensure the appendable format() operation is implemented.")
085    public void testUnitFormatFormatAppendable() {
086        for (UnitFormat format : TCKSetup.getConfiguration().getUnitFormats4Test()) {
087                Class<?> type = format.getClass();
088            testHasPublicMethod("Section 4.5", type, false, Appendable.class, "format", Unit.class, Appendable.class);
089        }
090    }
091    
092    /**
093     * Ensure the isLocaleSensitive() method is implemented.
094     */
095    @SpecAssertion(section = "4.5", id = "45-A4")
096    @Test(groups = { FORMAT }, description = "4.5 Ensure the isLocaleSensitive() method is implemented.")
097    public void testUnitFormatFormatIsLocalSensitive() {
098        for (UnitFormat format : TCKSetup.getConfiguration().getUnitFormats4Test()) {
099                Class<?> type = format.getClass();
100            testHasPublicMethod("Section 4.5", type, "isLocaleSensitive", false);
101        }
102    }
103    
104    /**
105     * Ensure the label() operation is implemented.
106     */
107    @SpecAssertion(section = "4.5", id = "45-A5")
108    @Test(groups = { FORMAT }, description = "4.5 Ensure the label() operation is implemented.")
109    public void testUnitFormatLabel() {
110        for (UnitFormat format : TCKSetup.getConfiguration().getUnitFormats4Test()) {
111                Class<?> type = format.getClass();
112            testHasPublicMethod("Section 4.5", type, "label", true);
113        }
114    }
115    
116    /**
117     * Ensure the parse() operation is implemented.
118     */
119    @SpecAssertion(section = "4.5", id = "45-A6")
120    @Test(groups = { FORMAT }, description = "4.5 Ensure the parse() operation is implemented.")
121    public void testUnitFormatParse() {
122        for (UnitFormat format : TCKSetup.getConfiguration().getUnitFormats4Test()) {
123                Class<?> type = format.getClass();
124            testHasPublicMethod("Section 4.5", type, "parse", true);
125        }
126    }
127}