ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - npryce/hamkrest: Hamcrest for Kotlin
Hamcrest for Kotlin. Contribute to npryce/hamkrest development by creating an account on GitHub.
Visit Site

GitHub - npryce/hamkrest: Hamcrest for Kotlin

GitHub - npryce/hamkrest: Hamcrest for Kotlin

HamKrest - Hamcrest for Kotlin

A reimplementation of Hamcrest to take advantage of Kotlin language features.

Kotlin Build Status Maven Central

Note: as of version 1.4.0.0, you must add kotlin-reflect to the classpath to use HamKrest's reflective features.

When working in Kotlin, Hamkrest provides these benefits over using the Java Hamcrest library:

  • Kotlin's type system means that developers don't have to worry about getting the variance of generic signatures right. Variance is defined on the abstract Matcher type and Kotlin makes sure composition and subtyping work together the way you expect.

  • Syntactic sugar. You can negate a matcher with the ! operator and compose matchers with infix and and or functions:

    import com.natpryce.hamkrest.assertion.assert
          
    ...
          
    assertThat("xyzzy", startsWith("x") and endsWith("y") and !containsSubstring("a"))
    
  • Easier to extend. You can convert named unary predicates into matchers.

    val isBlank = Matcher(String::isBlank)
    
    assertThat(input, isBlank)
    

    As a shortcut, you can pass named functions to the assertThat, and, or and many other functions that take a matcher.

    assertThat(input, String::isBlank)
    

    You can also convert a named binary predicate and the second argument to a matcher for first argument, which works well for extension methods.

    fun String.hasLength(n: Int): Boolean = this.length == n
    
    val isTheRightLength = Matcher(String::hasLength, 8)
    
    assertThat(secretCode, isTheRightLength)
    

    You can use function and property references to match features of a value:

    val isLongEnough = has(String::length, greaterThan(8))
    
    assertThat(password, isLongEnough)
    

    All of these shortcuts produce good, human-readable diagnostics.

    You can customise how diagnostics are generated by creating a project-specific assert object.

More documentation

More detailed documentation of specific library features is in the docs/ directory.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory