Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute mockito with mockk and assertj with kluent #177

Merged
merged 43 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
71c4edb
Introduce spring-mockk
ursjoss May 2, 2020
e0cfee8
Add kluent to test-lib
ursjoss May 2, 2020
5c050ea
common: Use kluent, mockk, mockk-spring over assertj, mockito, mockit…
ursjoss May 2, 2020
5828b8b
public: Use kluent, mockk, mockk-spring over assertj, mockito, mockit…
ursjoss May 2, 2020
77782d2
core: Use kluent, mockk, mockk-spring over assertj, mockito, mockito-…
ursjoss May 2, 2020
b2bcebb
Remove assertj, mockito, mockito-kotlin except from web projects
ursjoss May 2, 2020
78375bf
Convert public-web tests to kotlin and remove mockito/mockito-kotlin,…
ursjoss May 2, 2020
8fcc8f0
Convert core-web tests to kotlin and remove mockito/mockito-kotlin, a…
ursjoss May 3, 2020
eaea5e0
Prevent transitive dependencies on mockito, hamcrest and assertj
ursjoss May 4, 2020
e39b2ef
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss May 9, 2020
ca33616
run check with stacktrace but not info. Try with daemon
ursjoss May 10, 2020
3140fa3
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss May 11, 2020
5544952
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss May 13, 2020
1854f4f
Merge remote-tracking branch 'origin/master' into chore/remove_mockit…
ursjoss May 18, 2020
0c5b99c
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss Jun 3, 2020
e98f02d
Clear all mocks after each test
ursjoss Jun 12, 2020
846be96
Fix mocking verification
ursjoss Jun 12, 2020
64ea85e
Merge remote-tracking branch 'origin/master' into chore/remove_mockit…
ursjoss Jun 12, 2020
59aa055
Merge remote-tracking branch 'origin/master' into chore/remove_mockit…
ursjoss Jun 21, 2020
9ba751a
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss Jun 21, 2020
5f7f4d2
Remove unused import
ursjoss Jun 21, 2020
46397fb
Merge branch 'master' into chore/remove_mockito_assertj
ursjoss Jun 28, 2020
9d1ca71
Fix test after merge issue
ursjoss Jun 28, 2020
1d296e6
ktlint autocorrection
ursjoss Jun 28, 2020
dae436c
ktlint manual changes
ursjoss Jun 28, 2020
98427e8
Avoid relaxing in some tests, avoid mocking if possible
ursjoss Jun 29, 2020
ffd3397
Fix test fixtures
ursjoss Jun 30, 2020
b878079
Raise MaxMetaspace to 3G
ursjoss Jun 30, 2020
3afbe1b
Increase maxHeapSize for tests
ursjoss Jun 30, 2020
0f84c84
Merge test task configuration
ursjoss Jun 30, 2020
38840f6
Raise memory for kotlin compiler
ursjoss Jun 30, 2020
0ac9401
Temporarily disable the slowest tests
ursjoss Jul 1, 2020
a2cf86a
Disable the slowest tests from July 10
ursjoss Jul 1, 2020
fb2fb61
Reactivate ResultPanelInEditModeTest
ursjoss Jul 1, 2020
bebfe23
Fix mocking of AjaxRequestTarget
ursjoss Jul 1, 2020
c60b859
Fix spring-boot-configuration-processor setup
ursjoss Jul 4, 2020
f128713
Cleanup tests
ursjoss Jul 4, 2020
49addb2
Use improved TestAjaxRequestHandler to considerably speed up the tests
ursjoss Jul 4, 2020
a5e946b
Use HashSet in TestAjaxRequestHandler - trading speed for maintaining…
ursjoss Jul 4, 2020
a70ecd5
Remove unmockkAll
ursjoss Jul 4, 2020
143fbd3
Revert "Use HashSet in TestAjaxRequestHandler - trading speed for mai…
ursjoss Jul 4, 2020
b22f981
Revert "Raise memory for kotlin compiler"
ursjoss Jul 5, 2020
0de4cd6
Revert "Raise MaxMetaspace to 3G"
ursjoss Jul 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
max_line_length = 150
tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
gradle-cache-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}

- name: Check with Gradle
run: ./gradlew check --no-daemon --info
run: ./gradlew check --stacktrace
9 changes: 5 additions & 4 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ NOTE: References to user stories are in the form Iteration/Story-Number.
.Changed
- Bumped detekt, jooq-modelator

//.Deprecated
//
//.Removed
//
.Deprecated

