Skip to content

Commit 2d7e9dc

Browse files
committed
Added additional TCK test skeleton implementations for API coverage.
1 parent 33895b6 commit 2d7e9dc

File tree

5 files changed

+188
-81
lines changed

5 files changed

+188
-81
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,12 @@ public int getNumericCode() {
248248
public int getDefaultFractionDigits() {
249249
return currency.getDefaultFractionDigits();
250250
}
251-
};
251+
252+
@Override
253+
public int compareTo(CurrencyUnit o){
254+
return 0;
255+
}
256+
};
252257
}
253258

254259
@Override
@@ -305,6 +310,11 @@ public MonetaryAmount add(MonetaryAmount amount) {
305310
public MonetaryAmount abs() {
306311
return this;
307312
}
308-
};
313+
314+
@Override
315+
public int compareTo(MonetaryAmount o){
316+
return 0;
317+
}
318+
};
309319
}
310320
}

src/test/java/org/javamoney/tck/tests/conversion/ConvertingAmountsTest.java

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,82 @@
1111

1212
package org.javamoney.tck.tests.conversion;
1313

14+
import org.jboss.test.audit.annotations.SpecAssertion;
1415
import org.jboss.test.audit.annotations.SpecVersion;
1516
import org.junit.Assert;
1617
import org.junit.Test;
1718

