Skip to content

Commit

Permalink
Merge tag '1.3.2' into develop
Browse files Browse the repository at this point in the history
1.3.2

- add `expectThrows<T> {...}` expression
- add: Throwable.should.haveCause(type)
- add: Expect<Duration> (java/kotlin)
  • Loading branch information
odd-poet committed Dec 13, 2024
2 parents c602f90 + 53e56b2 commit 393f6b7
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 30 deletions.
119 changes: 119 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
## Change History

## 1.3.2

date: 2024.12.14

- add `expectThrows<T> {...}` expression
- add: Throwable.should.haveCause(type)
- add: Expect<Duration> (java/kotlin)

## 1.3.1

date: 2022.02.01

- upgrade kotlin version to 1.3.30
- gradle version up to 7.3.1
- migrate junit 4 to junit 5
- add assertion for `ByteArray`, `Instant`
- fix: literalizer error for `LocalDateTime`
- refactor: make literalizer internal class

## 1.3.0

date: 2021.09.29

- kotlin version up : 1.4.31
- use junit 5
- some extensions added

## 1.2.2

date: 2019.04.18

- improve: literal for throwable object will show it's own message.

## 1.2.1

date: 2018.09.04

- fix: long collection would be printed with multiline in log
- add: `Map.should.haveEntries(size)`

## 1.2.0

date: 2018.09.04

- feature: could describe prop of subject in message log and exception message

## 1.1.2

date: 2018.09.04

- fix: scope of extension `Any.literal`

## 1.1.1

date: 2018.08.19

- change `should.be()` to compare with same type object.

## 1.1.0

date: 2018.08.19

- add assertions for `Array`
- add assertions for `File`

## 1.0.1

date: 2018.08.19

- modify logging for `InputStream.equalAsText()`

## 1.0.0

date: 2018.08.11

- add assertion for `Instant`

## 0.9.0

date: 2018.08.10

- upgrade kotlin : 1.2.60
- upgrade gradle : 4.9
- bintray plugin : 1.8.4
- add extension for 'Boolean'
- logging for 'expect { }.throws()'
- add assertions(`haveLengthWith`, `haveLenghIn`) for `String`
- add assertion(`beIn`) for `Number`
- add assertion(`equalAsText`) for `InputStream`
- fix: unchecked cast warning

## 0.8.4

date: 2017.07.26

- separate literal generator
- rename `satisfyThat` to `satisfyThatForNullable`
- add new method `satisfyThat` for non-nullable type
- add assertion `containString`, `containChar` to `String` type

## 0.8.2

date: 2017.07.13

- add javadoc Jar as artifact

## 0.8.1

date: 2017.07.13

- remove generic from final class extension: `Double`, `Float`, `Int`, `Long`

## 0.8.0

date: 2017.07.12

- initial release
57 changes: 31 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# kotlin-expect
# kotlin-expect

[![Build Status](https://travis-ci.org/odd-poet/kotlin-expect.svg?branch=master)](https://travis-ci.org/odd-poet/kotlin-expect)[![codecov](https://codecov.io/gh/odd-poet/kotlin-expect/branch/master/graph/badge.svg)](https://codecov.io/gh/odd-poet/kotlin-expect)

`kotlin-expect` is a assertion library for kotlin test. it's inspried by [Rspec Expectation].


## Setup
## Setup

```gradle
dependencies {
testCompile("net.oddpoet:kotlin-expect:1.3.1")
testCompile("net.oddpoet:kotlin-expect:1.3.2")
}
```

## Basic Usage
## Basic Usage

### `expect(s).to`

You can write an assertion for a subject in the form `expect(subject).to`.
You can write an assertion for a subject in the form `expect(subject).to`.

```kotlin
val list = listOf(1, 2, 3)
expect(list).to.haveSizeOf(3)
expect(list).to.satisfy { size == 3}
expect(list).to.satisfy { size == 3 }
expect(list).to.not.contain(5)
expect(list).to.containAll { it < 10 }
expect(list).to.not.beInstanceOf(Set::class)
Expand Down Expand Up @@ -49,6 +49,7 @@ expect(aList) {
it.should.containAny { it.lenngth < 2 }
}
```

### `expect { }.throws()`

An assertion for an exception can be written in the form `expect { ... }.throws()`.
Expand All @@ -67,7 +68,7 @@ expect {
```

## Write own your assertion

`Kotlin-expect` has built-in assertions for java base types(`String`, `Collection`, `Map`, `Number` and so on).
You can define new assertions for your class.
An assertion for a class is defined as an extension of the `Expect` class.
Expand All @@ -77,39 +78,43 @@ An assertion for a class is defined as an extension of the `Expect` class.
```kotlin
// for your classes
abstract class Person(
val name: String,
val birthdate: LocalDate)
val name: String,
val birthdate: LocalDate
)

class Employee(
name: String, birthdate: LocalDate,
val empNo: String?,
val dept: String?) : Person(name, birthdate)
name: String, birthdate: LocalDate,
val empNo: String?,
val dept: String?
) : Person(name, birthdate)
```

```kotlin
// you can write your own assertion
fun <T : Person> Expect<T>.beUnderage() =
satisfyThat("be underage") {
it.birthdate.plusYears(19) > LocalDate.now()
}
satisfyThat("be underage") {
it.birthdate.plusYears(19) > LocalDate.now()
}

fun Expect<Employee>.beValid() =
satisfyThat("be valid") {
it.empNo != null && it.dept != null
}
satisfyThat("be valid") {
it.empNo != null && it.dept != null
}

fun Expect<Employee>.beAssignedTo(dept: String) =
satisfyThat("be assigned to $dept") {
it.dept == dept
}
satisfyThat("be assigned to $dept") {
it.dept == dept
}
```

```kotlin
// then you can use your assertion.
val emp = Employee(
"yunsang.choi",
LocalDate.of(1976, 4, 2),
"X00000",
"DevTeam")
"yunsang.choi",
LocalDate.of(1976, 4, 2),
"X00000",
"DevTeam"
)
expect(emp) {
it.should.beValid()
it.should.not.beUnderage()
Expand Down
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-library`
kotlin("jvm")
Expand All @@ -11,7 +9,7 @@ plugins {
}

group = "net.oddpoet"
version = "1.3.2-SNAPSHOT"
version = "1.3.2"
description = "rspec style assertion library for kotlin test"

repositories {
Expand Down Expand Up @@ -80,7 +78,6 @@ tasks {
}
}


publishing {
publications {
create<MavenPublication>("maven") {
Expand Down

0 comments on commit 393f6b7

Please sign in to comment.