Skip to content

Commit

Permalink
[HMA-2463] - 2020/2021 Update (#34)
Browse files Browse the repository at this point in the history
* Update NI rates for 2020 tax year

* Upgrade to 1.3.70

* Add in Data-Driven Tests for 2020

Co-authored-by: Ngou Long Kam <[email protected]>
  • Loading branch information
georgeherby and ngoulongkam authored Mar 5, 2020
1 parent 69a9c7e commit cda8bb3
Show file tree
Hide file tree
Showing 11 changed files with 571 additions and 73 deletions.
44 changes: 19 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ version = System.getenv("BITRISE_GIT_TAG") ?: ("SNAPSHOT-" + getDate())

plugins {
`maven-publish`
kotlin("multiplatform").version("1.3.61")
kotlin("multiplatform").version("1.3.70")
jacoco
java
id("com.github.dawnwords.jacoco.badge").version("0.1.0")
Expand All @@ -46,6 +46,7 @@ repositories {
}
}


/***********************************************************************************************************************
* Declarations
***********************************************************************************************************************/
Expand Down Expand Up @@ -93,7 +94,7 @@ kotlin {
}

sourceSets {
val klockVersion = "1.8.0"
val klockVersion = "1.9.0"
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
Expand All @@ -104,6 +105,8 @@ kotlin {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("io.kotlintest:kotlintest-runner-junit5:3.3.2")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
}
}

Expand All @@ -115,7 +118,7 @@ kotlin {
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(kotlin("test-junit5"))
}
}

Expand All @@ -125,8 +128,7 @@ kotlin {
}
}

val iosTest by getting {
}
val iosTest by getting {}

val iosArm32Main by sourceSets.getting
val iosArm64Main by sourceSets.getting
Expand All @@ -142,20 +144,6 @@ kotlin {
}
}

tasks.register("iosTest") {
group = project.name
val device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
this.dependsOn(iosX64.binaries.getTest("DEBUG").linkTaskName)
group = JavaBasePlugin.VERIFICATION_GROUP
description = "Runs tests for target ios on an iOS simulator"

doLast {
val binary = iosArm64.binaries.getTest("DEBUG").outputFile
exec {
commandLine(listOf("xcrun", "simctl", "spawn", device, binary.absolutePath))
}
}
}

