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