19+
import javax.money.CurrencyUnit;
20+
import javax.money.convert.ConversionContext;
21+
import javax.money.convert.CurrencyConversionException;
22+
import javax.money.convert.MonetaryConversions;
23+
1824
/**
1925
* Test for converting amounts.
2026
* Created by Anatole on 10.03.14.
2127
*/
2228
@SpecVersion(spec = "JSR 354", version = "1.0.0")
2329
public class ConvertingAmountsTest{
2430

25-
@Test
26-
public void placeholder(){
31+
// ******************************* A. Test Basic MonetaryConversions Accessors ******************************
32+
33+
/**
34+
* Test successful conversion for possible currency pairs.<br/>
35+
* Hint: you may only check for rate factory, when using a hardcoded ExchangeRateProvider, such a provider
36+
* must be also implemented and registered as an SPI.
37+
*/
38+
@Test @SpecAssertion(id = "432-A1", section="4.3.2")
39+
public void testConversion(){
40+
Assert.fail();
41+
}
42+
43+
/**
44+
* Compare conversions done with exchange rates provided for same currency pair.
45+
*/
46+
@Test @SpecAssertion(id = "432-A2", section="4.3.2")
47+
public void testConversionComparedWithRate(){
2748
Assert.fail();
2849
}
2950

30-
/*
31-
<group>
32-
<text>A. Test Basic MonetaryConversions Accessors
33-
</text>
34-
<assertion id="432-A1">
35-
<text>Test successful conversion for possible currency pairs.</text>
36-
</assertion>
37-
<assertion id="432-A2">
38-
<text>Compare conversions done with exchange rates provided for same conversion.</text>
39-
</assertion>
40-
<assertion id="432-A3">
41-
<text>Bad case: try converting from/to an inconvertible (custom) currency, ensure CurrencyConversionException is thrown.</text>
42-
</assertion>
43-
<assertion id="432-A4">
44-
<text>Bad case: try converting from/to a null currency, ensure CurrencyConversionException is thrown.</text>
45-
</assertion>
46-
</group>
51+
/**
52+
* Bad case: try converting from/to an inconvertible (custom) currency, ensure CurrencyConversionException is thrown.
53+
* @see org.javamoney.moneta.BuildableCurrencyUnit for creating a custom currency, with some fancy non-ISO currency code.
4754
*/
55+
@Test(expected=CurrencyConversionException.class) @SpecAssertion(id = "432-A3", section="4.3.2")
56+
public void testUnsupportedConversion(){
57+
Assert.fail();
58+
}
59+
60+
/**
61+
* Bad case: try converting from/to a null currency, ensure NullPointerException is thrown.
62+
*/
63+
@Test(expected=NullPointerException.class) @SpecAssertion(id = "432-A4", section="4.3.2")
64+
public void testNullConversion1(){
65+
MonetaryConversions.getConversion((CurrencyUnit)null);
66+
}
67+
68+
/**
69+
* Bad case: try converting from/to a null currency, ensure NullPointerException is thrown.
70+
*/
71+
@Test(expected=NullPointerException.class) @SpecAssertion(id = "432-A4", section="4.3.2")
72+
public void testNullConversion2(){
73+
MonetaryConversions.getConversion((String)null);
74+
}
75+
76+
/**
77+
* Bad case: try converting from/to a null currency, ensure NullPointerException is thrown.
78+
*/
79+
@Test(expected=NullPointerException.class) @SpecAssertion(id = "432-A4", section="4.3.2")
80+
public void testNullConversion3(){
81+
MonetaryConversions.getConversion((CurrencyUnit) null, ConversionContext.of());
82+
}
83+
84+
/**
85+
* Bad case: try converting from/to a null currency, ensure NullPointerException is thrown.
86+
*/
87+
@Test(expected=NullPointerException.class) @SpecAssertion(id = "432-A4", section="4.3.2")
88+
public void testNullConversion4(){
89+
MonetaryConversions.getConversion((String)null, ConversionContext.of());
90+
}
91+
4892
}

src/test/java/org/javamoney/tck/tests/conversion/ExchangeRatesAndRateProvidersTest.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.javamoney.tck.tests.conversion;
1313

14+
import org.jboss.test.audit.annotations.SpecAssertion;
1415
import org.jboss.test.audit.annotations.SpecVersion;
1516
import org.junit.Assert;
1617
import org.junit.Test;
@@ -22,25 +23,33 @@
2223
@SpecVersion(spec = "JSR 354", version = "1.0.0")
2324
public class ExchangeRatesAndRateProvidersTest{
2425

25-
@Test
26-
public void placeholder(){
26+
// *************************** A. Test Basic MonetaryConversions Accessors *********************************
27+
28+
/**
29+
* Test access to conversion rates.<br/>
30+
* Hint: this assertion will require multiple tests to be written!
31+
*/
32+
@Test @SpecAssertion(id="433-A1", section="4.3.3")
33+
public void testAccessRates(){
34+
Assert.fail();
35+
}
36+
37+
/**
38+
* Ensure additional ConversionContext is passed correctly to SPIs.<br/>
39+
* Hint: this assertion will require some custom SPIs to be registered and selected for chain inclusion!
40+
*/
41+
@Test @SpecAssertion(id="433-A2", section="4.3.3")
42+
public void testPassingOverConversionContextToSPIs(){
2743
Assert.fail();
2844
}
2945

30-
/*
31-
<group>
32-
<text>A. Test Basic MonetaryConversions Accessors
33-
</text>
34-
<assertion id="433-A1">
35-
<text>Test access to conversion rates.</text>
36-
</assertion>
37-
<assertion id="433-A2">
38-
<text>Ensure additional ConversionContext is passed correctly to SPIs.</text>
39-
</assertion>
40-
<assertion id="433-A3">
41-
<text>Bad case: try accessing rates with incosistent data.</text>
42-
</assertion>
43-
</group>
46+
/**
47+
* Bad case: try accessing rates with incosistent/invalid data.<br/>
48+
* Hint: this assertion will require multiple tests to be written!
4449
*/
50+
@Test @SpecAssertion(id="433-A3", section="4.3.3")
51+
public void testInvalidUsage(){
52+
Assert.fail();
53+
}
4554

4655
}

src/test/java/org/javamoney/tck/tests/conversion/MonetaryConversionsTest.java

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,81 @@
1111

1212
package org.javamoney.tck.tests.conversion;
1313

14+
import org.jboss.test.audit.annotations.SpecAssertion;
1415
import org.jboss.test.audit.annotations.SpecVersion;
1516
import org.junit.Assert;
1617
import org.junit.Test;
1718

19+
import javax.money.MonetaryException;
20+
1821
/**
1922
* Created by Anatole on 10.03.14.
2023
*/
2124
@SpecVersion(spec = "JSR 354", version = "1.0.0")
2225
public class MonetaryConversionsTest{
2326

24-
@Test
25-
public void placeholder(){
27+
// ************************************* A. Test Basic MonetaryConversions Accessors *****************************
28+
29+
/**
30+
* Ensure at least one conversion provider is available.<br/>
31+
* Hint: ignore all TCK test providers, only count up productive providers.
32+
*/
33+
@Test @SpecAssertion(id="431-A1", section="4.3.1")
34+
public void testProvidersAvailable(){
35+
Assert.fail();
36+
}
37+
38+
/**
39+
* Access and test different Currency Conversions for the provider in place.<br/>
40+
* Test TCK providers, but also test implementation providers. Doing the ladder it
41+
* is not possible to test the rates quality, just that rates are returned if necessary.
42+
*/
43+
@Test @SpecAssertion(id="431-A2", section="4.3.1")
44+
public void testConversionsAreAvailable(){
45+
Assert.fail();
46+
}
47+
48+
/**
49+
* Test if all providers returns valid meta data.
50+
* @see javax.money.convert.ProviderContext
51+
*/
52+
@Test @SpecAssertion(id="431-A3", section="4.3.1")
53+
public void testProviderMetadata(){
54+
Assert.fail();
55+
}
56+
57+
/**
58+
* Access the default provider chain. Compare with entries from javamoney.properties. The chain must not be empty!
59+
*/
60+
@Test @SpecAssertion(id="431-A4", section="4.3.1")
61+
public void testDefaultProviderChainIsDefined(){
2662
Assert.fail();
2763
}
28-
/*
29-
<group>
30-
<text>A. Test Basic MonetaryConversions Accessors
31-
</text>
32-
<assertion id="431-A1">
33-
<text>Ensure at least one conversion provider is accessible.</text>
34-
</assertion>
35-
<assertion id="431-A2">
36-
<text>Access and test different Currency Conversions for the provider in place.</text>
37-
</assertion>
38-
<assertion id="431-A3">
39-
<text>Access and test the provider's meta data.</text>
40-
</assertion>
41-
<assertion id="431-A4">
42-
<text>Access the default provider chain (must be defined).</text>
43-
</assertion>
44-
<assertion id="431-A5">
45-
<text>Access and test conversion using the default provider chain.</text>
46-
</assertion>
47-
<assertion id="431-A6">
48-
<text>Bad case: Test access of an inexistent provider.</text>
49-
</assertion>
50-
<assertion id="431-A7">
51-
<text>Bad case: Test inclusion of an inexistent provider in a provider chain.</text>
52-
</assertion>
53-
</group>
64+
65+
/**
66+
* Access and test conversion using the default provider chain.<br/>
67+
* Hint the exact rate factors returned cannot be tested, just rates that make sense must be returned.
68+
*/
69+
@Test @SpecAssertion(id="431-A5", section="4.3.1")
70+
public void testDefaultProviderChain(){
71+
Assert.fail();
72+
}
73+
74+
/**
75+
* Bad case: Test access of an inexistent provider. Should throw a MonetaryException
5476
*/
77+
@Test(expected=MonetaryException.class) @SpecAssertion(id="431-A6", section="4.3.1")
78+
public void testUseInvalidProvider(){
79+
Assert.fail();
80+
}
81+
82+
/**
83+
* Bad case: Test access of an inexistent provider within a chain of providers (all other providers must be valid).
84+
* Should throw a MonetaryException
85+
*/
86+
@Test(expected=MonetaryException.class) @SpecAssertion(id="431-A7", section="4.3.1")
87+
public void testUseInvalidProviderWithinChain(){
88+
Assert.fail();
89+
}
5590

5691
}

src/test/java/org/javamoney/tck/tests/conversion/ProviderChainsTest.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.javamoney.tck.tests.conversion;
1313

14+
import org.jboss.test.audit.annotations.SpecAssertion;
1415
import org.jboss.test.audit.annotations.SpecVersion;
1516
import org.junit.Assert;
1617
import org.junit.Test;
@@ -22,25 +23,33 @@
2223
@SpecVersion(spec = "JSR 354", version = "1.0.0")
2324
public class ProviderChainsTest{
2425

25-
@Test
26-
public void placeholder(){
26+
// ********************** A. Test Basic MonetaryConversions Accessors *********************************
27+
28+
/**
29+
* Test correct rate evaluation for different provider chains, providers defined by the TCK.<br/>
30+
* Hint do not use non TCK provider for this test, it will make results undeterministic.
31+
*/
32+
@Test @SpecAssertion(id="434-A1", section="4.3.4")
33+
public void testCorrectRateEvaluationInChain(){
34+
Assert.fail();
35+
}
36+
37+
/**
38+
* Test correct rate evaluation for different provider chains, providers defined by the TCK, with historic rates.<br/>
39+
* Hint do not use non TCK provider for this test, it will make results undeterministic.
40+
*/
41+
@Test @SpecAssertion(id="434-A2", section="4.3.4")
42+
public void testCorrectRateEvaluationInChainHistoric(){
2743
Assert.fail();
2844
}
2945

30-
/*
31-
<group>
32-
<text>A. Test Basic MonetaryConversions Accessors
33-
</text>
34-
<assertion id="434-A1">
35-
<text>Test correct rate evaluation for different provider chains, providers defined by the TCK.</text>
36-
</assertion>
37-
<assertion id="434-A2">
38-
<text>Test correct rate evaluation for different provider chains, providers defined by the TCK, with historic rates.</text>
39-
</assertion>
40-
<assertion id="434-A3">
41-
<text>Test availability of providers defined by the TCK.</text>
42-
</assertion>
43-
</group>
46+
/**
47+
* Test availability of providers defined by the TCK.<br/>
48+
* Hint do not use non TCK provider for this test, it will make results undeterministic.
4449
*/
50+
@Test @SpecAssertion(id="434-A3", section="4.3.4")
51+
public void testTCKRateChainAvailability(){
52+
Assert.fail();
53+
}
4554

4655
}

0 commit comments

Comments
 (0)