Added more tests.

This commit is contained in:
Erik C. Thauvin 2021-07-10 02:31:54 -07:00
parent e8e7f65b2c
commit 352bdaeb0d
7 changed files with 102 additions and 34 deletions

View file

@ -78,6 +78,7 @@ detekt {
sonarqube {
properties {
property("sonar.projectName", "semver-gradle")
property("sonar.projectKey", "ethauvin_semver-gradle")
property("sonar.organization", "ethauvin-github")
property("sonar.host.url", "https://sonarcloud.io")

View file

@ -96,28 +96,29 @@ open class SemverConfig @Inject constructor(
val separator: String
get() = semVersion.separator
override fun toString(): String {
return "SemverConfig(" +
"properties='$properties', " +
"semverKey='$semverKey', " +
"majorKey='$majorKey', " +
"minorKey='$minorKey', " +
"patchKey='$patchKey', " +
"preReleaseKey='$preReleaseKey', " +
"preReleasePrefixKey='$preReleasePrefixKey', " +
"buildMetaKey='$buildMetaKey', " +
"buildMetaPrefixKey='$buildMetaPrefixKey', " +
"separator='$separatorKey', " +
"keysPrefix='$keysPrefix', " +
"semver='$semver', " +
"major='$major', " +
"minor='$minor', " +
"patch='$patch', " +
"preRelease='$preRelease', " +
"buildMeta='$buildMeta', " +
"preReleasePrefix='$preReleasePrefix', " +
"buildMetaPrefix='$buildMetaPrefix', " +
"separator='$separator'" +
')'
return mapOf(
Pair("properties", properties),
Pair("semverKey", semverKey),
Pair("majorKey", majorKey),
Pair("minorKey", minorKey),
Pair("patchKey", patchKey),
Pair("preReleaseKey", preReleaseKey),
Pair("preReleasePrefixKey", preReleasePrefixKey),
Pair("buildMetaKey", buildMetaKey),
Pair("buildMetaPrefixKey", buildMetaPrefixKey),
Pair("separator", separatorKey),
Pair("keysPrefix", keysPrefix),
Pair("semver", semver),
Pair("major", major),
Pair("minor", minor),
Pair("patch", patch),
Pair("preRelease", preRelease),
Pair("buildMeta", buildMeta),
Pair("preReleasePrefix", preReleasePrefix),
Pair("buildMetaPrefix", buildMetaPrefix),
Pair("separator", separator)
).toString()
}
}

View file

@ -70,16 +70,5 @@ class Version {
if (isPatch) patch++
}
override fun toString(): String {
return "Version(" +
"major='$major', " +
"minor='$minor', " +
"patch='$patch', " +
"preRelease='$preRelease', " +
"preReleasePrefix='$preReleasePrefix', " +
"buildMeta='$buildMeta', " +
"buildMetaPrefix='$buildMetaPrefix', " +
"separator='$separator', " +
')'
}
override fun toString() = semver
}

View file

@ -69,6 +69,11 @@ class SemverConfigTest {
}
assertEquals(config.properties, "version.properties", "config.properties should be version.properties")
assertTrue(
config.toString().contains("properties=${SemverConfig.DEFAULT_PROPERTIES}"),
"toString contains default properties"
)
}
@Test

View file

@ -0,0 +1,58 @@
/*
* testSortedProperties.kt
*
* Copyright (c) 2018-2021, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of this project nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.gradle.semver
import kotlin.test.Test
import kotlin.test.assertEquals
class SortedPropertiesTest {
@Test
fun testSortedProperties() {
val props = SortedProperties()
val fruits = setOf("Avocado", "Tomato", "apple", "banana", "cucumber", "zucchini")
fruits.reversed().forEach {
props[it] = "test"
}
val keys = props.keys().iterator()
fruits.forEach {
assertEquals(it, keys.next(), "$it key")
}
val entries = props.entries.iterator()
fruits.forEach {
assertEquals(it, entries.next().key, "$it entry")
}
}
}

View file

@ -134,6 +134,16 @@ class UtilsTest {
locked.delete()
}
@Test
fun testLoadIntProperty() {
val props = SortedProperties()
props["foo"] = "bar"
assertFailsWith<GradleException> { Utils.loadIntProperty(props, "foo", 1) }
assertEquals(Utils.loadIntProperty(props, "none", 1), 1, "default int value")
}
@Test
fun testPrefix() {
version.preReleasePrefix = "."
@ -198,6 +208,7 @@ class UtilsTest {
newPropsFile.delete()
System.getProperties().setProperty(config.semverKey, "3.2.2")
props["foo"] = "bar"
Utils.loadVersion(config, version, props)
assertEquals(version.semver, System.getProperty(config.semverKey), "versions should match")
}

View file

@ -49,6 +49,7 @@ class VersionTest {
assertEquals("+", version.buildMetaPrefix, "meta prefix should be +")
assertEquals(".", version.separator, "separator should be .")
assertEquals("1.0.0", version.semver, "version should be 1.0.0")
assertEquals(version.toString(), version.semver, "toString should be semver")
}
@Test
@ -102,5 +103,7 @@ class VersionTest {
version.separator = "-"
assertEquals("1-0-0--beta++007", version.semver, "should return 1-0-0--beta++007")
assertEquals(version.toString(), version.semver, "toString() should return semver")
}
}