-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add builder tests for GeographicLocation and OpenStreetMapElement
- Loading branch information
Showing
6 changed files
with
122 additions
and
7 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/test/kotlin/dev/stalla/builder/validating/ValidatingGeographicLocationBuilderTest.kt
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,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) | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/kotlin/dev/stalla/builder/validating/ValidatingOpenStreetMapElementBuilderTest.kt
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,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) | ||
} | ||
} | ||
} |
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