Skip to content

Commit

Permalink
Add builder tests for GeographicLocation and OpenStreetMapElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgirro committed Apr 28, 2021
1 parent 1d9cd39 commit 3027242
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.stalla.builder.validating

import assertk.all
import assertk.assertAll
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.isTrue
import assertk.assertions.prop
import dev.stalla.builder.GeographicLocationBuilder
import dev.stalla.model.aPodcastindexGeographicLocation
import dev.stalla.model.podcastindex.GeographicLocation
import org.junit.jupiter.api.Test

internal class ValidatingGeographicLocationBuilderTest {

@Test
internal fun `should not build a GeographicLocation when the mandatory fields are missing`() {
val geoBuilder = ValidatingGeographicLocationBuilder()

assertAll {
assertThat(geoBuilder).prop(GeographicLocationBuilder::hasEnoughDataToBuild).isFalse()

assertThat(geoBuilder.build()).isNull()
}
}

@Test
internal fun `should build a GeographicLocation with all the mandatory href field`() {
val geoBuilder = ValidatingGeographicLocationBuilder()
.latitude(1.0)
.longitude(2.0)

assertAll {
assertThat(geoBuilder).prop(GeographicLocationBuilder::hasEnoughDataToBuild).isTrue()

assertThat(geoBuilder.build()).isNotNull().all {
prop(GeographicLocation::latitude).isEqualTo(1.0)
prop(GeographicLocation::longitude).isEqualTo(2.0)
}
}
}

@Test
internal fun `should populate a GeographicLocation builder with all properties from an GeographicLocation model`() {
val geo = aPodcastindexGeographicLocation()
val geoBuilder = GeographicLocation.builder().applyFrom(geo)

assertAll {
assertThat(geoBuilder).prop(GeographicLocationBuilder::hasEnoughDataToBuild).isTrue()

assertThat(geoBuilder.build()).isNotNull().isEqualTo(geo)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.stalla.builder.validating

import assertk.all
import assertk.assertAll
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isNotNull
import assertk.assertions.isNull
import assertk.assertions.isTrue
import assertk.assertions.prop
import dev.stalla.builder.OpenStreetMapElementBuilder
import dev.stalla.model.aPodcastindexOpenStreetMapElement
import dev.stalla.model.podcastindex.OpenStreetMapElement
import dev.stalla.model.podcastindex.OpenStreetMapElementType
import org.junit.jupiter.api.Test

internal class ValidatingOpenStreetMapElementBuilderTest {

@Test
internal fun `should not build an OpenStreetMap element when the mandatory fields are missing`() {
val osmBuilder = ValidatingOpenStreetMapElementBuilder()

assertAll {
assertThat(osmBuilder).prop(OpenStreetMapElementBuilder::hasEnoughDataToBuild).isFalse()

assertThat(osmBuilder.build()).isNull()
}
}

@Test
internal fun `should build a OpenStreetMap element with all the mandatory href field`() {
val osmBuilder = ValidatingOpenStreetMapElementBuilder()
.type(OpenStreetMapElementType.Relation)
.id(1L)

assertAll {
assertThat(osmBuilder).prop(OpenStreetMapElementBuilder::hasEnoughDataToBuild).isTrue()

assertThat(osmBuilder.build()).isNotNull().all {
prop(OpenStreetMapElement::type).isEqualTo(OpenStreetMapElementType.Relation)
prop(OpenStreetMapElement::id).isEqualTo(1L)
}
}
}

@Test
internal fun `should populate a OpenStreetMap element builder with all properties from an GeographicLocation model`() {
val osm = aPodcastindexOpenStreetMapElement()
val osmBuilder = OpenStreetMapElement.builder().applyFrom(osm)

assertAll {
assertThat(osmBuilder).prop(OpenStreetMapElementBuilder::hasEnoughDataToBuild).isTrue()

assertThat(osmBuilder.build()).isNotNull().isEqualTo(osm)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import assertk.assertions.isNull
import assertk.assertions.isTrue
import assertk.assertions.prop
import dev.stalla.builder.PodcastindexLocationBuilder
import dev.stalla.model.aPodcastindexGeoLocation
import dev.stalla.model.aPodcastindexGeographicLocation
import dev.stalla.model.aPodcastindexOpenStreetMapElement
import dev.stalla.model.anEpisodePodcastindexLocation
import dev.stalla.model.podcastindex.PodcastindexLocation
Expand All @@ -32,7 +32,7 @@ internal class ValidatingPodcastindexLocationBuilderTest {
@Test
internal fun `should not build an Podcastindex Location with when the name field is missing`() {
val locationBuilder = ValidatingPodcastindexLocationBuilder()
.geo(aPodcastindexGeoLocation())
.geo(aPodcastindexGeographicLocation())

assertAll {
assertThat(locationBuilder).prop(PodcastindexLocationBuilder::hasEnoughDataToBuild).isFalse()
Expand Down Expand Up @@ -61,15 +61,15 @@ internal class ValidatingPodcastindexLocationBuilderTest {
internal fun `should build an Podcastindex Location with all the added entries to its fields`() {
val locationBuilder = ValidatingPodcastindexLocationBuilder()
.name("name")
.geo(aPodcastindexGeoLocation())
.geo(aPodcastindexGeographicLocation())
.osm(aPodcastindexOpenStreetMapElement())

assertAll {
assertThat(locationBuilder).prop(PodcastindexLocationBuilder::hasEnoughDataToBuild).isTrue()

assertThat(locationBuilder.build()).isNotNull().all {
prop(PodcastindexLocation::name).isEqualTo("name")
prop(PodcastindexLocation::geo).isEqualTo(aPodcastindexGeoLocation())
prop(PodcastindexLocation::geo).isEqualTo(aPodcastindexGeographicLocation())
prop(PodcastindexLocation::osm).isEqualTo(aPodcastindexOpenStreetMapElement())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/dev/stalla/model/EpisodeFixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ internal fun anEpisodePodcastindexPerson(
@JvmOverloads
internal fun anEpisodePodcastindexLocation(
name: String = "episode podcastindex location name",
geo: GeographicLocation? = aPodcastindexGeoLocation(),
geo: GeographicLocation? = aPodcastindexGeographicLocation(),
osm: OpenStreetMapElement? = aPodcastindexOpenStreetMapElement()
) = PodcastindexLocation(name, geo, osm)

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/dev/stalla/model/Fixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal fun aGoogleplayCategory(
) = category

@JvmOverloads
internal fun aPodcastindexGeoLocation(
internal fun aPodcastindexGeographicLocation(
coordA: Double = 48.20849,
coordB: Double = 16.37208,
coordC: Double? = 5.0,
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/dev/stalla/model/PodcastFixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ internal fun aPodcastPodcastindexPerson(
@JvmOverloads
internal fun aPodcastPodcastindexLocation(
name: String = "podcast podcastindex location name",
geo: GeographicLocation? = aPodcastindexGeoLocation(),
geo: GeographicLocation? = aPodcastindexGeographicLocation(),
osm: OpenStreetMapElement? = aPodcastindexOpenStreetMapElement()
) = PodcastindexLocation(name, geo, osm)

0 comments on commit 3027242

Please sign in to comment.