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.CurrencyContext; 013import javax.money.CurrencyContextBuilder; 014import javax.money.CurrencyUnit; 015import java.io.Serializable; 016import java.util.Objects; 017 018/** 019 * Test currency unit. 020 */ 021public final class TestCurrencyUnit implements CurrencyUnit, Serializable { 022 023 private String code; 024 private int defsultFractionUnits = 11; 025 private static final CurrencyContext CONTEXT = 026 CurrencyContextBuilder.of(TestCurrencyUnit.class.getSimpleName()).build(); 027 028 public TestCurrencyUnit(String code) { 029 Objects.requireNonNull(code); 030 this.code = code; 031 } 032 033 public TestCurrencyUnit(String code, int defsultFractionUnits) { 034 Objects.requireNonNull(code); 035 this.code = code; 036 this.defsultFractionUnits = defsultFractionUnits; 037 } 038 039 public TestCurrencyUnit() { 040 this("TesT"); 041 } 042 043 @Override 044 public String getCurrencyCode() { 045 return code; 046 } 047 048 @Override 049 public int getNumericCode() { 050 return Integer.MIN_VALUE; 051 } 052 053 @Override 054 public int getDefaultFractionDigits() { 055 return defsultFractionUnits; 056 } 057 058 @Override 059 public CurrencyContext getContext() { 060 return CONTEXT; 061 } 062 063 @Override 064 public int compareTo(CurrencyUnit o) { 065 if (o instanceof TestCurrencyUnit) { 066 return 0; 067 } 068 return 1; 069 } 070 071}