@@ -16,6 +16,8 @@ public class ModellingMonetaryAmountsTest{
1616
1717 private final static String DEFAULT_CURRENCY = "CHF" ;
1818
19+ private final static String ADDITIONAL_CURRENCY = "USD" ;
20+
1921 /**
2022 * Ensure at least one javax.money.MonetaryAmount implementation is registered,
2123 * by calling MonetaryAmounts.getAmountTypes();
@@ -324,7 +326,14 @@ public void testAddMixedFractions(){
324326 @ SpecAssertion (section = "4.2.2" , id = "422-D2" )
325327 @ Test (expected = MonetaryException .class )
326328 public void testAdd_IncompatibleCurrencies (){
327- fail ("Not yet implemented" );
329+ for (Class type : MonetaryAmounts .getAmountTypes ()){
330+ MonetaryAmount mAmount1 =
331+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
332+ MonetaryAmount mAmount2 =
333+ MonetaryAmounts .getAmountFactory (type ).setCurrency (ADDITIONAL_CURRENCY ).setNumber (20 ).create ();
334+ MonetaryAmount mActualResult = mAmount1 .add (mAmount2 );
335+ fail ("Exception expected" );
336+ }
328337 }
329338
330339 /**
@@ -333,7 +342,14 @@ public void testAdd_IncompatibleCurrencies(){
333342 @ SpecAssertion (section = "4.2.2" , id = "422-D3" )
334343 @ Test
335344 public void testAdd_Zero (){
336- fail ("Not yet implemented" );
345+ for (Class type : MonetaryAmounts .getAmountTypes ()){
346+ MonetaryAmount mAmount1 =
347+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
348+ MonetaryAmount mAmount2 =
349+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (0 ).create ();
350+ MonetaryAmount mActualResult = mAmount1 .add (mAmount2 );
351+ Assert .assertEquals ("Adding zero" , mAmount1 , mActualResult );
352+ }
337353 }
338354
339355 /**
@@ -353,7 +369,12 @@ public void testAdd_ExceedsCapabilities(){
353369 @ SpecAssertion (section = "4.2.2" , id = "422-D5" )
354370 @ Test (expected = NullPointerException .class )
355371 public void testAdd_Null (){
356- fail ("Not yet implemented" );
372+ for (Class type : MonetaryAmounts .getAmountTypes ()){
373+ MonetaryAmount mAmount1 =
374+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
375+ MonetaryAmount mActualResult = mAmount1 .add (null );
376+ fail ("Exception expected" );
377+ }
357378 }
358379
359380
@@ -423,25 +444,6 @@ public void testSubtractMixedIntegers(){
423444 fail ();
424445 }
425446
426-
427-
428-
429-
430-
431-
432-
433-
434-
435-
436-
437-
438-
439-
440-
441-
442-
443-
444-
445447 /**
446448 * Tests that subtract() correctly adds two values, using positive and negative fractions.
447449 */
@@ -458,7 +460,14 @@ public void testSubtractMixedFractions(){
458460 @ SpecAssertion (section = "4.2.2" , id = "422-D8" )
459461 @ Test (expected = MonetaryException .class )
460462 public void testSubtract_IncompatibleCurrencies (){
461- fail ("Not yet implemented" );
463+ for (Class type : MonetaryAmounts .getAmountTypes ()){
464+ MonetaryAmount mAmount1 =
465+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
466+ MonetaryAmount mAmount2 =
467+ MonetaryAmounts .getAmountFactory (type ).setCurrency (ADDITIONAL_CURRENCY ).setNumber (20 ).create ();
468+ MonetaryAmount mActualResult = mAmount1 .subtract (mAmount2 );
469+ fail ("Exception expected" );
470+ }
462471 }
463472
464473 /**
@@ -467,7 +476,14 @@ public void testSubtract_IncompatibleCurrencies(){
467476 @ SpecAssertion (section = "4.2.2" , id = "422-D7" )
468477 @ Test
469478 public void testSubtract_Zero (){
470- fail ("Not yet implemented" );
479+ for (Class type : MonetaryAmounts .getAmountTypes ()){
480+ MonetaryAmount mAmount1 =
481+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
482+ MonetaryAmount mAmount2 =
483+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (0 ).create ();
484+ MonetaryAmount mActualResult = mAmount1 .subtract (mAmount2 );
485+ Assert .assertEquals ("Subtract zero" , mAmount1 , mActualResult );
486+ }
471487 }
472488
473489 /**
@@ -487,7 +503,12 @@ public void testSubtract_ExceedsCapabilities(){
487503 @ SpecAssertion (section = "4.2.2" , id = "422-D10" )
488504 @ Test (expected = NullPointerException .class )
489505 public void testSubtract_Null (){
490- fail ("Not yet implemented" );
506+ for (Class type : MonetaryAmounts .getAmountTypes ()){
507+ MonetaryAmount mAmount1 =
508+ MonetaryAmounts .getAmountFactory (type ).setCurrency (DEFAULT_CURRENCY ).setNumber (10 ).create ();
509+ MonetaryAmount mActualResult = mAmount1 .subtract (null );
510+ fail ("Exception expected" );
511+ }
491512 }
492513
493514
0 commit comments