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

Project update #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 112 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
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
37 changes: 0 additions & 37 deletions build.gradle

This file was deleted.

Empty file added build.gradle.kts
Empty file.
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal() // so that external plugins can be resolved in dependencies section
}
19 changes: 19 additions & 0 deletions buildSrc/src/main/kotlin/test-clock-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
junit5Version = 5.7.0
kotestVersion = 4.3.2
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions settings.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include("test-clock-core","test-clock-kotlin")

rootProject.name = "test-clock"

7 changes: 7 additions & 0 deletions test-clock-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("test-clock-conventions")
}

dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ void canChangeInstant() {
testClock.instant(fixedClock.instant());
assertEquals(testClock.instant(), fixedClock.instant());
}
}
}
3 changes: 0 additions & 3 deletions test-clock-core/test-clock-core.gradle

This file was deleted.

19 changes: 19 additions & 0 deletions test-clock-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -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<MutableClock>({
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
}
}
}
}
}
})
})
Loading