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.*;
016
017/**
018 * Created by Anatole on 19.04.2014.
019 */
020public final class TestCurrencyProvider implements CurrencyProviderSpi {
021
022    @Override
023    public Set<CurrencyUnit> getCurrencies(CurrencyQuery currencyQuery) {
024        Set<CurrencyUnit> result = new HashSet<>(1);
025        for (String cur : currencyQuery.getCurrencyCodes()) {
026            if (cur.endsWith("_test")) {
027                result.add(new TestCurrencyUnit(cur));
028            }
029        }
030        for (Locale country : currencyQuery.getCountries()) {
031            if ("test".equals(country.getVariant())) {
032                result.add(new TestCurrencyUnit(country.toString()));
033            }
034        }
035        return result;
036    }
037}