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