Skip to content

Commit d4419fe

Browse files
committed
Minor changes.
2 parents a6bfb09 + 1201f34 commit d4419fe

File tree

10 files changed

+569
-215
lines changed

10 files changed

+569
-215
lines changed

LICENCE.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
JSR 354: Money and Currency Reference Implementation
2-
=========
2+
====================================================
33
JSR 354 provides an API for representing, transporting, and performing comprehensive calculations with Money and Currency.
4-
See the home page for more details:
5-
http://jcp.org/en/jsr/detail?name=354
4+
This module implements JSR 354 Money & Currency. Hereby basic implementations of amounts, currency and roundings are provided.
5+
6+
See the JCP detail page:
7+
http://jcp.org/en/jsr/detail?id=354
68

79
Or the GitHub page:
810
http://javamoney.github.io/ri.html
911

10-
The current module contains the reference implementation of JSR 354, licenced under
11-
the Apache 2 Licence, see LICENCE.html.
12+
This module is licenced under the the [Apache 2 Licence](https://www.apache.org/licenses/LICENSE-2.0.html).
1213

1314
[![Build Status](https://api.travis-ci.org/JavaMoney/jsr354-ri.png?branch=master)](https://travis-ci.org/JavaMoney/jsr354-ri)
1415
[![Coverage Status](https://coveralls.io/repos/JavaMoney/jsr354-ri/badge.png)](https://coveralls.io/r/JavaMoney/jsr354-ri)

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
<parent>
2020
<groupId>org.javamoney</groupId>
2121
<artifactId>javamoney-parent</artifactId>
22-
<version>1.0-SNAPSHOT</version>
22+
<version>0.5</version>
2323
</parent>
2424

2525
<artifactId>moneta</artifactId>
2626
<packaging>jar</packaging>
27-
<version>1.0-SNAPSHOT</version>
2827

2928
<name>Moneta (JSR 354 RI)</name>
3029
<url>http://javamoney.org</url>
@@ -630,4 +629,5 @@
630629
</plugins>
631630
</reporting>
632631

632+
<version>1.0-RC1</version>
633633
</project>

src/main/java/org/javamoney/moneta/CurrencyUnitBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
2+
* Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of

src/test/java/org/javamoney/moneta/FastMoneyTest.java

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
import javax.money.*;
2121

2222
import java.io.*;
23+
import java.lang.invoke.MethodHandles;
2324
import java.math.BigDecimal;
2425
import java.math.BigInteger;
26+
import java.util.logging.Level;
27+
import java.util.logging.Logger;
2528

2629
import static org.testng.Assert.*;
2730

2831
/**
2932
* @author Anatole
3033
*/
3134
public class FastMoneyTest{
35+
36+
private static final Logger LOG = Logger.getLogger(MethodHandles.lookup().lookupClass().getName());
3237

3338
private static final BigDecimal TEN = new BigDecimal(10.0d);
3439
protected static final CurrencyUnit EURO = MonetaryCurrencies.getCurrency("EUR");
@@ -416,6 +421,123 @@ public void testMultiplyDouble(){
416421
FastMoney m = FastMoney.of(100, "CHF");
417422
assertEquals(FastMoney.of(new BigDecimal("50.0"), "CHF"), m.multiply(0.5));
418423
}
424+
425+
/**
426+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(double)}.
427+
*/
428+
@Test
429+
public void testMultiplyDoublePositiveInfinity(){
430+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
431+
try {
432+
m.multiply(Double.POSITIVE_INFINITY);
433+
fail("multiplying with POSITIVE_INFINITY should fail");
434+
} catch (ArithmeticException e) {
435+
LOG.log(Level.FINE, "multiplying with POSITIVE_INFINITY fails as expected", e);
436+
}
437+
}
438+
439+
/**
440+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(double)}.
441+
*/
442+
@Test
443+
public void testMultiplyDoubleNegativeInfinity(){
444+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
445+
try {
446+
m.multiply(Double.NEGATIVE_INFINITY);
447+
fail("multiplying with NEGATIVE_INFINITY should fail");
448+
} catch (ArithmeticException e) {
449+
LOG.log(Level.FINE, "multiplying with NEGATIVE_INFINITY fails as expected", e);
450+
}
451+
}
452+
453+
/**
454+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(double)}.
455+
*/
456+
@Test
457+
public void testMultiplyDoubleNaN(){
458+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
459+
try {
460+
m.multiply(Double.NaN);
461+
fail("multiplying with NaN should fail");
462+
} catch (ArithmeticException e) {
463+
LOG.log(Level.FINE, "multiplying with NaN fails as expected", e);
464+
}
465+
}
466+
467+
/**
468+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(Number)}.
469+
*/
470+
@Test
471+
public void testMultiplyNumberPositiveInfinity(){
472+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
473+
try {
474+
m.multiply(Double.valueOf(Double.POSITIVE_INFINITY));
475+
fail("multiplying with POSITIVE_INFINITY should fail");
476+
} catch (ArithmeticException e) {
477+
LOG.log(Level.FINE, "multiplying with POSITIVE_INFINITY fails as expected", e);
478+
}
479+
}
480+
481+
/**
482+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(Number)}.
483+
*/
484+
@Test
485+
public void testMultiplyNumberNegativeInfinity(){
486+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
487+
try {
488+
m.multiply(Double.valueOf(Double.NEGATIVE_INFINITY));
489+
fail("multiplying with NEGATIVE_INFINITY should fail");
490+
} catch (ArithmeticException e) {
491+
LOG.log(Level.FINE, "multiplying with NEGATIVE_INFINITY fails as expected", e);
492+
}
493+
}
494+
495+
/**
496+
* Test method for {@link org.javamoney.moneta.FastMoney#multiply(Number)}.
497+
*/
498+
@Test
499+
public void testMultiplyNumberNaN(){
500+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
501+
try {
502+
m.multiply(Double.valueOf(Double.NaN));
503+
fail("multiplying with NaN should fail");
504+
} catch (ArithmeticException e) {
505+
LOG.log(Level.FINE, "multiplying with NaN fails as expected", e);
506+
}
507+
}
508+
509+
/**
510+
* Test method for {@link org.javamoney.moneta.FastMoney#divide(double)}.
511+
*/
512+
@Test
513+
public void testDivideBadNaN(){
514+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
515+
try {
516+
m.divide(Double.NaN);
517+
fail("dividing by NaN should not be allowed");
518+
} catch (ArithmeticException e) {
519+
LOG.log(Level.FINE, "dividing by NaN fails as expected", e);
520+
}
521+
try {
522+
m.divide(Double.valueOf(Double.NaN));
523+
fail("dividing by h NaN should not be allowed");
524+
} catch (ArithmeticException e) {
525+
LOG.log(Level.FINE, "dividing by NaN fails as expected", e);
526+
}
527+
}
528+
529+
/**
530+
* Test method for {@link org.javamoney.moneta.FastMoney#divide(double)}.
531+
*/
532+
@Test
533+
public void testDivideInfinityDoubles(){
534+
double[] values = new double[]{Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
535+
FastMoney m = FastMoney.of(new BigDecimal("50.0"), "USD");
536+
for (double d : values) {
537+
assertTrue(m.divide(d).isZero());
538+
assertTrue(m.divide(Double.valueOf(d)).isZero());
539+
}
540+
}
419541

420542
/**
421543
* Test method for {@link org.javamoney.moneta.FastMoney#negate()}.

src/test/java/org/javamoney/moneta/MoneyTest.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,67 @@ public void testMultiplyNumber() {
525525
assertEquals(Money.of(200, "CHF"), m.multiply(2));
526526
assertEquals(Money.of(new BigDecimal("50.0"), "CHF"), m.multiply(0.5));
527527
}
528+
529+
530+
531+
/**
532+
* Test method for {@link org.javamoney.moneta.Money#multiply(double)}.
533+
*/
534+
@Test
535+
public void testMultiplyBadDoubles(){
536+
double[] values = new double[]{
537+
Double.POSITIVE_INFINITY,
538+
Double.NEGATIVE_INFINITY,
539+
Double.NaN};
540+
Money m = Money.of(new BigDecimal("50.0"), "USD");
541+
for (double d : values) {
542+
try {
543+
m.multiply(d);
544+
fail("multiplying with:" + d + "should not be allowed");
545+
} catch (ArithmeticException e) {
546+
// should reach here
547+
}
548+
try {
549+
m.multiply(Double.valueOf(d));
550+
fail("multiplying with:" + d + "should not be allowed");
551+
} catch (ArithmeticException e) {
552+
// should reach here
553+
}
554+
}
555+
}
556+
557+
/**
558+
* Test method for {@link org.javamoney.moneta.Money#divide(double)}.
559+
*/
560+
@Test
561+
public void testDivideBadDoubles(){
562+
Money m = Money.of(new BigDecimal("50.0"), "USD");
563+
try {
564+
m.divide(Double.NaN);
565+
fail("dividing with:NaN should not be allowed");
566+
} catch (ArithmeticException e) {
567+
// should reach here
568+
}
569+
try {
570+
m.divide(Double.valueOf(Double.NaN));
571+
fail("dividing with NaN should not be allowed");
572+
} catch (ArithmeticException e) {
573+
// should reach here
574+
}
575+
}
576+
577+
/**
578+
* Test method for {@link org.javamoney.moneta.Money#divide(double)}.
579+
*/
580+
@Test
581+
public void testDivideInfinityDoubles(){
582+
double[] values = new double[]{Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY};
583+
Money m = Money.of(new BigDecimal("50.0"), "USD");
584+
for (double d : values) {
585+
assertTrue(m.divide(d).isZero());
586+
assertTrue(m.divide(Double.valueOf(d)).isZero());
587+
}
588+
}
528589

529590
/**
530591
* Test method for {@link org.javamoney.moneta.Money#negate()}.

0 commit comments

Comments
 (0)