diff --git a/.gitignore b/.gitignore index 0a8704c..ab425e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,113 @@ -build/ -.gradle/ -*.ipr + +# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,gradle +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij+all,gradle + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + *.iml -*.iws \ No newline at end of file +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +# End of https://www.toptal.com/developers/gitignore/api/intellij+all,gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 888e0b1..0000000 --- a/build.gradle +++ /dev/null @@ -1,37 +0,0 @@ -buildscript { - ext { - versions = [ - hamkrest: "1.4.0.0", - junit: "1.0.0-M4", - jupiter: "5.0.0-M4", - kotlin: "1.1.2", - spek: "1.1.1" - ] - } - - repositories { - jcenter() - } - - dependencies { - classpath "org.junit.platform:junit-platform-gradle-plugin:${versions.junit}" - classpath "com.netflix.nebula:nebula-kotlin-plugin:${versions.kotlin}" - } -} - -subprojects { - apply plugin: "java" - apply plugin: "org.junit.platform.gradle.plugin" - - repositories { - jcenter() - } - - dependencies { - testCompile "org.junit.jupiter:junit-jupiter-api:${versions.jupiter}" - testRuntime "org.junit.jupiter:junit-jupiter-engine:${versions.jupiter}" - } - - sourceCompatibility = 1.8 - targetCompatibility = 1.8 -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..e69de29 diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..9dcdc72 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,8 @@ + +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() // so that external plugins can be resolved in dependencies section +} diff --git a/buildSrc/src/main/kotlin/test-clock-conventions.gradle.kts b/buildSrc/src/main/kotlin/test-clock-conventions.gradle.kts new file mode 100644 index 0000000..bf22cf5 --- /dev/null +++ b/buildSrc/src/main/kotlin/test-clock-conventions.gradle.kts @@ -0,0 +1,19 @@ +plugins { + java +} + +repositories { + mavenCentral() + jcenter() +} +val junit5Version: String by project + +dependencies { + testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version") +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..80a1d28 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +junit5Version = 5.7.0 +kotestVersion = 4.3.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 85aef70..666595e 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9e89b67..4684e09 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 19 21:40:25 PDT 2017 +#Thu Dec 31 12:18:29 CST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index bad7f05..0000000 --- a/settings.gradle +++ /dev/null @@ -1,16 +0,0 @@ -include "test-clock-core", - "test-clock-kotlin" - -rootProject.name = "test-clock" - -def setBuildFile(project) { - project.buildFileName = "${project.name}.gradle" - project.children.each { - setBuildFile(it) - } -} - -rootProject.children.each { - setBuildFile it -} - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..ed8f3f7 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,4 @@ +include("test-clock-core","test-clock-kotlin") + +rootProject.name = "test-clock" + diff --git a/test-clock-core/build.gradle.kts b/test-clock-core/build.gradle.kts new file mode 100644 index 0000000..98f140d --- /dev/null +++ b/test-clock-core/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("test-clock-conventions") +} + +dependencies { + implementation("com.google.code.findbugs:jsr305:3.0.2") +} diff --git a/test-clock-core/src/test/java/io/github/robfletcher/time/MutableClockTests.java b/test-clock-core/src/test/java/io/github/robfletcher/time/MutableClockTests.java index dffc77d..ad10bbe 100644 --- a/test-clock-core/src/test/java/io/github/robfletcher/time/MutableClockTests.java +++ b/test-clock-core/src/test/java/io/github/robfletcher/time/MutableClockTests.java @@ -55,4 +55,4 @@ void canChangeInstant() { testClock.instant(fixedClock.instant()); assertEquals(testClock.instant(), fixedClock.instant()); } -} \ No newline at end of file +} diff --git a/test-clock-core/test-clock-core.gradle b/test-clock-core/test-clock-core.gradle deleted file mode 100644 index a7a1f40..0000000 --- a/test-clock-core/test-clock-core.gradle +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - compile "com.google.code.findbugs:jsr305:3.0.2" -} \ No newline at end of file diff --git a/test-clock-kotlin/build.gradle.kts b/test-clock-kotlin/build.gradle.kts new file mode 100644 index 0000000..78f82fd --- /dev/null +++ b/test-clock-kotlin/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + kotlin("jvm") version "1.4.21" + id("test-clock-conventions") +} +repositories { + mavenCentral() +} + +val kotestVersion: String by project + +dependencies { + implementation(project(":test-clock-core")) + testImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") + testImplementation("io.kotest:kotest-assertions-core:$kotestVersion") +} + +tasks.withType { + useJUnitPlatform() +} diff --git a/test-clock-kotlin/src/test/kotlin/io/github/robfletcher/time/MutableClockSpec.kt b/test-clock-kotlin/src/test/kotlin/io/github/robfletcher/time/MutableClockSpec.kt index ef3a903..b76af44 100644 --- a/test-clock-kotlin/src/test/kotlin/io/github/robfletcher/time/MutableClockSpec.kt +++ b/test-clock-kotlin/src/test/kotlin/io/github/robfletcher/time/MutableClockSpec.kt @@ -1,73 +1,52 @@ package io.github.robfletcher.time -import com.natpryce.hamkrest.equalTo -import com.natpryce.hamkrest.should.shouldMatch -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.given -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.api.dsl.on -import org.jetbrains.spek.api.lifecycle.CachingMode.SCOPE -import org.jetbrains.spek.subject.SubjectSpek +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe import java.time.Clock -import java.time.Clock.fixed import java.time.Duration import java.time.Instant.EPOCH import java.time.ZoneOffset.MAX import java.time.ZoneOffset.MIN -object MutableClockSpec : SubjectSpek({ +class MutableClockSpec : DescribeSpec({ - var fixedClock: Clock? = null + var fixedClock: Clock? = null - beforeGroup { - fixedClock = Clock.fixed(subject.instant(), subject.zone) - } - - describe("mutable clock") { - subject(SCOPE) { - mutableClock() - } - - it("is equal to a fixed clock with the same instant and zone") { - subject shouldMatch equalTo(fixedClock) - } - - it("is not equal to a fixed clock with a different instant") { - subject shouldMatch !equalTo(fixed(subject.instant.plusMillis(1), subject.zone)) - } - - it("is not equal to a fixed clock with a different time zone") { - subject.withZone(MIN) shouldMatch !equalTo(fixedClock!!.withZone(MAX)) - } - - describe("advancing time") { - on("advancing the clock") { - subject += Duration.ofHours(1) - } - - it("changes the instant reported by the clock") { - subject.instant shouldMatch equalTo(fixedClock!!.instant() + Duration.ofHours(1)) - } + describe("mutable clock") { + lateinit var subject: MutableClock + beforeEach { + subject = mutableClock() + fixedClock = Clock.fixed(subject.instant(), subject.zone) + } - given("and advanced again") { - on("advancing the clock again") { - subject += Duration.ofHours(1) + it("is equal to a fixed clock with the same instant and zone") { + subject shouldBe fixedClock } - it("changes the instant reported by the clock") { - subject.instant shouldMatch equalTo(fixedClock!!.instant() + Duration.ofHours(2)) + it("is not equal to a fixed clock with a different instant") { + subject shouldNotBe Clock.fixed(subject.instant.plusMillis(1), subject.zone) } - } - } - describe("changing the instant") { - on("changing the instant") { - subject.instant = EPOCH - } + it("is not equal to a fixed clock with a different time zone") { + subject.withZone(MIN) shouldNotBe fixedClock!!.withZone(MAX) + } - it("returns the new instant") { - subject.instant() shouldMatch equalTo(EPOCH) - } + describe("advancing time") { + it("changes the instant reported by the clock") { + subject += Duration.ofHours(1) + subject.instant shouldBe fixedClock!!.instant() + Duration.ofHours(1) + } + + describe("changing the instant") { + beforeEach { + subject.instant = EPOCH + + } + it("returns the new instant") { + subject.instant() shouldBe EPOCH + } + } + } } - } -}) \ No newline at end of file +}) diff --git a/test-clock-kotlin/test-clock-kotlin.gradle b/test-clock-kotlin/test-clock-kotlin.gradle deleted file mode 100644 index 4e114d7..0000000 --- a/test-clock-kotlin/test-clock-kotlin.gradle +++ /dev/null @@ -1,39 +0,0 @@ -apply plugin: "nebula.kotlin" - -repositories { - maven { url "http://dl.bintray.com/jetbrains/spek" } -} - -dependencies { - compile project(":test-clock-core") - testCompile "org.jetbrains.spek:spek-api:${versions.spek}" - testCompile "org.jetbrains.spek:spek-subject-extension:${versions.spek}" - testCompile "com.natpryce:hamkrest:${versions.hamkrest}" - testRuntime "org.jetbrains.spek:spek-junit-platform-engine:${versions.spek}" -} - -configurations.all { - resolutionStrategy { - eachDependency { details -> - if (details.requested.group == "org.jetbrains.kotlin") { - details.useVersion versions.kotlin - } - } - } -} - -compileKotlin { - kotlinOptions { - languageVersion = VersionNumber.parse(versions.kotlin).with { - "${it.major}.${it.minor}" - } - } -} - -junitPlatform { - filters { - engines { - include "spek" - } - } -}