-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PgClient Money does not preserve sign if integral part is zero (#1362)
Fixes #1360 Signed-off-by: Thomas Segismont <[email protected]>
- Loading branch information
1 parent
f9e17ed
commit 4842084
Showing
3 changed files
with
98 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
vertx-pg-client/src/test/java/io/vertx/pgclient/data/MoneyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.vertx.pgclient.data; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MoneyTest { | ||
|
||
@Parameters | ||
public static Object[][] data() { | ||
return new Object[][]{{"-1234.56", -1234L, 56}, {"-0.12", 0L, 12}, {"0.12", 0L, 12}, {"1234.56", 1234L, 56}}; | ||
} | ||
|
||
@Parameter | ||
public String strValue; | ||
@Parameter(1) | ||
public long integralPart; | ||
@Parameter(2) | ||
public int fractionalPart; | ||
private BigDecimal value; | ||
private Money money; | ||
|
||
@Before | ||
public void setUp() { | ||
value = new BigDecimal(strValue); | ||
money = new Money(value); | ||
} | ||
|
||
@Test | ||
public void testBigDecimalValue() { | ||
assertEquals(value, money.bigDecimalValue()); | ||
} | ||
|
||
@Test | ||
public void testIntegerPart() { | ||
assertEquals(integralPart, money.getIntegerPart()); | ||
} | ||
|
||
@Test | ||
public void testDecimalPart() { | ||
assertEquals(fractionalPart, money.getDecimalPart()); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings("deprecation") | ||
public void setParts() { | ||
assertEquals(new Money(3.24D), money.setIntegerPart(3).setDecimalPart(24)); | ||
assertEquals(new Money(-173.01D), money.setIntegerPart(-173).setDecimalPart(1)); | ||
} | ||
} |