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.spi; 031 032import static org.hamcrest.MatcherAssert.assertThat; 033import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo; 034import static org.hamcrest.number.OrderingComparison.lessThanOrEqualTo; 035import static org.testng.AssertJUnit.assertNotNull; 036import static tech.units.tck.TCKRunner.SECTION_PREFIX; 037import static tech.units.tck.TCKRunner.SPEC_ID; 038import static tech.units.tck.TCKRunner.SPEC_VERSION; 039import static tech.units.tck.util.TestGroups.SPI; 040import static org.testng.AssertJUnit.assertFalse; 041 042import java.util.List; 043 044import javax.measure.spi.ServiceProvider; 045 046import org.jboss.test.audit.annotations.SpecAssertion; 047import org.jboss.test.audit.annotations.SpecVersion; 048import org.testng.annotations.Test; 049 050/** 051 * Test class for {@link ServiceProvider}. 052 * @author Werner Keil 053 * @version 1.2, November 15, 2020 054 * @since 1.0 055 */ 056@SpecVersion(spec = SPEC_ID, version = SPEC_VERSION) 057public class ServiceProviderTest { 058 private static final String SECTION_NUM = "5.3"; 059 private static final String DESCRIPTION = SECTION_NUM + " Service Provider"; 060 061 // ************************ 5.3 Service Provider 062 // ************************ 063 /** 064 * Access available service providers. 065 */ 066 @Test(groups = { SPI }, description = DESCRIPTION) 067 @SpecAssertion(section = SECTION_NUM, id = "53-A1") 068 public void testAvailable() { 069 List<ServiceProvider> spa = ServiceProvider.available(); 070 assertNotNull(SECTION_PREFIX + SECTION_NUM + ": available ServiceProviders is null", spa); 071 } 072 073 /** 074 * Available service providers not empty. 075 */ 076 @Test(groups = { SPI }, description = DESCRIPTION) 077 @SpecAssertion(section = SECTION_NUM, id = "53-A2") 078 public void testAvailableNotEmpty() { 079 List<ServiceProvider> spa = ServiceProvider.available(); 080 assertNotNull(SECTION_PREFIX + SECTION_NUM + ": available ServiceProviders is null", spa); 081 assertFalse(SECTION_PREFIX + SECTION_NUM + ": No available ServiceProviders found", spa.isEmpty()); 082 } 083 084 // ************************ 5.3 Service Provider 085 // ************************ 086 /** 087 * Access current ServiceProvider. 088 */ 089 @Test(groups = { SPI }, description = DESCRIPTION) 090 @SpecAssertion(section = SECTION_NUM, id = "53-A3") 091 public void testCurrent() { 092 ServiceProvider sp = ServiceProvider.current(); 093 assertNotNull(SECTION_PREFIX + SECTION_NUM + ": No current ServiceProvider found", sp); 094 } 095 096 // ************************ 5.3 Service Provider 097 // ************************ 098 /** 099 * Access a ServiceProvider priority. 100 */ 101 @Test(groups = { SPI }, description = DESCRIPTION) 102 @SpecAssertion(section = SECTION_NUM, id = "53-A4") 103 public void testPriority() { 104 ServiceProvider sp = ServiceProvider.current(); 105 assertThat(SECTION_PREFIX + SECTION_NUM + ": Priority should be a valid int", sp.getPriority(), 106 greaterThanOrEqualTo(Integer.MIN_VALUE)); 107 assertThat(SECTION_PREFIX + SECTION_NUM + ": Priority should be a valid int", sp.getPriority(), 108 lessThanOrEqualTo(Integer.MAX_VALUE)); 109 } 110}