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