This repository was archived by the owner on Apr 25, 2023. It is now read-only.
forked from skizware/money-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed amount from double to JavaMoney
- Loading branch information
Showing
17 changed files
with
298 additions
and
225 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.iml | ||
target/ | ||
.idea | ||
.idea | ||
/.settings/ | ||
/.project |
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,3 @@ | ||
/.settings/ | ||
/.classpath | ||
/.project |
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
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
package com.skizware.money.tracker.service; | ||
|
||
import com.skizware.money.tracker.domain.MoneyTracker; | ||
import com.skizware.money.tracker.persistence.repository.UserRepository; | ||
import com.skizware.user.User; | ||
import junit.framework.TestCase; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
|
||
import org.javamoney.moneta.FastMoney; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import com.skizware.money.tracker.service.impl.MoneyTrackerServiceImpl; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.money.CurrencyUnit; | ||
import javax.money.Monetary; | ||
import javax.money.MonetaryAmount; | ||
|
||
/** | ||
* Tests for the application logic. | ||
|
@@ -24,17 +22,17 @@ | |
@ContextConfiguration(locations = "ApplicationTest-config.xml") | ||
public class MoneyTrackerServiceTest extends TestCase { | ||
|
||
|
||
public static final String TEST_EMAIL_1 = "[email protected]"; | ||
public static final String TEST_EMAIL_2 = "[email protected]"; | ||
private static final CurrencyUnit TEST_CURRENCY = Monetary.getCurrency("EUR"); | ||
private static final String TEST_EMAIL_1 = "[email protected]"; | ||
private static final String TEST_EMAIL_2 = "[email protected]"; | ||
|
||
@Autowired | ||
private MoneyTrackerServiceImpl moneyTrackerService; | ||
|
||
public void setupUser(){ | ||
User newUser = moneyTrackerService.enrollUser(TEST_EMAIL_1); | ||
MoneyTracker moneyTracker = moneyTrackerService.createUserMoneyTracker(newUser, 5000D); | ||
moneyTracker.addTransaction(-500D, "Stuff"); | ||
MoneyTracker moneyTracker = moneyTrackerService.createUserMoneyTracker(newUser, FastMoney.of(5000D, TEST_CURRENCY)); | ||
moneyTracker.addTransaction(FastMoney.of(-500D, TEST_CURRENCY), "Stuff"); | ||
moneyTrackerService.updateUserMoneyTrackers(newUser); | ||
} | ||
|
||
|
@@ -78,15 +76,19 @@ public void testCreateMoneyTrackerForUser() { | |
//given a user | ||
User user = new User(TEST_EMAIL_2); | ||
|
||
MoneyTracker moneyTracker = moneyTrackerService.createUserMoneyTracker(user, 5000D); | ||
MoneyTracker moneyTracker = moneyTrackerService.createUserMoneyTracker(user, createMoney(5000D)); | ||
assertNotNull(moneyTracker); | ||
assertEquals("First tracker created, list should have 1 tracker", 1, user.getMoneyTrackers().size()); | ||
assertEquals("Tracker should have 5000 money for the month", 5000D, moneyTracker.getMoneyForTheMonth()); | ||
assertEquals("Tracker should have 5000 money for the month", createMoney(5000D), moneyTracker.getMoneyForTheMonth()); | ||
|
||
moneyTracker = moneyTrackerService.createUserMoneyTracker(user, 7000D); | ||
moneyTracker = moneyTrackerService.createUserMoneyTracker(user, createMoney(7000D)); | ||
assertNotNull(moneyTracker); | ||
assertEquals("Second tracker created, list should have 2 trackers", 2, user.getMoneyTrackers().size()); | ||
assertEquals("Tracker should have 7000 money for the month", 7000D, moneyTracker.getMoneyForTheMonth()); | ||
assertEquals("Tracker should have 7000 money for the month", createMoney(7000D), moneyTracker.getMoneyForTheMonth()); | ||
} | ||
|
||
private MonetaryAmount createMoney(final Double number) { | ||
return FastMoney.of(number, TEST_CURRENCY); | ||
} | ||
|
||
} |
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,3 @@ | ||
/.settings/ | ||
/.classpath | ||
/.project |
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 |
---|---|---|
@@ -1,28 +1,34 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>skizware</groupId> | ||
<artifactId>money-tracker</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>skizware</groupId> | ||
<artifactId>money-tracker</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>skizware.money-tracker</groupId> | ||
<artifactId>money-tracker-domain</artifactId> | ||
<packaging>jar</packaging> | ||
<groupId>skizware.money-tracker</groupId> | ||
<artifactId>money-tracker-domain</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>money-tracker-domain</name> | ||
<url>http://maven.apache.org</url> | ||
<name>money-tracker-domain</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.javamoney</groupId> | ||
<artifactId>moneta</artifactId> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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
Oops, something went wrong.