Skip to content

Commit d5066cc

Browse files
author
atsticks
committed
Enhanced TCK output, especially for System.out.
Added runner in test area for executing TCKRunner. Added additional test descriptions.
1 parent d94f3c5 commit d5066cc

File tree

6 files changed

+171
-157
lines changed

6 files changed

+171
-157
lines changed

src/main/java/org/javamoney/tck/TCKRunner.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void main(String... args){
6262
TestNG tng = new TestNG();
6363
tng.setXmlSuites(suites);
6464
tng.setOutputDirectory("./tck-results");
65-
tng.addListener(new VerboseReporter());
65+
// tng.addListener(new VerboseReporter());
6666
File file = new File(System.getProperty("java.io.tmpdir"), "tck-results.txt");
6767
TCKReporter rep = new TCKReporter(file);
6868
System.out.println("Writing to file " + file.getAbsolutePath() + " ...");
@@ -78,6 +78,7 @@ public static final class TCKReporter extends TestListenerAdapter{
7878
private int failed = 0;
7979
private int success = 0;
8080

81+
private StringWriter internalBuffer = new StringWriter(3000);
8182
private FileWriter w;
8283

8384
public TCKReporter(File file){
@@ -90,6 +91,12 @@ public TCKReporter(File file){
9091
w.write("**** JSR 354 - Money & Currency, Technical Compatibility Kit, version 1.0\n");
9192
w.write("*****************************************************************************************\n\n");
9293
w.write("Executed on " + new java.util.Date() +"\n\n" );
94+
95+
// System.out:
96+
internalBuffer.write("*****************************************************************************************\n");
97+
internalBuffer.write("**** JSR 354 - Money & Currency, Technical Compatibility Kit, version 1.0\n");
98+
internalBuffer.write("*****************************************************************************************\n\n");
99+
internalBuffer.write("Executed on " + new java.util.Date() + "\n\n");
93100
}
94101
catch(IOException e){
95102
e.printStackTrace();
@@ -173,9 +180,12 @@ public void onTestSuccess(ITestResult tr){
173180
}
174181
}
175182

176-
private void log(String string) throws IOException{
183+
private void log(String text) throws IOException {
177184
count++;
178-
w.write(string + '\n');
185+
w.write(text);
186+
w.write('\n');
187+
internalBuffer.write(text);
188+
internalBuffer.write('\n');
179189
}
180190

181191
public void writeSummary(){
@@ -188,6 +198,9 @@ public void writeSummary(){
188198
log("TOTAL TESTS FAILED : " + failed);
189199
w.flush();
190200
w.close();
201+
internalBuffer.flush();
202+
System.out.println();
203+
System.out.println(internalBuffer);
191204
}
192205
catch(IOException e){
193206
throw new IllegalStateException("IO Error", e);

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

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Created by Anatole on 10.03.14.
2828
*/
2929
@SpecVersion(spec = "JSR 354", version = "1.0.0")
30-
public class ExchangeRatesAndRateProvidersTest{
30+
public class ExchangeRatesAndRateProvidersTest {
3131

3232
// *************************** A. Test Basic MonetaryConversions Accessors *********************************
3333

@@ -37,13 +37,13 @@ public class ExchangeRatesAndRateProvidersTest{
3737
* Test access to conversion rates.<p>
3838
* Hint: this assertion will require multiple tests to be written!
3939
*/
40-
@Test
40+
@Test(description = "4.3.3 Test access of Conversion Rates, using TCK provided rate provider.")
4141
@SpecAssertion(id = "433-A1", section = "4.3.3")
42-
public void testAccessKnownRates(){
42+
public void testAccessKnownRates() {
4343
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("TestRateProvider");
4444
// Use test provider
45-
for(CurrencyUnit base : MonetaryCurrencies.getCurrencies()){
46-
if(base.equals(FOO_UNIT)){
45+
for (CurrencyUnit base : MonetaryCurrencies.getCurrencies()) {
46+
if (base.equals(FOO_UNIT)) {
4747
continue;
4848
}
4949
ExchangeRate rate = prov.getExchangeRate(base, FOO_UNIT);
@@ -63,17 +63,17 @@ public void testAccessKnownRates(){
6363
*/
6464
@Test(description = "4.3.3 Test access to exchange rates from TestRateProvider, using target currency code.")
6565
@SpecAssertion(id = "433-A1", section = "4.3.3")
66-
public void testAccessKnownRatesWithCodes(){
66+
public void testAccessKnownRatesWithCodes() {
6767
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("TestRateProvider");
6868
// Use test provider
69-
for(CurrencyUnit base : MonetaryCurrencies.getCurrencies()){
70-
if(base.equals(FOO_UNIT)){
69+
for (CurrencyUnit base : MonetaryCurrencies.getCurrencies()) {
70+
if (base.equals(FOO_UNIT)) {
7171
continue;
7272
}
7373
ExchangeRate rate = prov.getExchangeRate(base.getCurrencyCode(), "XXX");
7474
AssertJUnit
7575
.assertNotNull("Identity rate, accessed by getExchangeRate(String, String), is not defined for " +
76-
base.getCurrencyCode() + " -> " + FOO_UNIT.getCurrencyCode(), rate
76+
base.getCurrencyCode() + " -> " + FOO_UNIT.getCurrencyCode(), rate
7777
);
7878
AssertJUnit.assertEquals(rate.getBase().getCurrencyCode(), base.getCurrencyCode());
7979
AssertJUnit.assertEquals(rate.getTerm().getCurrencyCode(), "FOO");
@@ -87,11 +87,11 @@ public void testAccessKnownRatesWithCodes(){
8787
*/
8888
@Test(description = "4.3.3 Test access to exchange rates from TestRateProvider, using target CUrrencyUnit.")
8989
@SpecAssertion(id = "433-A1", section = "4.3.3")
90-
public void testAccessKnownRatesAndContext(){
90+
public void testAccessKnownRatesAndContext() {
9191
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("TestRateProvider");
9292
// Use test provider
93-
for(CurrencyUnit base : MonetaryCurrencies.getCurrencies()){
94-
if(base.equals(FOO_UNIT)){
93+
for (CurrencyUnit base : MonetaryCurrencies.getCurrencies()) {
94+
if (base.equals(FOO_UNIT)) {
9595
continue;
9696
}
9797
ExchangeRate rate = prov.getExchangeRate(base, FOO_UNIT);
@@ -112,15 +112,15 @@ public void testAccessKnownRatesAndContext(){
112112
*/
113113
@Test(description = "4.3.3 Test access to conversion rates, including known factor, using TestRateProvider.")
114114
@SpecAssertion(id = "433-A1", section = "4.3.3")
115-
public void testAccessKnownRatesWithCodesAndContext(){
115+
public void testAccessKnownRatesWithCodesAndContext() {
116116
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("TestRateProvider");
117117
// Use test provider
118-
for(CurrencyUnit base : MonetaryCurrencies.getCurrencies()){
118+
for (CurrencyUnit base : MonetaryCurrencies.getCurrencies()) {
119119
ExchangeRate rate = prov.getExchangeRate(base, FOO_UNIT);
120120
AssertJUnit
121121
.assertNotNull("Identity rate, accessed by getExchangeRate(String, String, ConversionContext), " +
122-
"is not defined for " +
123-
base.getCurrencyCode() + " -> " + FOO_UNIT.getCurrencyCode(), rate
122+
"is not defined for " +
123+
base.getCurrencyCode() + " -> " + FOO_UNIT.getCurrencyCode(), rate
124124
);
125125
AssertJUnit.assertEquals(rate.getBase().getCurrencyCode(), base.getCurrencyCode());
126126
AssertJUnit.assertEquals(rate.getTerm().getCurrencyCode(), FOO_UNIT.getCurrencyCode());
@@ -134,9 +134,9 @@ public void testAccessKnownRatesWithCodesAndContext(){
134134
*/
135135
@Test(description = "4.3.3 Test access to identity conversion rate for CurrencyUnits, using default provider")
136136
@SpecAssertion(id = "433-A1", section = "4.3.3")
137-
public void testAccessRates_IdentityRatesWithUnits(){
137+
public void testAccessRates_IdentityRatesWithUnits() {
138138
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(); // Use default provider
139-
for(CurrencyUnit unit : MonetaryCurrencies.getCurrencies()){
139+
for (CurrencyUnit unit : MonetaryCurrencies.getCurrencies()) {
140140
ExchangeRate rate = prov.getExchangeRate(unit, unit);
141141
AssertJUnit.assertNotNull(
142142
"Identity rate, accessed by getExchangeRate(CurrencyUnit, CurrencyUnit), is not defined for " +
@@ -151,9 +151,9 @@ public void testAccessRates_IdentityRatesWithUnits(){
151151
*/
152152
@Test(description = "4.3.3 Test access to conversion rate for currency codes, using default provider.")
153153
@SpecAssertion(id = "433-A1", section = "4.3.3")
154-
public void testAccessRates_IdentityRatesWithCodes(){
154+
public void testAccessRates_IdentityRatesWithCodes() {
155155
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(); // Use default provider
156-
for(CurrencyUnit unit : MonetaryCurrencies.getCurrencies()){
156+
for (CurrencyUnit unit : MonetaryCurrencies.getCurrencies()) {
157157
ExchangeRate rate = prov.getExchangeRate(unit.getCurrencyCode(), unit.getCurrencyCode());
158158
AssertJUnit.assertNotNull(
159159
"Identity rate, accessed by getExchangeRate(String, String), is not defined for " +
@@ -168,9 +168,9 @@ public void testAccessRates_IdentityRatesWithCodes(){
168168
*/
169169
@Test(description = "4.3.3 Test access to conversion rate for CurrencyQuery, using default provider.")
170170
@SpecAssertion(id = "433-A1", section = "4.3.3")
171-
public void testAccessRates_IdentityRatesWithUnitsAndContext(){
171+
public void testAccessRates_IdentityRatesWithUnitsAndContext() {
172172
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(); // Use default provider
173-
for(CurrencyUnit unit : MonetaryCurrencies.getCurrencies()){
173+
for (CurrencyUnit unit : MonetaryCurrencies.getCurrencies()) {
174174
ExchangeRate rate = prov.getExchangeRate(ConversionQueryBuilder.create().setBaseCurrency(unit).setTermCurrency(unit).build());
175175
AssertJUnit.assertNotNull(
176176
"Identity rate, accessed by getExchangeRate(ConversionQuery), " +
@@ -186,7 +186,7 @@ public void testAccessRates_IdentityRatesWithUnitsAndContext(){
186186
*/
187187
@Test(description = "4.3.3 Ensure additional ConversionQuery data is passed correctly to SPIs.")
188188
@SpecAssertion(id = "433-A2", section = "4.3.3")
189-
public void testPassingOverConversionContextToSPIs(){
189+
public void testPassingOverConversionContextToSPIs() {
190190
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider("TestRateProvider");
191191
ConversionQuery ctx =
192192
ConversionQueryBuilder.create().set(Locale.CANADA).set("Foo", "bar").setBaseCurrency(FOO_UNIT)
@@ -211,21 +211,20 @@ public void testPassingOverConversionContextToSPIs(){
211211
*/
212212
@Test(description = "4.3.3 Bad case: try accessing exchange rates with invalid base currency code.")
213213
@SpecAssertion(id = "433-A3", section = "4.3.3")
214-
public void testInvalidUsage_InvalidSourceCurrency(){
215-
for(String providerID : MonetaryConversions.getProviderNames()){
216-
if("TestRateProvider".equals(providerID)){
214+
public void testInvalidUsage_InvalidSourceCurrency() {
215+
for (String providerID : MonetaryConversions.getProviderNames()) {
216+
if ("TestRateProvider".equals(providerID)) {
217217
continue;
218218
}
219219
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
220-
try{
220+
try {
221221
prov.getExchangeRate("dhdjbdjd", "CHF");
222222
Assert.fail(
223223
"ExchangeRateProvider should throw UnknownCurrencyException when an invalid source currency " +
224224
"is passed to getExchangeRate(String,String), provider: " +
225225
providerID
226226
);
227-
}
228-
catch(UnknownCurrencyException e){
227+
} catch (UnknownCurrencyException e) {
229228
// OK
230229
}
231230
}
@@ -237,20 +236,19 @@ public void testInvalidUsage_InvalidSourceCurrency(){
237236
*/
238237
@Test(description = "4.3.3 Bad case: try accessing exchange rates with null base currency code.")
239238
@SpecAssertion(id = "433-A3", section = "4.3.3")
240-
public void testInvalidUsage_NullSourceCurrency(){
241-
for(String providerID : MonetaryConversions.getProviderNames()){
242-
if("TestRateProvider".equals(providerID)){
239+
public void testInvalidUsage_NullSourceCurrency() {
240+
for (String providerID : MonetaryConversions.getProviderNames()) {
241+
if ("TestRateProvider".equals(providerID)) {
243242
continue;
244243
}
245244
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
246-
try{
245+
try {
247246
prov.getExchangeRate(null, "CHF");
248247
Assert.fail("ExchangeRateProvider should throw NullPointerException when an null source currency " +
249-
"is passed to getExchangeRate(String,String), provider: " +
250-
providerID
248+
"is passed to getExchangeRate(String,String), provider: " +
249+
providerID
251250
);
252-
}
253-
catch(NullPointerException e){
251+
} catch (NullPointerException e) {
254252
// OK
255253
}
256254
}
@@ -262,21 +260,20 @@ public void testInvalidUsage_NullSourceCurrency(){
262260
*/
263261
@Test(description = "4.3.3 Bad case: try accessing exchange rates with invalid term currency code.")
264262
@SpecAssertion(id = "433-A3", section = "4.3.3")
265-
public void testInvalidUsage_InvalidTargetCurrency(){
266-
for(String providerID : MonetaryConversions.getProviderNames()){
267-
if("TestRateProvider".equals(providerID)){
263+
public void testInvalidUsage_InvalidTargetCurrency() {
264+
for (String providerID : MonetaryConversions.getProviderNames()) {
265+
if ("TestRateProvider".equals(providerID)) {
268266
continue;
269267
}
270268
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
271-
try{
269+
try {
272270
prov.getExchangeRate("CHF", "dhdjbdjd");
273271
Assert.fail(
274272
"ExchangeRateProvider should throw UnknownCurrencyException when an invalid target currency " +
275273
"is passed to getExchangeRate(String,String), provider: " +
276274
providerID
277275
);
278-
}
279-
catch(UnknownCurrencyException e){
276+
} catch (UnknownCurrencyException e) {
280277
// OK
281278
}
282279
}
@@ -288,20 +285,19 @@ public void testInvalidUsage_InvalidTargetCurrency(){
288285
*/
289286
@Test(description = "4.3.3 Bad case: try accessing exchange rates with null term currency code.")
290287
@SpecAssertion(id = "433-A3", section = "4.3.3")
291-
public void testInvalidUsage_NullTargetCurrency(){
292-
for(String providerID : MonetaryConversions.getProviderNames()){
293-
if("TestRateProvider".equals(providerID)){
288+
public void testInvalidUsage_NullTargetCurrency() {
289+
for (String providerID : MonetaryConversions.getProviderNames()) {
290+
if ("TestRateProvider".equals(providerID)) {
294291
continue;
295292
}
296293
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
297-
try{
294+
try {
298295
prov.getExchangeRate("CHF", null);
299296
Assert.fail("ExchangeRateProvider should throw NullPointerException when an null target currency " +
300-
"is passed to getExchangeRate(String,String), provider: " +
301-
providerID
297+
"is passed to getExchangeRate(String,String), provider: " +
298+
providerID
302299
);
303-
}
304-
catch(NullPointerException e){
300+
} catch (NullPointerException e) {
305301
// OK
306302
}
307303
}
@@ -313,14 +309,14 @@ public void testInvalidUsage_NullTargetCurrency(){
313309
*/
314310
@Test(description = "4.3.3 Bad case: try accessing exchange rates with null ConversionQuery.")
315311
@SpecAssertion(id = "433-A3", section = "4.3.3")
316-
public void testInvalidUsage_InvalidSourceCurrencyAndContext(){
317-
for(String providerID : MonetaryConversions.getProviderNames()){
318-
if("TestRateProvider".equals(providerID)){
312+
public void testInvalidUsage_InvalidSourceCurrencyAndContext() {
313+
for (String providerID : MonetaryConversions.getProviderNames()) {
314+
if ("TestRateProvider".equals(providerID)) {
319315
continue;
320316
}
321317
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
322-
try{
323-
prov.getExchangeRate((ConversionQuery)null);
318+
try {
319+
prov.getExchangeRate((ConversionQuery) null);
324320
Assert.fail(
325321
"ExchangeRateProvider should throw NPE when an null ConversionQuery " +
326322
"is passed to getExchangeRate(ConversionQuery), provider: " +
@@ -339,17 +335,16 @@ public void testInvalidUsage_InvalidSourceCurrencyAndContext(){
339335
*/
340336
@Test(description = "4.3.3 Bad case: try accessing exchange rates with null base CurrencyUnit.")
341337
@SpecAssertion(id = "433-A3", section = "4.3.3")
342-
public void testInvalidUsage_NullSourceCurrencyUnit(){
343-
for(String providerID : MonetaryConversions.getProviderNames()){
338+
public void testInvalidUsage_NullSourceCurrencyUnit() {
339+
for (String providerID : MonetaryConversions.getProviderNames()) {
344340
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
345-
try{
341+
try {
346342
prov.getExchangeRate(null, MonetaryCurrencies.getCurrency("CHF"));
347343
Assert.fail("ExchangeRateProvider should throw NullPointerException when an null source currency " +
348-
"is passed to getExchangeRate(CurrencyUnit,CurrencyUnit), provider: " +
349-
providerID
344+
"is passed to getExchangeRate(CurrencyUnit,CurrencyUnit), provider: " +
345+
providerID
350346
);
351-
}
352-
catch(NullPointerException e){
347+
} catch (NullPointerException e) {
353348
// OK
354349
}
355350
}
@@ -361,18 +356,17 @@ public void testInvalidUsage_NullSourceCurrencyUnit(){
361356
*/
362357
@Test(description = "4.3.3 Bad case: try accessing exchange rates with null term CurrencyUnit.")
363358
@SpecAssertion(id = "433-A3", section = "4.3.3")
364-
public void testInvalidUsage_NullTargetCurrencyUnit(){
365-
for(String providerID : MonetaryConversions.getProviderNames()){
359+
public void testInvalidUsage_NullTargetCurrencyUnit() {
360+
for (String providerID : MonetaryConversions.getProviderNames()) {
366361
ExchangeRateProvider prov = MonetaryConversions.getExchangeRateProvider(providerID);
367-
try{
362+
try {
368363
prov.getExchangeRate(MonetaryCurrencies.getCurrency("CHF"), null);
369364
Assert.fail(
370365
"ExchangeRateProvider should throw NullPointerException when an invalid target currency " +
371366
"is passed to getExchangeRate(CurrencyUnit,CurrencyUnit), provider: " +
372367
providerID
373368
);
374-
}
375-
catch(NullPointerException e){
369+
} catch (NullPointerException e) {
376370
// OK
377371
}
378372
}

0 commit comments

Comments
 (0)