Skip to content

Commit 0a1dbd0

Browse files
committed
Reorganized assertion numbering. Reconnected existing tests.
Added additional assertions, clarified contents.
1 parent 7be444f commit 0a1dbd0

File tree

4 files changed

+663
-504
lines changed

4 files changed

+663
-504
lines changed

src/test/java/org/javamoney/tck/tests/CurrencyUnitTest.java

Lines changed: 71 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
@SpecVersion(spec = "JSR 354", version = "0.8")
2323
public class CurrencyUnitTest {
2424

25-
@SpecAssertion(
26-
section = "4.2.1",
27-
id = "EnsureCurrencyUnit")
25+
@SpecAssertion(section = "4.2.1", id = "421-A1")
2826
@Test
2927
public void testEnsureCurrencyUnit() {
3028
assertTrue("TCK Configuration not available.",
@@ -33,71 +31,54 @@ public void testEnsureCurrencyUnit() {
3331
.size() > 0);
3432
}
3533

36-
@SpecAssertion(
37-
section = "4.2.1",
38-
id = "Enforce3LetterCode4ISO")
34+
@SpecAssertion(section = "4.2.1", id = "421-A2")
3935
@Test
40-
public void testEnforce3LetterCode4ISO() {
36+
public void testEqualISOCurrencies() {
4137
for (Class type : TCKTestSetup.getTestConfiguration()
4238
.getCurrencyClasses()) {
4339
for (Currency currency : Currency.getAvailableCurrencies()) {
44-
CurrencyUnit unit = MonetaryCurrencies.getCurrency(
45-
currency.getCurrencyCode());
40+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(currency
41+
.getCurrencyCode());
4642
assertNotNull(unit);
47-
assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
43+
CurrencyUnit unit2 = MonetaryCurrencies.getCurrency(currency
44+
.getCurrencyCode());
45+
assertNotNull(unit2);
46+
assertEquals(unit, unit2);
4847
}
4948
}
5049
}
5150

52-
53-
@SpecAssertion(
54-
section = "4.2.1",
55-
id = "IsSerializable")
56-
@Test
57-
public void testImplementsSerializable() {
58-
for (Class type : TCKTestSetup.getTestConfiguration()
59-
.getCurrencyClasses()) {
60-
ClassTester.testSerializable(type);
61-
}
62-
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
63-
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
64-
ClassTester.testSerializable(unit);
65-
}
66-
}
67-
68-
@SpecAssertion(
69-
section = "4.2.1",
70-
id = "IsImmutable")
51+
@SpecAssertion(section = "4.2.1", id = "421-A3")
7152
@Test
72-
public void testIsImmutable() {
53+
public void testEnforce3LetterCode4ISO() {
7354
for (Class type : TCKTestSetup.getTestConfiguration()
7455
.getCurrencyClasses()) {
75-
ClassTester.testImmutable(type);
76-
}
77-
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
78-
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
79-
ClassTester.testImmutable(unit.getClass());
56+
for (Currency currency : Currency.getAvailableCurrencies()) {
57+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(currency
58+
.getCurrencyCode());
59+
assertNotNull(unit);
60+
assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
61+
}
8062
}
8163
}
8264

83-
@SpecAssertion(
84-
section = "4.2.1",
85-
id = "IsComparable")
65+
@SpecAssertion(section = "4.2.1", id = "421-A4")
8666
@Test
87-
public void testCurrencyClassesComparable() {
67+
public void testISOCodes() {
8868
for (Class type : TCKTestSetup.getTestConfiguration()
8969
.getCurrencyClasses()) {
90-
ClassTester.testComparable(type);
91-
}
92-
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
93-
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
94-
ClassTester.testComparable(unit.getClass());
70+
for (Currency currency : Currency.getAvailableCurrencies()) {
71+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(currency
72+
.getCurrencyCode());
73+
assertEquals(currency.getCurrencyCode(), unit.getCurrencyCode());
74+
assertEquals(currency.getDefaultFractionDigits(),
75+
unit.getDefaultFractionDigits());
76+
assertEquals(currency.getNumericCode(), unit.getNumericCode());
77+
}
9578
}
9679
}
9780

98-
@SpecAssertion(
99-
section = "4.2.1",
100-
id = "ImplementsHashCode")
81+
@SpecAssertion(section = "4.2.1", id = "421-B1")
10182
@Test
10283
public void testCurrencyClassesEqualsHashcode() {
10384
for (Class type : TCKTestSetup.getTestConfiguration()
@@ -111,9 +92,7 @@ public void testCurrencyClassesEqualsHashcode() {
11192
}
11293
}
11394

114-
@SpecAssertion(
115-
section = "4.2.1",
116-
id = "ImplementsEquals")
95+
@SpecAssertion(section = "4.2.1", id = "421-B2")
11796
@Test
11897
public void testImplementsEquals() {
11998
List<CurrencyUnit> firstUnits = new ArrayList<CurrencyUnit>();
@@ -122,8 +101,7 @@ public void testImplementsEquals() {
122101
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
123102
assertNotNull(unit);
124103
ClassTester.testHasPublicMethod(unit.getClass(), boolean.class,
125-
"equals",
126-
Object.class);
104+
"equals", Object.class);
127105
firstUnits.add(unit);
128106
CurrencyUnit unit2 = MonetaryCurrencies.getCurrency(code);
129107
assertNotNull(unit);
@@ -132,17 +110,40 @@ public void testImplementsEquals() {
132110
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
133111
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
134112
ClassTester.testHasPublicMethod(unit.getClass(), boolean.class,
135-
"equals",
136-
Object.class);
113+
"equals", Object.class);
137114
}
138115
for (int i = 0; i < firstUnits.size(); i++) {
139116
assertEquals(firstUnits.get(i), secondUnits.get(i));
140117
}
141118
}
142119

143-
@SpecAssertion(
144-
section = "4.2.1",
145-
id = "IsThreadSafe")
120+
@SpecAssertion(section = "4.2.1", id = "421-B3")
121+
@Test
122+
public void testCurrencyClassesComparable() {
123+
for (Class type : TCKTestSetup.getTestConfiguration()
124+
.getCurrencyClasses()) {
125+
ClassTester.testComparable(type);
126+
}
127+
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
128+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
129+
ClassTester.testComparable(unit.getClass());
130+
}
131+
}
132+
133+
@SpecAssertion(section = "4.2.1", id = "421-B4")
134+
@Test
135+
public void testIsImmutable() {
136+
for (Class type : TCKTestSetup.getTestConfiguration()
137+
.getCurrencyClasses()) {
138+
ClassTester.testImmutable(type);
139+
}
140+
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
141+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
142+
ClassTester.testImmutable(unit.getClass());
143+
}
144+
}
145+
146+
@SpecAssertion(section = "4.2.1", id = "421-B5")
146147
@Test
147148
public void testIsThreadSafe() throws NoSuchMethodException,
148149
SecurityException, IllegalAccessException,
@@ -154,4 +155,17 @@ public void testIsThreadSafe() throws NoSuchMethodException,
154155
}
155156
}
156157

158+
@SpecAssertion(section = "4.2.1", id = "421-B6")
159+
@Test
160+
public void testImplementsSerializable() {
161+
for (Class type : TCKTestSetup.getTestConfiguration()
162+
.getCurrencyClasses()) {
163+
ClassTester.testSerializable(type);
164+
}
165+
for (String code : new String[] { "CHF", "USD", "EUR", "GBP", "USS" }) {
166+
CurrencyUnit unit = MonetaryCurrencies.getCurrency(code);
167+
ClassTester.testSerializable(unit);
168+
}
169+
}
170+
157171
}

0 commit comments

Comments
 (0)