001/* 002 * Copyright (c) 2012, 2013, Werner Keil, Credit Suisse (Anatole Tresch). Licensed under the Apache 003 * License, Version 2.0 (the "License"); you may not use this file except in compliance with the 004 * License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 005 * Unless required by applicable law or agreed to in writing, software distributed under the License 006 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 007 * or implied. See the License for the specific language governing permissions and limitations under 008 * the License. Contributors: Anatole Tresch - initial version. 009 */ 010package org.javamoney.tck.tests.internal; 011 012import javax.money.CurrencyQuery; 013import javax.money.CurrencyUnit; 014import javax.money.spi.CurrencyProviderSpi; 015import java.util.HashSet; 016import java.util.Locale; 017import java.util.Set; 018 019/** 020 * Test currency provider. 021 */ 022public final class TestCurrencyProvider implements CurrencyProviderSpi { 023 024 @Override 025 public String getProviderName() { 026 return getClass().getSimpleName(); 027 } 028 029 @Override 030 public boolean isCurrencyAvailable(CurrencyQuery query) { 031 return !getCurrencies(query).isEmpty(); 032 } 033 034 @Override 035 public Set<CurrencyUnit> getCurrencies(CurrencyQuery currencyQuery) { 036 Set<CurrencyUnit> result = new HashSet<>(1); 037 for (String cur : currencyQuery.getCurrencyCodes()) { 038 if (cur.endsWith("_test")) { 039 result.add(new TestCurrencyUnit(cur)); 040 } 041 } 042 for (Locale country : currencyQuery.getCountries()) { 043 if ("test".equals(country.getVariant())) { 044 result.add(new TestCurrencyUnit(country.toString())); 045 } 046 } 047 return result; 048 } 049}