Skip to content

Commit 861d3bc

Browse files
committed
Merge pull request #4 from simkuenzi/master
Tests for MonetaryAmountFormat - Hacker Garten
2 parents 57daea9 + cb12d7b commit 861d3bc

File tree

3 files changed

+416
-0
lines changed

3 files changed

+416
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.javamoney.tck.tests;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import java.text.DecimalFormat;
8+
import java.util.Locale;
9+
import java.util.Set;
10+
11+
import javax.money.format.AmountStyle;
12+
import javax.money.format.MonetaryAmountFormat;
13+
import javax.money.format.MonetaryFormats;
14+
15+
import org.jboss.test.audit.annotations.SpecAssertion;
16+
import org.jboss.test.audit.annotations.SpecVersion;
17+
import org.junit.Test;
18+
19+
@SpecVersion(spec = "JSR 354", version = "1.0.0")
20+
public class AccessingMonetaryAmountFormatTest {
21+
22+
@SpecAssertion(section = "4.4.1", id = "441-B1")
23+
@Test
24+
public void testLocalesSupported() {
25+
Locale[] jdkDecimalFormatLocales = DecimalFormat.getAvailableLocales();
26+
for (Locale jdkDecimalFormatLocale : jdkDecimalFormatLocales) {
27+
MonetaryAmountFormat amountFormat = MonetaryFormats
28+
.getAmountFormat(jdkDecimalFormatLocale);
29+
assertNotNull(amountFormat);
30+
assertEquals(jdkDecimalFormatLocale, amountFormat.getAmountStyle()
31+
.getLocale());
32+
}
33+
}
34+
35+
@Test
36+
@SpecAssertion(section = "4.4.1", id = "441-B2")
37+
public void testGetAmountFormat() {
38+
for (Locale locale : DecimalFormat.getAvailableLocales()) {
39+
assertNotNull(MonetaryFormats.getAmountFormat(AmountStyle
40+
.of(locale)));
41+
}
42+
}
43+
44+
@Test
45+
@SpecAssertion(section = "4.4.1", id = "441-B3")
46+
public void testGetAvailableLocales() {
47+
Set<Locale> locales = MonetaryFormats.getAvailableLocales();
48+
for (Locale locale : DecimalFormat.getAvailableLocales()) {
49+
assertTrue(locales.contains(locale));
50+
}
51+
}
52+
53+
@Test
54+
@SpecAssertion(section = "4.4.1", id = "441-B3")
55+
public void testAmountStyleOf() {
56+
for (Locale locale : DecimalFormat.getAvailableLocales()) {
57+
assertNotNull(AmountStyle.of(locale));
58+
}
59+
}
60+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.javamoney.tck.tests;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
6+
import java.util.Currency;
7+
import java.util.Locale;
8+
9+
import javax.money.MonetaryAmount;
10+
import javax.money.MonetaryAmounts;
11+
import javax.money.format.MonetaryAmountFormat;
12+
import javax.money.format.MonetaryFormats;
13+
14+
import org.jboss.test.audit.annotations.SpecAssertion;
15+
import org.jboss.test.audit.annotations.SpecVersion;
16+
import org.junit.Test;
17+
18+
@SpecVersion(spec = "JSR 354", version = "1.0.0")
19+
public class MonetaryAmountFormatTest {
20+
21+
@SpecAssertion(section = "4.4.1", id = "441-A1")
22+
@Test
23+
public void testNoDepOnAmountImplementation() {
24+
final Locale defaultLocale = Locale.getDefault();
25+
MonetaryAmountFormat amountFormat = MonetaryFormats
26+
.getAmountFormat(defaultLocale);
27+
final Number[] values = new Number[] { 100, 10000000000000L };// TODO
28+
// other
29+
// values
30+
// and
31+
// currencies
32+
final Currency currency = Currency.getAvailableCurrencies().iterator()
33+
.next();
34+
for (Number value : values) {
35+
MonetaryAmount amount = MonetaryAmounts.getAmountFactory()
36+
.setCurrency(currency.getCurrencyCode()).setNumber(value)
37+
.create();
38+
String formattedAmount = amountFormat.format(amount);
39+
MonetaryAmount amountMock = TestMonetaryAmountFactory.getAmount(
40+
value, currency);
41+
String formattedAmountMock = amountFormat.format(amountMock);
42+
assertNotNull(formattedAmountMock);
43+
assertEquals(formattedAmountMock, formattedAmount);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)