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