Skip to content

Commit

Permalink
min-/max provided
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Aug 2, 2018
1 parent 1cd368a commit 0048a5c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/main/java/de/jfachwert/bank/Geldbetrag.java
Expand Up @@ -65,7 +65,13 @@ public class Geldbetrag implements MonetaryAmount, Fachwert {

/** Da 0-Betraege relativ haeufig vorkommen, spendieren wir dafuer eine eigene Konstante. */
public static final Geldbetrag ZERO = new Geldbetrag(BigDecimal.ZERO);


/** Der minimale Betrag, den wir unterstuetzen. */
public static final Geldbetrag MIN_VALUE = new Geldbetrag(BigDecimal.valueOf(Long.MIN_VALUE));

/** Der maximale Betrag, den wir unterstuetzen. */
public static final Geldbetrag MAX_VALUE = new Geldbetrag(BigDecimal.valueOf(Long.MAX_VALUE));

private final BigDecimal betrag;
private final Currency currency;

Expand Down
18 changes: 7 additions & 11 deletions src/main/java/de/jfachwert/bank/GeldbetragFactory.java
Expand Up @@ -40,7 +40,7 @@ public class GeldbetragFactory implements MonetaryAmountFactory<Geldbetrag> {
*/
@Override
public Class<? extends MonetaryAmount> getAmountType() {
throw new UnsupportedOperationException("not yet implemented");
return Geldbetrag.class;
}

/**
Expand Down Expand Up @@ -91,27 +91,23 @@ public MonetaryAmountFactory<Geldbetrag> setNumber(Number number) {
}

/**
* Get the maximum possible number that this type can represent. If the numeric model has no limitations on the
* numeric range, null should be returned. If {@link MonetaryContext#getPrecision()} returns a value > 0 this
* method is required to provide a maximal amount.
* Liefert die Maximal-Nummer, die der {@link Geldbetrag} darstellen kann.
*
* @return the maximum possible number, or null.
* @return Maximal-Betrag
*/
@Override
public NumberValue getMaxNumber() {
throw new UnsupportedOperationException("not yet implemented");
return Geldbetrag.MAX_VALUE.getNumber();
}

/**
* Get the minimum possible number that this type can represent. If the numeric model has no limitations on the
* numeric range, null should be returned. If {@link MonetaryContext#getPrecision()} returns a value > 0 this
* method is required to provide a maximal amount.
* Liefert die Minimal-Nummer, die der {@link Geldbetrag} darstellen kann.
*
* @return the minimum possible number, or null.
* @return Minimal-Betrag
*/
@Override
public NumberValue getMinNumber() {
throw new UnsupportedOperationException("not yet implemented");
return Geldbetrag.MIN_VALUE.getNumber();
}

/**
Expand Down
36 changes: 32 additions & 4 deletions src/test/java/de/jfachwert/bank/GeldbetragFactoryTest.java
Expand Up @@ -19,9 +19,11 @@

import org.junit.Test;

import java.math.BigDecimal;
import javax.money.NumberValue;

import static org.junit.Assert.*;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

/**
* Unit-Tests fuer {@link GeldbetragFactory}-Klasse.
Expand All @@ -46,9 +48,35 @@ public void testCreate() {
*/
@Test
public void testSetNumber() {
factory.setNumber(BigDecimal.ONE);
factory.setCurrency("CHF");
factory.setNumber(1).setCurrency("CHF");
assertEquals(Geldbetrag.valueOf("1 CHF"), factory.create());
}

/**
* Testet das Setzen eines Geldbetrags.
*/
@Test
public void testSetNumberDouble() {
factory.setNumber(0.25).setCurrency("EUR");
assertEquals(Geldbetrag.valueOf("0.25 EUR"), factory.create());
}

/**
* Hier wird der Min-/Max-Bereich eines Geldbetrags geprueft.
*/
@Test
public void testMinMaxNumber() {
NumberValue minNumber = factory.getMinNumber();
NumberValue maxNumber = factory.getMaxNumber();
assertThat(minNumber + " < " + maxNumber, minNumber.compareTo(maxNumber), lessThan(0));
}

/**
* Testmethode fuer {@link GeldbetragFactory#getAmountType()}.
*/
@Test
public void testGetAmountType() {
assertEquals(Geldbetrag.class, factory.getAmountType());
}

}

0 comments on commit 0048a5c

Please sign in to comment.