Skip to content

Commit

Permalink
Remove FOSSA badge
Browse files Browse the repository at this point in the history
  • Loading branch information
cjaehnen committed Aug 12, 2024
1 parent 6549453 commit dcc7026
Show file tree
Hide file tree
Showing 16 changed files with 329 additions and 315 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[![Release Version](https://img.shields.io/github/release/opengoodio/kotlin-commons.svg)](https://github.com/opengoodio/kotlin-commons/releases/latest)
[![Maven Central](https://img.shields.io/maven-central/v/io.opengood.commons/kotlin-commons.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.opengood.commons%22%20AND%20a:%22kotlin-commons%22)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/opengoodio/kotlin-commons/master/LICENSE)
[![FOSSA](https://app.fossa.com/api/projects/custom%2B22161%2Fgit.luolix.top%2Fopengoodio%2Fkotlin-commons.svg?type=small)](https://app.fossa.com/projects/custom%2B22161%2Fgit.luolix.top%2Fopengoodio%2Fkotlin-commons?ref=badge_small)

Commons library containing reusable functions, extensions, and objects
for Kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldBeEmpty
import io.opengood.commons.kotlin.function.captureStdOut

class ArrayTest : FunSpec({
class ArrayTest :
FunSpec({

test("array of generic type printAll extension method prints all items to standard output") {
val expected =
"""
test("array of generic type printAll extension method prints all items to standard output") {
val expected =
"""
|Item #0: foo
|Item #1: bar
|
""".trimMargin()
""".trimMargin()

val output = captureStdOut { arrayOf("foo", "bar").printAll() }
val output = captureStdOut { arrayOf("foo", "bar").printAll() }

output shouldBe expected
}
output shouldBe expected
}

test("array of generic type printAll extension method does not print all items to standard output when none exist") {
val output = captureStdOut { emptyArray<String>().printAll() }
test("array of generic type printAll extension method does not print all items to standard output when none exist") {
val output = captureStdOut { emptyArray<String>().printAll() }

output.shouldBeEmpty()
}
})
output.shouldBeEmpty()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import io.kotest.matchers.shouldBe
import java.math.BigDecimal
import java.math.RoundingMode

class BigDecimalTest : FunSpec({
class BigDecimalTest :
FunSpec({

test("BigDecimal roundUp extension method returns value rounded to scale") {
BigDecimal(12.346).roundUp(2) shouldBe BigDecimal(12.35).setScale(2, RoundingMode.HALF_UP)
}
})
test("BigDecimal roundUp extension method returns value rounded to scale") {
BigDecimal(12.346).roundUp(2) shouldBe BigDecimal(12.35).setScale(2, RoundingMode.HALF_UP)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,80 @@ import io.kotest.matchers.booleans.shouldBeFalse
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.shouldBe

class ListTest : FunSpec({
class ListTest :
FunSpec({

test("list containsIgnoreCase extension method returns true when case insensitive string contained in list") {
val list = listOf("foo", "bar")
test("list containsIgnoreCase extension method returns true when case insensitive string contained in list") {
val list = listOf("foo", "bar")

list.containsIgnoreCase("foo").shouldBeTrue()
}
list.containsIgnoreCase("foo").shouldBeTrue()
}

test("list containsIgnoreCase extension method returns true when case sensitive string contained in list") {
val list = listOf("foo", "bar")
test("list containsIgnoreCase extension method returns true when case sensitive string contained in list") {
val list = listOf("foo", "bar")

list.containsIgnoreCase("Foo").shouldBeTrue()
}
list.containsIgnoreCase("Foo").shouldBeTrue()
}

test("list containsIgnoreCase extension method returns false when string not contained in list") {
val list = listOf("bar")
test("list containsIgnoreCase extension method returns false when string not contained in list") {
val list = listOf("bar")

list.containsIgnoreCase("foo").shouldBeFalse()
}
list.containsIgnoreCase("foo").shouldBeFalse()
}

test("list sortAscending extension method sorts list of maps keys in ascending order") {
val list =
listOf(
mapOf(
"foo" to "bar",
"baz" to "pas",
),
mapOf(
"foo" to "par",
"baz" to "taz",
),
)
test("list sortAscending extension method sorts list of maps keys in ascending order") {
val list =
listOf(
mapOf(
"foo" to "bar",
"baz" to "pas",
),
mapOf(
"foo" to "par",
"baz" to "taz",
),
)

val result = list.sortAscending("baz")
val result = list.sortAscending("baz")

result shouldBe
listOf(
mapOf(
"baz" to "pas",
"foo" to "bar",
),
mapOf(
"baz" to "taz",
"foo" to "par",
),
)
}
result shouldBe
listOf(
mapOf(
"baz" to "pas",
"foo" to "bar",
),
mapOf(
"baz" to "taz",
"foo" to "par",
),
)
}

test("list sortDescending extension method sorts list of maps keys in descending order") {
val list =
listOf(
mapOf(
"baz" to "pas",
"foo" to "bar",
),
mapOf(
"baz" to "taz",
"foo" to "par",
),
)
test("list sortDescending extension method sorts list of maps keys in descending order") {
val list =
listOf(
mapOf(
"baz" to "pas",
"foo" to "bar",
),
mapOf(
"baz" to "taz",
"foo" to "par",
),
)

val result = list.sortDescending("baz")
val result = list.sortDescending("baz")

result shouldBe
listOf(
mapOf(
"foo" to "par",
"baz" to "taz",
),
mapOf(
"foo" to "bar",
"baz" to "pas",
),
)
}
})
result shouldBe
listOf(
mapOf(
"foo" to "par",
"baz" to "taz",
),
mapOf(
"foo" to "bar",
"baz" to "pas",
),
)
}
})
131 changes: 66 additions & 65 deletions src/test/kotlin/io/opengood/commons/kotlin/extension/method/MapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,100 +9,101 @@ import io.kotest.matchers.maps.shouldNotContain
import io.kotest.matchers.shouldBe
import io.opengood.commons.kotlin.function.makeEntry

class MapTest : FunSpec({
class MapTest :
FunSpec({

test("map containsMultipleListItems extension method returns true when more than one item exists in values list for key") {
val map = mapOf("foo" to listOf("bar", "baz"))
test("map containsMultipleListItems extension method returns true when more than one item exists in values list for key") {
val map = mapOf("foo" to listOf("bar", "baz"))

map.containsMultipleListItems("foo").shouldBeTrue()
}
map.containsMultipleListItems("foo").shouldBeTrue()
}

test("map containsMultipleListItems extension method returns false when one item exists in values list for key") {
val map = mapOf("foo" to listOf("bar"))
test("map containsMultipleListItems extension method returns false when one item exists in values list for key") {
val map = mapOf("foo" to listOf("bar"))

map.containsMultipleListItems("foo").shouldBeFalse()
}
map.containsMultipleListItems("foo").shouldBeFalse()
}

test("map containsMultipleListItems extension method returns false when no items exist in values list for key") {
val map = mapOf("foo" to emptyList<String>())
test("map containsMultipleListItems extension method returns false when no items exist in values list for key") {
val map = mapOf("foo" to emptyList<String>())

map.containsMultipleListItems("foo").shouldBeFalse()
}
map.containsMultipleListItems("foo").shouldBeFalse()
}

test("map containsMultipleListItems extension method returns false when key does not exist") {
val map = emptyMap<String, List<String>>()
test("map containsMultipleListItems extension method returns false when key does not exist") {
val map = emptyMap<String, List<String>>()

map.containsMultipleListItems("foo").shouldBeFalse()
}
map.containsMultipleListItems("foo").shouldBeFalse()
}

test("map keyByIndex extension method returns key at specified index") {
val map = mapOf("foo" to "bar")
test("map keyByIndex extension method returns key at specified index") {
val map = mapOf("foo" to "bar")

map.keyByIndex(0) shouldBe "foo"
}
map.keyByIndex(0) shouldBe "foo"
}

test("map keyByIndex extension method throws exception when key does not exist") {
val map = emptyMap<String, String>()
test("map keyByIndex extension method throws exception when key does not exist") {
val map = emptyMap<String, String>()

shouldThrow<IndexOutOfBoundsException> {
map.keyByIndex(0)
shouldThrow<IndexOutOfBoundsException> {
map.keyByIndex(0)
}
}
}

test("map notContainsKey extension method returns true when key does not exist") {
val map = emptyMap<String, String>()
test("map notContainsKey extension method returns true when key does not exist") {
val map = emptyMap<String, String>()

map.notContainsKey("foo").shouldBeTrue()
}
map.notContainsKey("foo").shouldBeTrue()
}

test("map notContainsKey extension method returns false when key exists") {
val map = mapOf("foo" to "bar")
test("map notContainsKey extension method returns false when key exists") {
val map = mapOf("foo" to "bar")

map.notContainsKey("foo").shouldBeFalse()
}
map.notContainsKey("foo").shouldBeFalse()
}

test("map notContainsValue extension method returns true when value does not exist") {
val map = emptyMap<String, String>()
test("map notContainsValue extension method returns true when value does not exist") {
val map = emptyMap<String, String>()

map.notContainsValue("foo").shouldBeTrue()
}
map.notContainsValue("foo").shouldBeTrue()
}

test("map notContainsValue extension method returns false when value exists") {
val map = mapOf("foo" to "bar")
test("map notContainsValue extension method returns false when value exists") {
val map = mapOf("foo" to "bar")

map.notContainsValue("bar").shouldBeFalse()
}
map.notContainsValue("bar").shouldBeFalse()
}

test("map putIfNotAbsent extension method adds map entry to map when it does not exist") {
val map = mutableMapOf<String, String>()
val entry = makeEntry("foo", "bar")
test("map putIfNotAbsent extension method adds map entry to map when it does not exist") {
val map = mutableMapOf<String, String>()
val entry = makeEntry("foo", "bar")

map.putIfNotAbsent(entry)
map.putIfNotAbsent(entry)

map.shouldContain("foo", "bar")
}
map.shouldContain("foo", "bar")
}

test("map putIfNotAbsent extension method does not add map entry to map when it already exists") {
val map = mutableMapOf(Pair("foo", "bar"))
val entry = makeEntry("foo", "baz")
test("map putIfNotAbsent extension method does not add map entry to map when it already exists") {
val map = mutableMapOf(Pair("foo", "bar"))
val entry = makeEntry("foo", "baz")

map.putIfNotAbsent(entry)
map.putIfNotAbsent(entry)

map.shouldContain("foo", "bar")
map.shouldNotContain("foo", "baz")
}
map.shouldContain("foo", "bar")
map.shouldNotContain("foo", "baz")
}

test("map valueByIndex extension method returns value at specified index") {
val map = mapOf("foo" to "bar")
test("map valueByIndex extension method returns value at specified index") {
val map = mapOf("foo" to "bar")

map.valueByIndex(0) shouldBe "bar"
}
map.valueByIndex(0) shouldBe "bar"
}

test("map valueByIndex extension method throws exception when value does not exist") {
val map = emptyMap<String, String>()
test("map valueByIndex extension method throws exception when value does not exist") {
val map = emptyMap<String, String>()

shouldThrow<IndexOutOfBoundsException> {
map.valueByIndex(0)
shouldThrow<IndexOutOfBoundsException> {
map.valueByIndex(0)
}
}
}
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package io.opengood.commons.kotlin.extension.method
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class PairTest : FunSpec({
class PairTest :
FunSpec({

test("pair of generic types toEntry extension method returns map entry object") {
val result = Pair("foo", "bar").toEntry()
test("pair of generic types toEntry extension method returns map entry object") {
val result = Pair("foo", "bar").toEntry()

result.key shouldBe "foo"
result.value shouldBe "bar"
}
})
result.key shouldBe "foo"
result.value shouldBe "bar"
}
})
Loading

0 comments on commit dcc7026

Please sign in to comment.