Skip to content

Commit bab2437

Browse files
committed
Added test for TCK execution.
1 parent d7245bf commit bab2437

File tree

8 files changed

+162
-64
lines changed

8 files changed

+162
-64
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
jsr354-ritest
22
=============
33

4-
Test Project illustrating how an implementation can be tested using the TCK. The moneta reference implementation is used hereby.
4+
Test Project illustrating how an implementation can be tested using the TCK. The moneta reference implementation is used
5+
hereby.
6+
7+
The TCK can be started either:
8+
9+
* by running
10+
11+
java org.javamoney.tck.TCKRunner
12+
13+
* or by starting the TCK via JUnit (RunTCK test class)
14+

src/main/java/MyCurrency.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/main/java/RunTCK.java

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.javamoney.text.tck;
17+
18+
import javax.money.CurrencyContext;
19+
import javax.money.CurrencyContextBuilder;
20+
import javax.money.CurrencyUnit;
21+
import javax.money.MonetaryException;
22+
import java.util.Objects;
23+
24+
/**
25+
* Test implk class for currencies.
26+
*/
27+
public final class MyCurrency implements CurrencyUnit {
28+
29+
/**
30+
* serialVersionUID.
31+
*/
32+
private static final long serialVersionUID = -2389580389919492220L;
33+
/**
34+
* The unique currency code.
35+
*/
36+
private String currencyCode;
37+
/**
38+
* The (optional) numeric code.
39+
*/
40+
private int numericCode;
41+
/**
42+
* The default fraction digits.
43+
*/
44+
private int defaultFractionDigits;
45+
/**
46+
* THe currency's context.
47+
*/
48+
private static final javax.money.CurrencyContext currencyContext =
49+
CurrencyContextBuilder.of("org.javamoney.text.tck.MyCurrency").build();
50+
51+
52+
/**
53+
* Constructor, called from the Builder.
54+
*
55+
* @param code the code, never null.
56+
*/
57+
MyCurrency(String code) {
58+
this.defaultFractionDigits = 2;
59+
this.numericCode = -1;
60+
this.currencyCode = Objects.requireNonNull(code, "currencyCode required");
61+
}
62+
63+
@Override
64+
public CurrencyContext getContext() {
65+
return currencyContext;
66+
}
67+
68+
@Override
69+
public String getCurrencyCode() {
70+
return currencyCode;
71+
}
72+
73+
@Override
74+
public int getNumericCode() {
75+
return numericCode;
76+
}
77+
78+
@Override
79+
public int getDefaultFractionDigits() {
80+
return defaultFractionDigits;
81+
}
82+
83+
@Override
84+
public int compareTo(@SuppressWarnings("NullableProblems") CurrencyUnit o) {
85+
Objects.requireNonNull(o);
86+
return this.currencyCode.compareTo(o.getCurrencyCode());
87+
}
88+
89+
/* (non-Javadoc)
90+
* @see java.lang.Object#hashCode()
91+
*/
92+
@Override
93+
public int hashCode() {
94+
return Objects.hashCode(currencyCode);
95+
}
96+
97+
/* (non-Javadoc)
98+
* @see java.lang.Object#equals(java.lang.Object)
99+
*/
100+
@Override
101+
public boolean equals(Object obj) {
102+
if (obj == this) {
103+
return true;
104+
}
105+
if (obj instanceof MyCurrency) {
106+
MyCurrency other = (MyCurrency) obj;
107+
return Objects.equals(currencyCode, other.currencyCode);
108+
}
109+
return false;
110+
}
111+
112+
/* (non-Javadoc)
113+
* @see java.lang.Object#toString()
114+
*/
115+
@Override
116+
public String toString() {
117+
return "MyCurrency(currencyCode=" + currencyCode + ", numericCode=" + numericCode +
118+
", defaultFractionDigits=" + defaultFractionDigits + ", context=" + this.currencyContext + ')';
119+
}
120+
121+
}

src/main/java/MyMoney.java renamed to src/main/java/org/javamoney/text/tck/MyMoney.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1+
/**
2+
* Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package org.javamoney.text.tck;
17+
118
import javax.money.CurrencyUnit;
219
import javax.money.MonetaryAmount;
320
import javax.money.MonetaryAmountFactory;
421
import javax.money.MonetaryContext;
22+
import javax.money.MonetaryContextBuilder;
523
import javax.money.NumberValue;
24+
import java.math.BigDecimal;
625

726
/**
827
* Created by Anatole on 04.03.2015.
928
*/
1029
public final class MyMoney implements MonetaryAmount {
30+
31+
private static final MonetaryContext monetaryContext = MonetaryContextBuilder.of(MyMoney.class)
32+
.setMaxScale(new BigDecimal(Double.MAX_VALUE).scale()).build();
33+
1134
@Override
1235
public MonetaryContext getContext() {
13-
return null;
36+
return monetaryContext;
1437
}
1538

1639
@Override

src/main/java/TCKTestSetup.java renamed to src/main/java/org/javamoney/text/tck/TCKTestSetup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* License for the specific language governing permissions and limitations under
1414
* the License.
1515
*/
16+
package org.javamoney.text.tck;
1617

1718
import org.javamoney.tck.JSR354TestConfiguration;
1819

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
TCKTestSetup
1+
org.javamoney.text.tck.TCKTestSetup

src/test/RunTCK.java renamed to src/test/java/org/javamoney/test/tck/RunTCK.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
package org.javamoney.test.tck;
2+
3+
import org.javamoney.tck.TCKRunner;
14
import org.junit.Test;
25

36
public class RunTCK{
47

58
@Test
6-
public runTCK(){
9+
public void runTCK(){
710
TCKRunner.main(new String[0]);
811
}
912

0 commit comments

Comments
 (0)