.Removed
- {url-issues}177[#177] Removed mockito, mockito-kotlin, assertj. Converted all tests to kotlin.

//.Fixed
//
//.Security
Expand Down
28 changes: 19 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,21 @@ subprojects {

compileOnly(Lib.jsr305())

testImplementation(Lib.springBootStarter("test").id) {
exclude("junit", "junit")
exclude("org.skyscreamer", "jsonassert")
exclude("org.mockito", "mockito-core")
exclude("org.mockito", "mockito-junit-jupiter")
exclude("org.hamcrest", "hamcrest")
exclude("org.assertj", "assertj-core")
}
testImplementation(Lib.spek("dsl-jvm"))
testImplementation(Lib.kluent())
testImplementation(Lib.kluent().id) {
exclude("org.mockito", "mockito-core")
exclude("com.nhaarman.mockitokotlin2", "mockito-kotlin")
}
testImplementation(Lib.mockk())
testImplementation(Lib.springMockk())
testImplementation(Lib.kwik("evaluator"))
testImplementation(Lib.kwik("generator-stdlib"))

Expand Down Expand Up @@ -183,6 +195,12 @@ subprojects {
useJUnitPlatform {
includeEngines("junit-jupiter", "spek2")
}
failFast = true
testLogging {
events = setOf(STARTED, FAILED, PASSED, SKIPPED)
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
}
withType<Jar> {
enabled = !isWebProject()
Expand Down Expand Up @@ -246,14 +264,6 @@ tasks {
dependsOn(projectsWithCoverage.map { it.tasks.getByName("jacocoTestReport") })
dependsOn(subprojects.map { it.tasks.getByName("detekt") })
}
withType<Test> {
failFast = true
testLogging {
events = setOf(STARTED, FAILED, PASSED, SKIPPED)
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
}
}

fun String.mayHaveTestCoverage(): Boolean = this !in testModules
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/Lib.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object Lib {
private const val kwikVersion = "0.6.0"
private const val kluentVersion = "1.61"
private const val mockkVersion = "1.10.0"
private const val springMockkVersion = "2.0.1"

private const val jsr305Version = "3.0.2"
//endregion
Expand Down Expand Up @@ -137,14 +138,13 @@ object Lib {
// Test Libraries

fun junit5(module: String = "") = Dep("org.junit.jupiter", "junit-jupiter${if (module.isNotBlank()) "-$module" else ""}", junit5Version)
fun mockito3(module: String) = Dep("org.mockito", "mockito-$module", mockitoVersion)
fun mockitoKotlin() = Dep("com.nhaarman.mockitokotlin2", "mockito-kotlin", mockitoKotlinVersion)
fun assertj() = Dep("org.assertj", "assertj-core")

fun testcontainers(module: String) = Dep("org.testcontainers", module, testcontainersVersion)
fun equalsverifier() = Dep("nl.jqno.equalsverifier", "equalsverifier", equalsverifierVersion)
fun spek(module: String) = Dep("org.spekframework.spek2", "spek-$module", spekVersion)
fun kluent() = Dep("org.amshove.kluent", "kluent", kluentVersion)
fun mockk() = Dep("io.mockk", "mockk", mockkVersion)
fun springMockk() = Dep("com.ninja-squad", "springmockk", springMockkVersion)
fun kwik(module: String) = Dep("com.github.jcornaz.kwik", "kwik-$module-jvm", kwikVersion)

fun servletApi() = Dep("javax.servlet", "javax.servlet-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ enum class CodeClassId(val id: Int) {
CC8(8);

companion object {
private val ID2ENUM: Map<Int, CodeClassId> = values().map { it.id to it }.toMap()
private val ID2ENUM: Map<Int, CodeClassId> = values().associateBy { it.id }

fun fromId(id: Int): java.util.Optional<CodeClassId> {
return java.util.Optional.ofNullable(ID2ENUM[id])
}
fun fromId(id: Int): java.util.Optional<CodeClassId> =
java.util.Optional.ofNullable(ID2ENUM[id])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ open class ScipamatoEntity(
VERSION("version");
}

override fun toString(): String = "ScipamatoEntity[created=$created,lastModified=$lastModified,version=$version]"
override fun toString(): String =
"ScipamatoEntity[created=$created,lastModified=$lastModified,version=$version]"

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
return (version == (other as ScipamatoEntity).version)
}

override fun hashCode(): Int {
return version
}
override fun hashCode(): Int = version

companion object {
private const val serialVersionUID = 1L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package ch.difty.scipamato.common.entity

import nl.jqno.equalsverifier.EqualsVerifier
import nl.jqno.equalsverifier.Warning
import org.amshove.kluent.shouldBeEmpty
import org.amshove.kluent.shouldBeEqualTo
import org.assertj.core.api.Assertions.assertThat
import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldContainSame
import org.junit.jupiter.api.Test

@Suppress("PrivatePropertyName", "SpellCheckingInspection", "LocalVariableName")
Expand Down Expand Up @@ -68,66 +70,60 @@ class AbstractDefinitionEntityTest {

@Test
fun entity_canGetMainLanguageCode() {
assertThat(tde.mainLanguageCode).isEqualTo("de")
tde.mainLanguageCode shouldBeEqualTo "de"
}

@Test
fun entity_canGetName() {
assertThat(tde.name).isEqualTo("mainName")
tde.name shouldBeEqualTo "mainName"
}

@Test
fun definitionEntity_canChangeName() {
tde.name = "foo"
assertThat(tde.name).isEqualTo("foo")
tde.name shouldBeEqualTo "foo"
}

@Test
fun entity_canGetTranslationsInLanguage_evenMultiple() {
assertThat(tde.getTranslations("de")).containsExactly(dt_de, dt_de2)
assertThat(tde.getTranslations("en")).containsExactly(dt_en)
assertThat(tde.getTranslations("fr")).containsExactly(dt_fr)
tde.getTranslations("de") shouldContainSame listOf(dt_de, dt_de2)
tde.getTranslations("en") shouldContainSame listOf(dt_en)
tde.getTranslations("fr") shouldContainSame listOf(dt_fr)
}

@Test
fun entity_gettingTranslationsInUndefinedLanguage_returnsEmptyList() {
assertThat(tde.getTranslations("es")).isEmpty()
tde.getTranslations("es").shouldBeEmpty()
}

@Test
fun entity_canGetTranslationsAsString() {
assertThat(tde.translationsAsString).isEqualTo("DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'")
tde.translationsAsString shouldBeEqualTo "DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'"
}

@Test
fun entity_canAddTranslationInLanguage() {
tde.addTranslation("EN", TestDefinitionTranslation(20, "en", "english2", 20))
assertThat(tde.translationsAsString).isEqualTo(
"DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'; EN: 'english2'"
)
tde.translationsAsString shouldBeEqualTo "DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'; EN: 'english2'"
}

@Test
fun entity_canRemoveTranslationInLanguage() {
assertThat(tde.translationsAsString).isEqualTo(
"DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'"
)
tde.translationsAsString shouldBeEqualTo "DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais'"
tde.removeTranslation(dt_de2)
assertThat(tde.translationsAsString).isEqualTo(
"DE: 'deutsch'; EN: 'english'; FR: 'francais'"
)
tde.translationsAsString shouldBeEqualTo "DE: 'deutsch'; EN: 'english'; FR: 'francais'"
}

@Test
fun entity_gettingTranslationsAsString_withNoTranslations_returnsNull() {
assertThat(tde_wo_transl.translationsAsString).isNull()
tde_wo_transl.translationsAsString.shouldBeNull()
}

@Test
fun entity_gettingTranslationsAsString_withSingleTranslationsInMainLanguage_WithNullName_returnsNA() {
val t = TestDefinitionTranslation(1, "de", null, 10)
val e = TestDefinitionEntity("de", "some", 1, arrayOf(t))
assertThat(e.translationsAsString).isEqualTo("DE: n.a.")
e.translationsAsString shouldBeEqualTo "DE: n.a."
}

@Test
Expand All @@ -136,112 +132,111 @@ class AbstractDefinitionEntityTest {
val t_en = TestDefinitionTranslation(2, "en", null, 11)
val t_fr = TestDefinitionTranslation(3, "fr", null, 12)
val e = TestDefinitionEntity("de", "some", 1, arrayOf(t_de, t_en, t_fr))
assertThat(e.translationsAsString).isEqualTo("DE: 'd'; EN: n.a.; FR: n.a.")
e.translationsAsString shouldBeEqualTo "DE: 'd'; EN: n.a.; FR: n.a."
}

@Test
fun entity_canSetNameInMainLanguage() {
assertThat(tde.getNameInLanguage("de")).isEqualTo("deutsch")
assertThat(tde.name).isEqualTo("mainName")
tde.getNameInLanguage("de") shouldBeEqualTo "deutsch"
tde.name shouldBeEqualTo "mainName"
tde.setNameInLanguage("de", "d")
assertThat(tde.getNameInLanguage("de")).isEqualTo("d")
assertThat(tde.name).isEqualTo("d")
tde.getNameInLanguage("de") shouldBeEqualTo "d"
tde.name shouldBeEqualTo "d"
}

@Test
fun entity_canSetNameInOtherDefinedLanguage() {
assertThat(tde.getNameInLanguage("en")).isEqualTo("english")
tde.getNameInLanguage("en") shouldBeEqualTo "english"
tde.setNameInLanguage("en", "e")
assertThat(tde.getNameInLanguage("en")).isEqualTo("e")
assertThat(tde.name).isEqualTo("mainName")
tde.getNameInLanguage("en") shouldBeEqualTo "e"
tde.name shouldBeEqualTo "mainName"
}

@Test
fun entity_settingNameInUndefinedLanguageHasNoEffect() {
assertThat(tde.getNameInLanguage("es")).isNull()
tde.getNameInLanguage("es").shouldBeNull()
tde.setNameInLanguage("es", "d")
assertThat(tde.getNameInLanguage("es")).isNull()
tde.getNameInLanguage("es").shouldBeNull()
}

@Test
fun entity_gettingNameInUndefinedLanguage_returnsNull() {
assertThat(tde.getNameInLanguage("es")).isNull()
tde.getNameInLanguage("es").shouldBeNull()
}

@Test
fun entity_withNoTranslations_gettingNameInNormallyDefinedLanguage_returnsNull() {
assertThat(tde_wo_transl.getNameInLanguage("es")).isNull()
tde_wo_transl.getNameInLanguage("es").shouldBeNull()
}

@Test
fun entity_canGetDisplayName() {
assertThat(tde.displayValue).isEqualTo("mainName")
tde.displayValue shouldBeEqualTo "mainName"
}

@Test
fun entity_canGet_nullSafeId() {
assertThat(tde.nullSafeId).isEqualTo("foo")
tde.nullSafeId shouldBeEqualTo "foo"
}

@Test
fun entity_testingToString() {
assertThat(tde.toString()).isEqualTo(
tde.toString() shouldBeEqualTo
"AbstractDefinitionEntity[translations=DE: 'deutsch','deutsch2'; EN: 'english'; FR: 'francais', " +
"mainLanguageCode=de, name=mainName]"
)
"mainLanguageCode=de, name=mainName]"
}

@Test
fun entity_settingVersionNull_resultsInZero() {
assertThat(tde_wo_transl_versionNull.version).isEqualTo(0)
tde_wo_transl_versionNull.version shouldBeEqualTo 0
}

@Test
fun translation_canGetId() {
assertThat(dt_de.id).isEqualTo(1)
dt_de.id shouldBeEqualTo 1
}

@Test
fun translation_canGetLangCode() {
assertThat(dt_de.langCode).isEqualTo("de")
dt_de.langCode shouldBeEqualTo "de"
}

@Test
fun translation_canGetName() {
assertThat(dt_de.name).isEqualTo("deutsch")
dt_de.name shouldBeEqualTo "deutsch"
}

@Test
fun translation_canGetDisplayValue() {
assertThat(dt_de.displayValue).isEqualTo("de: deutsch")
dt_de.displayValue shouldBeEqualTo "de: deutsch"
}

@Test
fun translation_canGetVersion() {
assertThat(dt_de.version).isEqualTo(10)
dt_de.version shouldBeEqualTo 10
}

@Test
fun translation_settingVersionNull_resultsInZero() {
val dt = TestDefinitionTranslation(1, "de", "deutsch")
assertThat(dt.version).isEqualTo(0)
dt.version shouldBeEqualTo 0
}

@Test
fun translation_testingToString() {
assertThat(dt_de.toString()).isEqualTo("AbstractDefinitionTranslation(id=1, langCode=de, name=deutsch)")
dt_de.toString() shouldBeEqualTo "AbstractDefinitionTranslation(id=1, langCode=de, name=deutsch)"
}

@Test
fun translationFields() {
assertThat(AbstractDefinitionTranslation.DefinitionTranslationFields.values()).containsExactly(
AbstractDefinitionTranslation.DefinitionTranslationFields.values() shouldContainSame listOf(
AbstractDefinitionTranslation.DefinitionTranslationFields.ID,
AbstractDefinitionTranslation.DefinitionTranslationFields.LANG_CODE,
AbstractDefinitionTranslation.DefinitionTranslationFields.NAME
)
assertThat(AbstractDefinitionTranslation.DefinitionTranslationFields.ID.fieldName).isEqualTo("id")
assertThat(AbstractDefinitionTranslation.DefinitionTranslationFields.LANG_CODE.fieldName).isEqualTo("langCode")
assertThat(AbstractDefinitionTranslation.DefinitionTranslationFields.NAME.fieldName).isEqualTo("name")
AbstractDefinitionTranslation.DefinitionTranslationFields.ID.fieldName shouldBeEqualTo "id"
AbstractDefinitionTranslation.DefinitionTranslationFields.LANG_CODE.fieldName shouldBeEqualTo "langCode"
AbstractDefinitionTranslation.DefinitionTranslationFields.NAME.fieldName shouldBeEqualTo "name"
}

@Test
Expand Down
Loading