Skip to content

Commit

Permalink
Separate support for java.time types into new module
Browse files Browse the repository at this point in the history
See #113
  • Loading branch information
robfletcher committed Oct 11, 2018
1 parent 9c982ca commit 5a38aa7
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 17 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Any suggestions, [issue reports](https://github.com/robfletcher/strikt/issues),

Strikt is available from JCenter.

```groovy
```kotlin
repositories {
jcenter()
}
Expand All @@ -22,6 +22,24 @@ dependencies {

See the button below for the current version number.

## Additional Libraries

Strikt has the following additional libraries:

* `strikt-javatime` -- supports the JSR-310 `java.time` package.
* `strikt-protobuf` -- supports Protobuf / gRPC.

Versions are synchronized with the core Strikt library.

To install additional libraries include dependencies in your Gradle build.
For example:

```kotlin
dependencies {
testImplementation("time")
}
```

## Using Strikt

Please see the [project documentation](https://strikt.io/) and [API docs](https://strikt.io/api/strikt-core).
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rootProject.name = "strikt"

include("strikt-core", "strikt-protobuf", "site")
include("strikt-core", "strikt-protobuf", "strikt-java-time", "site")

enableFeaturePreview("STABLE_PUBLISHING")
7 changes: 6 additions & 1 deletion site/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import org.ajoberstar.gradle.git.ghpages.GithubPagesPluginExtension.DestinationC
import org.apache.tools.ant.filters.ConcatFilter
import org.apache.tools.ant.filters.ReplaceTokens
import org.jbake.gradle.JBakeTask
import org.jbake.gradle.JBakeServeTask

plugins {
id("org.ajoberstar.github-pages")
Expand Down Expand Up @@ -55,10 +56,14 @@ val copyApiDocs = task<Copy>("copyApiDocs") {
}
}

tasks.withType<JBakeTask> {
val bake by tasks.getting(JBakeTask::class) {
dependsOn(copyApiDocs)
}

val bakePreview by tasks.getting(JBakeServeTask::class) {
dependsOn(bake)
}

tasks.getByName("clean").doFirst {
delete("$projectDir/src/jbake/content/api/")
}
Expand Down
2 changes: 1 addition & 1 deletion site/src/jbake/assets/css/prism.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* PrismJS 1.15.0
https://prismjs.com/download.html#themes=prism-tomorrow&languages=clike+groovy+kotlin */
https://prismjs.com/download.html#themes=prism-tomorrow&languages=clike+kotlin */
/**
* prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
* Based on https://github.com/chriskempson/tomorrow-theme
Expand Down
3 changes: 1 addition & 2 deletions site/src/jbake/assets/js/prism.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions site/src/jbake/content/user-guide/additional-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ previousPage=custom-assertions.html
In addition to the core functionality provided by the `strikt-core` module, Strikt has the following optional modules:
## Java Time
Extensions for assertions and traversals on types from the `java.time` package.
See the [API docs](/api/strikt-java-time/).
Add the following to your dependencies:
```kotlin
testCompile("io.strikt:strikt-java-time:@version@")
```
## Protobuf
Extensions for testing code that uses Protobuf / gRPC.
See the [API docs](/api/strikt-protobuf/).
Add the following to your dependencies:
```groovy
testCompile "io.strikt:strikt-protobuf:@version@"
```kotlin
testCompile("io.strikt:strikt-protobuf:@version@")
```
4 changes: 2 additions & 2 deletions site/src/jbake/content/user-guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ It can be used with JUnit, Spek or any other runner that supports tests written
Strikt is available from JCenter.
Add the following to your `build.gradle`.
```groovy
```kotlin
repositories {
jcenter()
}
dependencies {
testCompile "io.strikt:strikt-core:@version@"
testCompile("io.strikt:strikt-core:@version@")
}
```
Expand Down
2 changes: 2 additions & 0 deletions site/src/jbake/templates/navbar.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
class="fas fa-book"></i></span><span>API</span></a>
<div class="navbar-dropdown is-right">
<a class="navbar-item" href="/api/strikt-core">strikt-core</a>
<a class="navbar-item"
href="/api/strikt-java-time">strikt-java-time</a>
<a class="navbar-item" href="/api/strikt-protobuf">strikt-protobuf</a>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions strikt-java-time/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("java-library")
id("nebula.kotlin")
id("published")
id("info.solidsoft.pitest")
}

dependencies {
api(project(":strikt-core"))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package strikt.assertions
package strikt.time

import strikt.api.Assertion
import java.time.Instant
Expand Down Expand Up @@ -62,7 +62,7 @@ fun <T : TemporalAccessor> Assertion.Builder<T>.isAfter(expected: TemporalAccess
* @see TemporalAccessor.get
*/
fun <T : TemporalAccessor> Assertion.Builder<T>.get(field: TemporalField): Assertion.Builder<Int> =
get(field.toString()) { this.get(field) }
get(field.toString()) { get(field) }

/**
* Maps an assertion on the subject to an assertion on the value of the
Expand All @@ -74,4 +74,4 @@ fun <T : TemporalAccessor> Assertion.Builder<T>.get(field: TemporalField): Asser
* @see TemporalAccessor.getLong
*/
fun <T : TemporalAccessor> Assertion.Builder<T>.getLong(field: TemporalField): Assertion.Builder<Long> =
get(field.toString()) { this.getLong(field) }
get(field.toString()) { getLong(field) }
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package strikt.assertions
package strikt.time

import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.DynamicTest.dynamicTest
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.TestFactory
import org.junit.jupiter.api.assertThrows
import org.opentest4j.AssertionFailedError
import strikt.api.expectThat
import strikt.fails
import strikt.assertions.isEqualTo
import java.time.DateTimeException
import java.time.Instant
import java.time.LocalDate
Expand Down Expand Up @@ -95,7 +96,7 @@ internal class TemporalAssertions {
Pair(YearMonth.from(today), today.minusMonths(1))
).map { (subject, expected) ->
dynamicTest("fails asserting $subject (${subject.javaClass.simpleName}) is before $expected (${expected.javaClass.simpleName})") {
fails {
assertThrows<AssertionFailedError> {
expectThat(subject).isBefore(expected)
}
}
Expand Down Expand Up @@ -173,7 +174,7 @@ internal class TemporalAssertions {
Pair(YearMonth.from(today), today.plusMonths(1))
).map { (subject, expected) ->
dynamicTest("fails asserting $subject (${subject.javaClass.simpleName}) is before $expected (${expected.javaClass.simpleName})") {
fails {
assertThrows<AssertionFailedError> {
expectThat(subject).isAfter(expected)
}
}
Expand Down

0 comments on commit 5a38aa7

Please sign in to comment.