-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Entea/transaction_validation_date_range
Transaction validation: date range
- Loading branch information
Showing
10 changed files
with
118 additions
and
12 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
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
67 changes: 67 additions & 0 deletions
67
base/src/test/scala/co/uproot/abandon/DateConstraintTest.scala
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,67 @@ | ||
package co.uproot.abandon | ||
|
||
import java.time.{LocalDate, Month} | ||
|
||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest._ | ||
|
||
class DateConstraintTest extends FlatSpec with Matchers with BeforeAndAfterEach with MockFactory with OneInstancePerTest { | ||
|
||
class MockableDetailedPost extends DetailedPost(new AccountName(Seq()), 0, None, None) | ||
|
||
var appState: AppState = null | ||
|
||
override def beforeEach() { | ||
setupMocks() | ||
} | ||
|
||
it should "return true on valid posts" in { | ||
val constraint = new DateConstraint( | ||
Some(Date(2013, 1, 1)), | ||
Some(Date(2013, 12, 31)) | ||
) | ||
|
||
constraint.check(appState) should be(true) | ||
} | ||
|
||
it should "throw exception on end date violation" in { | ||
val constraint = new DateConstraint( | ||
Some(Date(2013, 1, 1)), | ||
Some(Date(2013, 11, 1)) | ||
) | ||
an [ConstraintError] should be thrownBy constraint.check(appState) | ||
|
||
val constraintWithoutFrom = new DateConstraint(None, Some(Date(2013, 11, 1))) | ||
an [ConstraintError] should be thrownBy constraintWithoutFrom.check(appState) | ||
} | ||
|
||
it should "throw exception on start date violation" in { | ||
val constraint = new DateConstraint( | ||
Some(Date(2013, 6, 1)), | ||
Some(Date(2013, 11, 1)) | ||
) | ||
an [ConstraintError] should be thrownBy constraint.check(appState) | ||
|
||
val constraintWithoutTo = new DateConstraint(Some(Date(2013, 11, 1)), None) | ||
an [ConstraintError] should be thrownBy constraintWithoutTo.check(appState) | ||
} | ||
|
||
it should "return true on empty dates" in { | ||
val constraintWithoutTo = new DateConstraint(None, None) | ||
constraintWithoutTo.check(appState) should be(true) | ||
} | ||
|
||
|
||
def setupMocks() { | ||
val accState = stub[AccountState] | ||
appState = new AppState(accState) | ||
|
||
val posts: Seq[DetailedPost] = (1 to 12).map(month => { | ||
val post = stub[MockableDetailedPost] | ||
(post.date _).when().returns(new Date(2013, month, 1)) | ||
post | ||
}) | ||
|
||
(accState.posts _).when().returns(posts) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -67,3 +67,8 @@ exports += { | |
}] | ||
|
||
} | ||
|
||
dateConstraints += { | ||
from = "2012-01-01" | ||
to = "2013-12-31" | ||
} |
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 |
---|---|---|
|
@@ -16,4 +16,3 @@ reports += { | |
type = balance | ||
accountMatch = ["^Income.*", "^Expenses.*"] | ||
} | ||
|
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