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.CurrencyUnit;
013import javax.money.MonetaryAmount;
014import javax.money.MonetaryAmountFactory;
015import javax.money.MonetaryContext;
016import javax.money.Monetary;
017import javax.money.NumberValue;
018
019public final class TestMonetaryAmountBuilder implements MonetaryAmountFactory<TestAmount> {
020
021    private Number value;
022    private CurrencyUnit currency;
023
024    public static TestAmount getAmount(final Number number, final CurrencyUnit currency) {
025        return new TestAmount(number, currency);
026    }
027
028    @Override
029    public Class<? extends MonetaryAmount> getAmountType() {
030        return TestAmount.class;
031    }
032
033    @Override
034    public MonetaryAmountFactory<TestAmount> setCurrency(String currencyCode) {
035        this.currency = Monetary.getCurrency(currencyCode);
036        return this;
037    }
038
039    @Override
040    public MonetaryAmountFactory<TestAmount> setCurrency(CurrencyUnit currency) {
041        this.currency = currency;
042        return this;
043    }
044
045    @Override
046    public MonetaryAmountFactory<TestAmount> setNumber(double number) {
047        this.value = number;
048        return this;
049    }
050
051    @Override
052    public MonetaryAmountFactory<TestAmount> setNumber(long number) {
053        this.value = number;
054        return this;
055    }
056
057    @Override
058    public MonetaryAmountFactory<TestAmount> setNumber(Number number) {
059        this.value = number;
060        return this;
061    }
062
063    @Override
064    public NumberValue getMaxNumber() {
065        return null;
066    }
067
068    @Override
069    public NumberValue getMinNumber() {
070        return null;
071    }
072
073    @Override
074    public MonetaryAmountFactory<TestAmount> setContext(MonetaryContext monetaryContext) {
075        return this;
076    }
077
078    @Override
079    public MonetaryAmountFactory<TestAmount> setAmount(MonetaryAmount amount) {
080        setCurrency(amount.getCurrency());
081        setNumber(amount.getNumber());
082        return this;
083    }
084
085    @Override
086    public TestAmount create() {
087        return new TestAmount(value, currency);
088    }
089
090    @Override
091    public MonetaryContext getDefaultMonetaryContext() {
092        return TestAmount.MONETARY_CONTEXT;
093    }
094
095    @Override
096    public MonetaryContext getMaximalMonetaryContext() {
097        return TestAmount.MONETARY_CONTEXT;
098    }
099}