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.format;
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;
035import static tech.units.tck.util.TestGroups.FORMAT;
036import static tech.units.tck.util.TestUtils.testHasPublicMethod;
037import static org.testng.AssertJUnit.assertFalse;
038import static org.testng.AssertJUnit.assertNotNull;
039
040import javax.measure.Quantity;
041import javax.measure.format.QuantityFormat;
042
043import org.jboss.test.audit.annotations.SpecAssertion;
044import org.jboss.test.audit.annotations.SpecVersion;
045import org.testng.annotations.Test;
046
047import tech.units.tck.TCKSetup;
048
049/**
050 * Tests for QuantityFormat
051 * @version 2.1, November 15, 2020
052 * @since 2.0
053 * @author  <a href="mailto:[email protected]">Werner Keil</a>
054 */
055@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION)
056public class QuantityFormatTest {
057        private static final String SECTION_NUM = "4.6";
058        
059    /**
060     * Ensure at least one QuantityFormat implementation
061     * is available/registered.
062     */
063    @SpecAssertion(section = SECTION_NUM, id = "46-A1")
064    @Test(groups = { FORMAT }, description = SECTION_NUM + " Ensure at least one QuantityFormat implementation is available/registered.")
065    public void testEnsureGotQuantityFormat() {
066        assertNotNull("TCK Configuration not available.", TCKSetup.getConfiguration());
067        assertFalse(TCKSetup.getConfiguration().getQuantityFormats4Test().isEmpty());
068    }
069    
070    /**
071     * Ensure the format() operation is implemented.
072     */
073    @SpecAssertion(section = SECTION_NUM, id = "46-A2")
074    @Test(groups = { FORMAT }, description = SECTION_NUM + " Ensure the format() operation is implemented.")
075    public void testQuantityFormatFormat() {
076        for (QuantityFormat format : TCKSetup.getConfiguration().getQuantityFormats4Test()) {
077                Class<?> type = format.getClass();
078            testHasPublicMethod(SECTION_PREFIX + SECTION_NUM, type, false, Appendable.class, "format", Quantity.class);
079        }
080    }
081    
082    /**
083     * Ensure the appendable format() operation is implemented.
084     */
085    @SpecAssertion(section = SECTION_NUM, id = "46-A3")
086    @Test(groups = { FORMAT }, description = SECTION_NUM + " Ensure the appendable format() operation is implemented.")
087    public void testQuantityFormatFormatAppendable() {
088        for (QuantityFormat format : TCKSetup.getConfiguration().getQuantityFormats4Test()) {
089                Class<?> type = format.getClass();
090            testHasPublicMethod(SECTION_PREFIX + SECTION_NUM, type, false, Appendable.class, "format", Quantity.class, Appendable.class);
091        }
092    }
093    
094    /**
095     * Ensure the isLocaleSensitive() method is implemented.
096     */
097    @SpecAssertion(section = SECTION_NUM, id = "46-A4")
098    @Test(groups = { FORMAT }, description = SECTION_NUM + " Ensure the isLocaleSensitive() method is implemented.")
099    public void testQuantityFormatFormatIsLocalSensitive() {
100        for (QuantityFormat format : TCKSetup.getConfiguration().getQuantityFormats4Test()) {
101                Class<?> type = format.getClass();
102            testHasPublicMethod(SECTION_PREFIX + SECTION_NUM, type, "isLocaleSensitive", false);
103        }
104    }
105    
106    /**
107     * Ensure the parse() operation is implemented.
108     */
109    @SpecAssertion(section = SECTION_NUM, id = "46-A5")
110    @Test(groups = { FORMAT }, description = SECTION_NUM + " Ensure the parse() operation is implemented.")
111    public void testQuantityFormatParse() {
112        for (QuantityFormat format : TCKSetup.getConfiguration().getQuantityFormats4Test()) {
113                Class<?> type = format.getClass();
114            testHasPublicMethod(SECTION_PREFIX + SECTION_NUM, type, "parse", true);
115        }
116    }
117}