tasks.register<org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask>("fatFramework") {
group = project.name
Expand All @@ -171,10 +159,7 @@ kotlin {
this.dependsOn(iosSimulatorFramework.linkTask)

from(
ios32Framework,
ios64Framework,
iosSimulatorFramework
)
ios32Framework, ios64Framework, iosSimulatorFramework)

doLast {
File(destinationDir, "gradlew").apply {
Expand All @@ -185,6 +170,16 @@ kotlin {
}
}

tasks.named<Test>("jvmTest") {
useJUnitPlatform()
testLogging {
showExceptions = true
showStandardStreams = true
events = setOf(org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED, org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}

tasks.getByName("build").dependsOn(tasks.getByName("fatFramework"))

/***********************************************************************************************************************
Expand Down Expand Up @@ -296,6 +291,5 @@ tasks.register<GradleBuild>("cleanBuildTestCoverage") {
"build",
"testCommonUnitTestCoverage",
"generateJacocoBadge",
"jacocoTestCoverageVerification"
)
"jacocoTestCoverageVerification")
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
4 changes: 1 addition & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
rootProject.name = "tax-kalculator"

enableFeaturePreview("GRADLE_METADATA")
rootProject.name = "tax-kalculator"
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package uk.gov.hmrc.calculator.annotations

import kotlin.reflect.KClass

@UseExperimental(ExperimentalMultiplatform::class)
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.SOURCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import uk.gov.hmrc.calculator.exception.InvalidTaxYearException

internal class EmployeeNIBands(taxYear: Int) {

private val employeeNIBands2020: List<EmployeeNIBand> = listOf(
EmployeeNIBand(0.0, 6240.00, 0.0),
EmployeeNIBand(6240.0, 9500.00, 0.0),
EmployeeNIBand(9500.0, 50000.00, 0.12),
EmployeeNIBand(50000.0, -1.0, 0.02)
)

private val employeeNIBands2019: List<EmployeeNIBand> = listOf(
EmployeeNIBand(0.0, 6136.00, 0.0),
EmployeeNIBand(6136.0, 8632.00, 0.0),
Expand All @@ -27,6 +34,7 @@ internal class EmployeeNIBands(taxYear: Int) {
)

internal val bands: List<EmployeeNIBand> = when (taxYear) {
2020 -> employeeNIBands2020
2019 -> employeeNIBands2019
else -> throw InvalidTaxYearException("$taxYear")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import uk.gov.hmrc.calculator.exception.InvalidTaxYearException

internal class EmployerNIBands(taxYear: Int) {

private val employerNIBands2020: List<EmployerNIBand> = listOf(
EmployerNIBand(0.0, 6240.00, 0.0),
EmployerNIBand(6240.0, 8788.00, 0.0),
EmployerNIBand(8788.0, 50000.00, 0.138),
EmployerNIBand(50000.0, -1.0, 0.138)
)

private val employerNIBands2019: List<EmployerNIBand> = listOf(
EmployerNIBand(0.0, 6136.00, 0.0),
EmployerNIBand(6136.0, 8632.00, 0.0),
Expand All @@ -27,6 +34,7 @@ internal class EmployerNIBands(taxYear: Int) {
)

internal val bands: List<EmployerNIBand> = when (taxYear) {
2020 -> employerNIBands2020
2019 -> employerNIBands2019
else -> throw InvalidTaxYearException("$taxYear")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ package uk.gov.hmrc.calculator.model.bands
import uk.gov.hmrc.calculator.exception.InvalidTaxYearException
import uk.gov.hmrc.calculator.model.Country
import uk.gov.hmrc.calculator.model.Country.SCOTLAND
import uk.gov.hmrc.calculator.model.Country.WALES

internal class TaxBands(country: Country, taxYear: Int) {

// 2020
private val wales2020: List<Band> = listOf(
TaxBand(0.0, 20000.00, 0.1)
)
private val scotland2020: List<Band> = listOf(
TaxBand(0.0, 21000.00, 0.15)
TaxBand(0.0, 12509.00, 0.0),
TaxBand(12509.00, 14549.00, 0.19),
TaxBand(14549.00, 24944.00, 0.20),
TaxBand(24944.00, 43430.00, 0.21),
TaxBand(43430.00, 150000.00, 0.41),
TaxBand(150000.0, -1.0, 0.46)
)
private val other2020: List<Band> = listOf(
TaxBand(0.0, 22000.00, 0.20)
TaxBand(0.0, 12509.00, 0.0),
TaxBand(12509.0, 50000.00, 0.2),
TaxBand(50000.0, 150000.00, 0.4),
TaxBand(150000.0, -1.0, 0.45)
)

// 2019
Expand All @@ -51,7 +55,6 @@ internal class TaxBands(country: Country, taxYear: Int) {

internal val bands: List<Band> = when (taxYear) {
2020 -> when (country) {
WALES -> wales2020
SCOTLAND -> scotland2020
else -> other2020
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@ class EmployeeNIBandsTests {
}

@Test
fun `Employee NI 2019 England`() {
fun `Employee NI 2019`() {
val band = EmployeeNIBands(2019).bands[2]
assertEquals(0.12, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employee NI 2019 Scotland`() {
val band = EmployeeNIBands(2019).bands[2]
assertEquals(0.12, band.percentageAsDecimal)
fun `Employee NI 2019 Large Wages`() {
val band = EmployeeNIBands(2019).bands[3]
assertEquals(0.02, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
assertEquals(true, band.inBand(100000.0))
}

@Test
fun `Employee NI 2019 Wales`() {
val band = EmployeeNIBands(2019).bands[2]
fun `Employee NI 2020`() {
val band = EmployeeNIBands(2020).bands[2]
assertEquals(0.12, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employee NI 2019 Wales Massive Wages`() {
val band = EmployeeNIBands(2019).bands[3]
fun `Employee NI 2020 Large Wages`() {
val band = EmployeeNIBands(2020).bands[3]
assertEquals(0.02, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(100000.0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,42 @@ class EmployerNIBandsTests {
}

@Test
fun `Employee NI 2019 England`() {
fun `Employer NI 2019 England`() {
val band = EmployerNIBands(2019).bands[2]
assertEquals(0.138, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employee NI 2019 Scotland`() {
fun `Employer NI 2019 Scotland`() {
val band = EmployerNIBands(2019).bands[2]
assertEquals(0.138, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employee NI 2019 Wales`() {
fun `Employer NI 2019 Wales`() {
val band = EmployerNIBands(2019).bands[2]
assertEquals(0.138, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employer NI 2020 England`() {
val band = EmployerNIBands(2020).bands[2]
assertEquals(0.138, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}

@Test
fun `Employer NI 2020 Scotland`() {
val band = EmployerNIBands(2020).bands[2]
assertEquals(0.138, band.percentageAsDecimal)
assertEquals(false, band.inBand(1000.0))
assertEquals(true, band.inBand(10000.0))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,4 @@ class TaxBandsTests {
assertEquals(true, taxBand.inBand(14548.00))
assertEquals(false, taxBand.inBand(14550.00))
}

@Test
fun bandsForWales2020() {
val taxBand = TaxBands(WALES, 2020).bands[0]
assertEquals(20000.00, taxBand.upper)
assertEquals(0.00, taxBand.lower)
assertEquals(0.10, taxBand.percentageAsDecimal)
}

@Test
fun bandsForScotland2020() {
val taxBand = TaxBands(SCOTLAND, 2020).bands[0]
assertEquals(21000.00, taxBand.upper)
assertEquals(0.00, taxBand.lower)
assertEquals(0.15, taxBand.percentageAsDecimal)
}

@Test
fun bandsForEngland2020() {
val taxBand = TaxBands(ENGLAND, 2020).bands[0]
assertEquals(22000.00, taxBand.upper)
assertEquals(0.00, taxBand.lower)
assertEquals(0.20, taxBand.percentageAsDecimal)
}
}
Loading

0 comments on commit cda8bb3

Please sign in to comment.