package org.javamoney.shelter.bitcoin.provider;

import org.junit.Test;

import javax.money.CurrencyQuery;
import javax.money.CurrencyQueryBuilder;
import javax.money.CurrencyUnit;
import javax.money.MonetaryCurrencies;
import javax.money.UnknownCurrencyException;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
 * First cut at a test for a BitcoinCurrencyProvider
 *
 * @author Sean Gilligan
 */
public class BitcoinCurrencyProviderTest {

    @Test
    public void canCreateNewInstance() {
        BitcoinCurrencyProvider provider = new BitcoinCurrencyProvider();
        assertNotNull(provider);
    }

    @Test
    public void returnsBitcoinForEmptyQuery() {
        BitcoinCurrencyProvider provider = new BitcoinCurrencyProvider();
        assertNotNull(provider);
        CurrencyQuery query = CurrencyQueryBuilder.of().build();
        Set<CurrencyUnit> currencies = provider.getCurrencies(query);
        assertEquals("returned 1 currency", 1, currencies.size());
        CurrencyUnit btc = (CurrencyUnit) currencies.toArray()[0];
        assertEquals("currency is BTC", "BTC", btc.getCurrencyCode());
    }

    @Test
    public void returnsBitcoinForBTCQuery() {
        BitcoinCurrencyProvider provider = new BitcoinCurrencyProvider();
        assertNotNull(provider);
        CurrencyQuery query = CurrencyQueryBuilder.of().setCurrencyCodes("BTC").build();
        Set<CurrencyUnit> currencies = provider.getCurrencies(query);
        assertEquals("returned 1 currency", 1, currencies.size());
        CurrencyUnit btc = (CurrencyUnit) currencies.toArray()[0];
        assertEquals("currency is BTC", "BTC", btc.getCurrencyCode());
    }

    @Test
    public void returnsEmptyForUSDQuery() {
        BitcoinCurrencyProvider provider = new BitcoinCurrencyProvider();
        assertNotNull(provider);
        CurrencyQuery query = CurrencyQueryBuilder.of().setCurrencyCodes("USD").build();
        Set<CurrencyUnit> currencies = provider.getCurrencies(query);
        assertEquals("returned 0 currencies", 0, currencies.size());
    }

    @Test(expected=UnknownCurrencyException.class)
    public void canNOTBeFoundViaMonetaryCurrencies() {
        // Since we're not registered properly MonetaryCurrencies.getCurrency should throw an exception
        CurrencyUnit btc = MonetaryCurrencies.getCurrency("BTC");
    }

}

@@ -42,16 +42,100 @@
 vider;%0A%0A
+import org.javamoney.moneta.CurrencyUnitBuilder;%0Aimport org.javamoney.moneta.Money;%0A
 import o
@@ -258,16 +258,51 @@
 cyUnit;%0A
+import javax.money.MonetaryAmount;%0A
 import j
@@ -2515,10 +2515,1307 @@
 %0A    %7D%0A%0A
+    @Test()%0A    public void WeCanMakeMoneyNow() %7B%0A        // Since we're not registered properly MonetaryCurrencies.getCurrency should throw an exception%0A        BitcoinCurrencyProvider provider = new BitcoinCurrencyProvider();%0A        assertNotNull(provider);%0A        CurrencyQuery query = CurrencyQueryBuilder.of().setCurrencyCodes(%22BTC%22).build();%0A        Set%3CCurrencyUnit%3E currencies = provider.getCurrencies(query);%0A        assertEquals(%22returned 1 currency%22, 1, currencies.size());%0A        CurrencyUnit btc = (CurrencyUnit) currencies.toArray()%5B0%5D;%0A        assertEquals(%22currency is BTC%22, %22BTC%22, btc.getCurrencyCode());%0A%0A        MonetaryAmount oneBitcoin = Money.of(1, btc);%0A        assertNotNull(oneBitcoin);%0A        assertEquals(%22number is correct%22, 1L, oneBitcoin.getNumber().longValueExact());%0A        assertEquals(%22units is correct%22, btc, oneBitcoin.getCurrency());%0A    %7D%0A%0A    @Test%0A    public void WeDoNotReallyNeedAProviderToMakeMoney() %7B%0A        CurrencyUnit btc = CurrencyUnitBuilder.of(%22BTC%22, %22ad hoc btc provider%22).build();%0A        MonetaryAmount oneBitcoin = Money.of(1, btc);%0A        assertNotNull(oneBitcoin);%0A        assertEquals(%22number is correct%22, 1L, oneBitcoin.getNumber().longValueExact());%0A        assertEquals(%22units is correct%22, btc, oneBitcoin.getCurrency());%0A    %7D%0A%0A
 %7D%0A

Add two more tests