Skip to content

Commit

Permalink
Merge pull request #98 from kartverket/TB-70-remove-assert-j
Browse files Browse the repository at this point in the history
TB-70 Fjern assertJ og skriv om til assertK
  • Loading branch information
henriwi authored Sep 25, 2024
2 parents 404317b + fee0383 commit fc3099a
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 131 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ testing {
implementation(libs.ktor.server.tests)
implementation(libs.ktor.client.content.negotation)

implementation(libs.assertj)
implementation(libs.assertk)
implementation(libs.testcontainers.postgresql)
}
}
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ shadowVersion = "8.1.1"
kompendiumVersion = "3.14.4"
jaxwsVersion = "4.0.3"
hikariVersion = "6.0.0"
assertjVersion = "3.26.3"
testcontainersVersion = "1.20.1"
mockkVersion = "1.13.12"
assertkVersion = "0.28.1"
Expand Down Expand Up @@ -45,7 +44,6 @@ kompendium-core = { group = "io.bkbn", name = "kompendium-core", version.ref = "
jaxws-rt = { group = "com.sun.xml.ws", name = "jaxws-rt", version.ref = "jaxwsVersion" }
jaxws-tools = { group = "com.sun.xml.ws", name = "jaxws-tools", version.ref = "jaxwsVersion" }

assertj = { group = "org.assertj", name = "assertj-core", version.ref = "assertjVersion" }
testcontainers-postgresql = { group = "org.testcontainers", name = "postgresql", version.ref = "testcontainersVersion" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockkVersion" }
mockk-dsl = { group = "io.mockk", name = "mockk-dsl", version.ref = "mockkVersion" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package no.kartverket.matrikkel.bygning

import assertk.assertThat
import assertk.assertions.isEqualTo
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.testing.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class InternalRouteTest : TestApplicationWithDb() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package no.kartverket.matrikkel.bygning.repositories

import assertk.all
import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.index
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.prop
import assertk.assertions.single
import no.kartverket.matrikkel.bygning.models.BruksarealRegistrering
import no.kartverket.matrikkel.bygning.models.BygningRegistrering
import no.kartverket.matrikkel.bygning.models.Egenregistrering
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Instant
import java.util.*

class EgenregistreringRepositoryTest : TestWithDb() {
val egenregistreringRepository = EgenregistreringRepository(dataSource)
private val egenregistreringRepository = EgenregistreringRepository(dataSource)

val defaultBygningRegistrering = BygningRegistrering(
private val defaultBygningRegistrering = BygningRegistrering(
bygningId = 1L,
bruksarealRegistrering = BruksarealRegistrering(
bruksareal = 125.0,
Expand All @@ -23,7 +30,7 @@ class EgenregistreringRepositoryTest : TestWithDb() {
bruksenhetRegistreringer = emptyList()
)

val defaultEgenregistrering = Egenregistrering(
private val defaultEgenregistrering = Egenregistrering(
id = UUID.randomUUID(),
registreringstidspunkt = Instant.parse("2024-01-01T12:00:00.00Z"),
bygningRegistrering = defaultBygningRegistrering,
Expand All @@ -35,20 +42,18 @@ class EgenregistreringRepositoryTest : TestWithDb() {

val bygningRegistreringer = egenregistreringRepository.getAllEgenregistreringerForBygning(1L)

assertThat(bygningRegistreringer).size().isEqualTo(1)
assertThat(bygningRegistreringer[0]).satisfies(
{ egenregistrering ->
assertThat(egenregistrering.id).isEqualTo(defaultEgenregistrering.id)
assertThat(egenregistrering.registreringstidspunkt).isEqualTo(defaultEgenregistrering.registreringstidspunkt)
}
)
assertThat(bygningRegistreringer).hasSize(1)

assertThat(bygningRegistreringer).single().all {
prop(Egenregistrering::id).isEqualTo(defaultEgenregistrering.id)
prop(Egenregistrering::registreringstidspunkt).isEqualTo(defaultEgenregistrering.registreringstidspunkt)
}
}

@Test
fun `lagring av 2 egenregistreringer skal returneres i riktig rekkefolge med seneste registreringer forst i listen`() {
val laterRegistreringId = UUID.randomUUID()
val laterRegistrering = defaultEgenregistrering.copy(
id = laterRegistreringId,
id = UUID.randomUUID(),
registreringstidspunkt = defaultEgenregistrering.registreringstidspunkt.plusSeconds(60)
)

Expand All @@ -57,15 +62,17 @@ class EgenregistreringRepositoryTest : TestWithDb() {

val registreringer = egenregistreringRepository.getAllEgenregistreringerForBygning(1L)

assertThat(registreringer[0].id).isEqualTo(laterRegistrering.id)
assertThat(registreringer[1].id).isEqualTo(defaultEgenregistrering.id)
assertThat(registreringer).index(0).all {
prop(Egenregistrering::id).isEqualTo(laterRegistrering.id)
}
assertThat(registreringer).index(1).all {
prop(Egenregistrering::id).isEqualTo(defaultEgenregistrering.id)
}
}

@Test
fun `henting av registreringer skal gi tom liste hvis bygningen ikke har registreringer`() {
egenregistreringRepository.saveEgenregistrering(defaultEgenregistrering)

val registreringer = egenregistreringRepository.getAllEgenregistreringerForBygning(2L)
val registreringer = egenregistreringRepository.getAllEgenregistreringerForBygning(1L)

assertThat(registreringer).isEmpty()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package no.kartverket.matrikkel.bygning.v1

import assertk.all
import assertk.assertThat
import assertk.assertions.hasSize
import assertk.assertions.isEqualTo
import assertk.assertions.prop
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.testing.*
import no.kartverket.matrikkel.bygning.TestApplicationWithDb
import no.kartverket.matrikkel.bygning.routes.v1.dto.response.BygningResponse
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class BygningRouteTest : TestApplicationWithDb() {
Expand All @@ -18,8 +22,10 @@ class BygningRouteTest : TestApplicationWithDb() {
val response = client.get("/v1/bygninger/1")

assertThat(response.status).isEqualTo(HttpStatusCode.OK)
assertThat(response.body<BygningResponse>().bygningId).isEqualTo(1L)
assertThat(response.body<BygningResponse>().bruksenheter).hasSize(2)
assertThat(response.body<BygningResponse>()).all {
prop(BygningResponse::bygningId).isEqualTo(1L)
prop(BygningResponse::bruksenheter).hasSize(2)
}
}

@Test
Expand Down
Loading

0 comments on commit fc3099a

Please sign in to comment.