Skip to content

Commit 9c446ec

Browse files
authored
Merge pull request #3 from navikt/grunnbelop
bibliotek for grunnbelop og tester
2 parents c7c21d2 + 94a1a8a commit 9c446ec

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

grunnbelop/build.gradle.kts

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package no.nav.dagpenger.grunnbelop
2+
3+
import java.math.BigDecimal
4+
import java.time.LocalDate
5+
import java.time.Month
6+
import java.time.YearMonth
7+
8+
data class Grunnbeløp(
9+
val fom: LocalDate,
10+
val tom: LocalDate,
11+
val verdi: BigDecimal
12+
)
13+
14+
private val grunnbeløp: Set<Grunnbeløp> = setOf(
15+
Grunnbeløp(
16+
LocalDate.of(2019, Month.MAY, 1),
17+
LocalDate.of(2020, Month.APRIL, 30),
18+
99858.toBigDecimal()),
19+
Grunnbeløp(
20+
LocalDate.of(2018, Month.MAY, 1),
21+
LocalDate.of(2019, Month.APRIL, 30),
22+
96883.toBigDecimal()),
23+
Grunnbeløp(
24+
LocalDate.of(2017, Month.MAY, 1),
25+
LocalDate.of(2018, Month.APRIL, 30),
26+
93634.toBigDecimal()),
27+
Grunnbeløp(
28+
LocalDate.of(2016, Month.MAY, 1),
29+
LocalDate.of(2017, Month.APRIL, 30),
30+
92576.toBigDecimal()),
31+
Grunnbeløp(
32+
LocalDate.of(2015, Month.MAY, 1),
33+
LocalDate.of(2016, Month.APRIL, 30),
34+
90068.toBigDecimal())
35+
)
36+
37+
fun getGrunnbeløpForMåned(dato: YearMonth): Grunnbeløp {
38+
return grunnbeløp.first { it.gjelderFor(LocalDate.of(dato.year, dato.month, 10)) }
39+
}
40+
41+
fun getGrunnbeløpForDato(dato: LocalDate): Grunnbeløp {
42+
return grunnbeløp.first { it.gjelderFor(dato) }
43+
}
44+
45+
fun Grunnbeløp.gjelderFor(dato: LocalDate): Boolean {
46+
return !(dato.isBefore(this.fom) || (dato.isAfter(this.tom)))
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package no.nav.dagpenger.grunnbelop
2+
3+
import org.junit.jupiter.api.Assertions
4+
import org.junit.jupiter.api.Test
5+
import java.time.LocalDate
6+
import java.time.Month
7+
import java.time.YearMonth
8+
9+
class GrunnbelopTest {
10+
11+
@Test
12+
fun ` Skal returnere grunnbeløp på 99858 for måned april 2020 `() {
13+
14+
Assertions.assertEquals(99858.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2020, Month.APRIL)).verdi)
15+
}
16+
17+
@Test
18+
fun ` Skal returnere grunnbeløp på 99858 for måned may 2019 `() {
19+
20+
Assertions.assertEquals(99858.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2019, Month.MAY)).verdi)
21+
}
22+
23+
@Test
24+
fun ` Skal returnere grunnbeløp på 96883 for måned april 2019 `() {
25+
26+
Assertions.assertEquals(96883.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2019, Month.APRIL)).verdi)
27+
}
28+
29+
@Test
30+
fun ` Skal returnere grunnbeløp på 93634 for måned mars 2018 `() {
31+
32+
Assertions.assertEquals(93634.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2018, Month.MARCH)).verdi)
33+
}
34+
35+
@Test
36+
fun ` Skal returnere grunnbeløp på 92576 for måned mai 2016 `() {
37+
38+
Assertions.assertEquals(92576.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2016, Month.MAY)).verdi)
39+
}
40+
41+
@Test
42+
fun ` Skal returnere grunnbeløp på 90068 for måned mars 2015 `() {
43+
44+
Assertions.assertEquals(90068.toBigDecimal(), getGrunnbeløpForMåned(YearMonth.of(2015, Month.AUGUST)).verdi)
45+
}
46+
47+
@Test
48+
fun ` Skal returnere grunnbeløp på 90068 for dato 06032015 `() {
49+
50+
Assertions.assertEquals(90068.toBigDecimal(), getGrunnbeløpForDato(LocalDate.of(2015, 8, 6)).verdi)
51+
}
52+
53+
@Test
54+
fun ` Skal returnere grunnbeløp på 90068 for dato 01052019 `() {
55+
56+
Assertions.assertEquals(99858.toBigDecimal(), getGrunnbeløpForDato(LocalDate.of(2019, 5, 1)).verdi)
57+
}
58+
}

settings.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
rootProject.name = "dp-biblioteker"
22

33
include("sts-klient")
4-
include("ktor-utils")
4+
include("ktor-utils")
5+
include("grunnbelop")

0 commit comments

Comments
 (0)