diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..3bc19a60 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 + +[*.{yml,json}] +indent_size = 2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a18bd67..5b312f6c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [ ubuntu-latest, windows-latest, macOS-latest ] steps: - uses: actions/checkout@v2 diff --git a/.travis.yml b/.travis.yml index b9f6162a..757c0751 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,16 @@ matrix: - include: - - os: linux - jdk: oraclejdk8 - before_script: - - chmod u+x gradlew - script: - - ./gradlew build -PANDORID - - ./gradlew clean build -PJS -PNATIVE - - os: osx - osx_image: xcode8 - before_script: - - chmod u+x gradlew - script: - - ./gradlew build -PANDROID - - ./gradlew clean build -PJS -PNATIVE + include: + - os: linux + jdk: oraclejdk8 + before_script: + - chmod u+x gradlew + script: + - ./gradlew build -PANDORID + - ./gradlew clean build -PJS -PNATIVE + - os: osx + osx_image: xcode8 + before_script: + - chmod u+x gradlew + script: + - ./gradlew build -PANDROID + - ./gradlew clean build -PJS -PNATIVE diff --git a/AUTHORS.md b/AUTHORS.md index 248e2edf..530cf098 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,45 +1,45 @@ # Maintainers -1. Markus Amshove - [@MarkusAmshove](/~https://github.com/MarkusAmshove) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=MarkusAmshove)) +1. Markus Amshove: [@MarkusAmshove](/~https://github.com/MarkusAmshove) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=MarkusAmshove)) # Contributors -1. Andreas Volkmann - [@goreRatzete](/~https://github.com/goreRatzete) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=goreRatzete)) -2. Egor Andreevici - [@Egorand](/~https://github.com/Egorand) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Egorand)) -3. Karun Japhet - [@javatarz](/~https://github.com/javatarz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=javatarz)) -4. Eric Burke - [@eburke56](/~https://github.com/eburke56) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=eburke56)) -5. Günther Grill - [@guenhter](/~https://github.com/guenhter) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=guenhter)) -6. jpopadak -[@jpopadak](/~https://github.com/jpopadak) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jpopadak)) -7. Nikolai Hellwig - [@nhellwig](/~https://github.com/nhellwig) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=nhellwig)) -8. Greg Woodfill - [@gregwoodfill](/~https://github.com/gregwoodfill) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=gregwoodfill)) -9. cketti -[@cketti](/~https://github.com/cketti) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=cketti)) -10. Grzegorz Miszewski - [@miszmaniac](/~https://github.com/miszmaniac) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=miszmaniac)) -11. Yahor Berdnikau - [@Tapchicoma](/~https://github.com/Tapchicoma) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Tapchicoma)) -12. Alan Evans - [@westonal](/~https://github.com/westonal) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=westonal)) -13. Victor J - Reventos [@vjames19](/~https://github.com/vjames19) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=vjames19)) -14. B. K. Oxley - [@binkley](/~https://github.com/binkley) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=binkley)) -15. Vasili Chyrvon - [@Jeevuz](/~https://github.com/Jeevuz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Jeevuz)) -16. Yannick - [@fishb6nes](/~https://github.com/fishb6nes) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=fishb6nes)) -17. Ole Kristian - Sandum [@okkero](/~https://github.com/okkero) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=okkero)) -18. Gabriel Aumala - [@GAumala](/~https://github.com/GAumala) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=GAumala)) -19. Deconinck Alban - [@neyb](/~https://github.com/neyb) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=neyb)) -20. Fabrício Rissetto - [@fabriciorissetto](/~https://github.com/fabriciorissetto) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=fabriciorissetto)) -21. Vitus Ortner - [@vitusortner](/~https://github.com/vitusortner) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=vitusortner)) -22. Caleb Brinkman - [@floralvikings](/~https://github.com/floralvikings) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=floralvikings)) -23. Jonathan Cornaz - [@jcornaz](/~https://github.com/jcornaz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jcornaz)) -24. Ivan Atanasov - [@IvanAtanasov89](/~https://github.com/IvanAtanasov89) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=IvanAtanasov89)) -25. Ruben Gees - [@rubengees](/~https://github.com/rubengees) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=rubengees)) -26. Juechen Wang - [@wangjuechen](/~https://github.com/wangjuechen) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=wangjuechen)) -27. Anton Sheihman [@sheix_](/~https://github.com/sheix_) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=rubengees)) -28. Vaios Tsitsonis [@St4B](/~https://github.com/St4B) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=st4b)) -29. Jógvan Olsen - [@jeggy](/~https://github.com/jeggy) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jeggy)) -30. Yang C - [@ychescale9](/~https://github.com/ychescale9) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=ychescale9)) -31. Christian Ivicevic - [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=ChristianIvicevic)) -32. Ivan Mikhnovich - [@Murtaught](/~https://github.com/Murtaught) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Murtaught)) -33. Jc Miñarro - [@JcMinarro](/~https://github.com/JcMinarro) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=JcMinarro)) -34. Kshitij Patil [@Kshitij09](/~https://github.com/Kshitij09) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Kshitij09)) -35. Keivan Esbati - [@Tenkei](/~https://github.com/Tenkei) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Tenkei)) -36. Sam Neirinck - [@samneirinck](/~https://github.com/samneirinck) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=samneirinck)) -37. Maxim Ivanov [@drcolombo](/~https://github.com/drcolombo) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=drcolombo)) -38. Piotr Bakalarski [@piotrb5e3](/~https://github.com/piotrb5e3) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=piotrb5e3)) -39. Priyank Gupta [@priyaaank](/~https://github.com/priyaaank) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=priyaaank)) \ No newline at end of file +1. Andreas Volkmann: [@goreRatzete](/~https://github.com/goreRatzete) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=goreRatzete)) +2. Egor Andreevici: [@Egorand](/~https://github.com/Egorand) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Egorand)) +3. Karun Japhet: [@javatarz](/~https://github.com/javatarz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=javatarz)) +4. Eric Burke: [@eburke56](/~https://github.com/eburke56) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=eburke56)) +5. Günther Grill: [@guenhter](/~https://github.com/guenhter) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=guenhter)) +6. [@jpopadak](/~https://github.com/jpopadak) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jpopadak)) +7. Nikolai Hellwig: [@nhellwig](/~https://github.com/nhellwig) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=nhellwig)) +8. Greg Woodfill: [@gregwoodfill](/~https://github.com/gregwoodfill) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=gregwoodfill)) +9. [@cketti](/~https://github.com/cketti) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=cketti)) +10. Grzegorz Miszewski: [@miszmaniac](/~https://github.com/miszmaniac) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=miszmaniac)) +11. Yahor Berdnikau: [@Tapchicoma](/~https://github.com/Tapchicoma) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Tapchicoma)) +12. Alan Evans: [@westonal](/~https://github.com/westonal) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=westonal)) +13. Victor J - Reventos: [@vjames19](/~https://github.com/vjames19) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=vjames19)) +14. B. K. Oxley: [@binkley](/~https://github.com/binkley) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=binkley)) +15. Vasili Chyrvon: [@Jeevuz](/~https://github.com/Jeevuz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Jeevuz)) +16. Yannick: [@fishb6nes](/~https://github.com/fishb6nes) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=fishb6nes)) +17. Ole Kristian - Sandum: [@okkero](/~https://github.com/okkero) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=okkero)) +18. Gabriel Aumala: [@GAumala](/~https://github.com/GAumala) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=GAumala)) +19. Deconinck Alban: [@neyb](/~https://github.com/neyb) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=neyb)) +20. Fabrício Rissetto: [@fabriciorissetto](/~https://github.com/fabriciorissetto) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=fabriciorissetto)) +21. Vitus Ortner: [@vitusortner](/~https://github.com/vitusortner) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=vitusortner)) +22. Caleb Brinkman: [@floralvikings](/~https://github.com/floralvikings) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=floralvikings)) +23. Jonathan Cornaz: [@jcornaz](/~https://github.com/jcornaz) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jcornaz)) +24. Ivan Atanasov: [@IvanAtanasov89](/~https://github.com/IvanAtanasov89) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=IvanAtanasov89)) +25. Ruben Gees: [@rubengees](/~https://github.com/rubengees) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=rubengees)) +26. Juechen Wang: [@wangjuechen](/~https://github.com/wangjuechen) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=wangjuechen)) +27. Anton Sheihman: [@sheix_](/~https://github.com/sheix_) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=rubengees)) +28. Vaios Tsitsonis: [@St4B](/~https://github.com/St4B) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=st4b)) +29. Jógvan Olsen: [@jeggy](/~https://github.com/jeggy) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=jeggy)) +30. Yang C: [@ychescale9](/~https://github.com/ychescale9) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=ychescale9)) +31. Christian Ivicevic: [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=ChristianIvicevic)) +32. Ivan Mikhnovich: [@Murtaught](/~https://github.com/Murtaught) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Murtaught)) +33. Jc Miñarro: [@JcMinarro](/~https://github.com/JcMinarro) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=JcMinarro)) +34. Kshitij Patil: [@Kshitij09](/~https://github.com/Kshitij09) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Kshitij09)) +35. Keivan Esbati: [@Tenkei](/~https://github.com/Tenkei) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=Tenkei)) +36. Sam Neirinck: [@samneirinck](/~https://github.com/samneirinck) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=samneirinck)) +37. Maxim Ivanov: [@drcolombo](/~https://github.com/drcolombo) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=drcolombo)) +38. Piotr Bakalarski: [@piotrb5e3](/~https://github.com/piotrb5e3) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=piotrb5e3)) +39. Priyank Gupta: [@priyaaank](/~https://github.com/priyaaank) ([Contributions](/~https://github.com/MarkusAmshove/Kluent/commits?author=priyaaank)) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b017b4c..544f5fee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,268 +2,422 @@ * Add support for file assertions `shouldContainLineWithString` and `shouldNotContainLineWithString` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/192) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/204) | thanks to [@priyaaank](/~https://github.com/priyaaank) # 1.68 + * Move more Assertions to support `assertSoftly` and the IntelliJ Compare window -* Support diffs in IntelliJ (Compare window) | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/200) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/202) | thanks to [@drcolombo](/~https://github.com/drcolombo) +* Support diffs in IntelliJ (Compare window) | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/200) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/202) | thanks to [@drcolombo](/~https://github.com/drcolombo) # 1.67 -* Further improve assertSoftly compatibility | [Issue](/~https://github.com/MarkusAmshove/Kluent/pull/196) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/198) | thanks to [@piotrb5e3](/~https://github.com/piotrb5e3) + +* Further improve assertSoftly compatibility | [Issue](/~https://github.com/MarkusAmshove/Kluent/pull/196) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/198) | thanks to [@piotrb5e3](/~https://github.com/piotrb5e3) # 1.66 -* Fix exceptions failing silently with `assertSoftly` | [Issue](/~https://github.com/MarkusAmshove/Kluent/pull/196) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/197) | thanks to [@piotrb5e3](/~https://github.com/piotrb5e3) + +* Fix exceptions failing silently with `assertSoftly` | [Issue](/~https://github.com/MarkusAmshove/Kluent/pull/196) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/197) | thanks to [@piotrb5e3](/~https://github.com/piotrb5e3) # 1.65 -* Add soft assertions (`assertSoftly`) | [Docs](/~https://github.com/MarkusAmshove/Kluent/blob/master/docs/SoftlyAssertions.md) | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/178) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/185) | thanks to [@drcolombo](/~https://github.com/drcolombo) -* Various bug fixes in Equivalency functionality and message formatting | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/186) | thanks to [@drcolombo](/~https://github.com/drcolombo) -* New assertion `shouldBeEqualToIgnoringCase` for `Char[Sequence]` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/187) | thanks to [@drcolombo](/~https://github.com/drcolombo) -* **BREAKING** Remove mocking feature | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/168) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/188) | thanks to [@jleidgens](/~https://github.com/jleidgens) for reporting and [@drcolombo](/~https://github.com/drcolombo) for fixing + +* Add soft assertions (`assertSoftly`) + | [Docs](/~https://github.com/MarkusAmshove/Kluent/blob/master/docs/SoftlyAssertions.md) + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/178) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/185) + | thanks to [@drcolombo](/~https://github.com/drcolombo) +* Various bug fixes in Equivalency functionality and message formatting + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/186) | thanks to [@drcolombo](/~https://github.com/drcolombo) +* New assertion `shouldBeEqualToIgnoringCase` for `Char[Sequence]` + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/187) | thanks to [@drcolombo](/~https://github.com/drcolombo) +* **BREAKING** Remove mocking feature | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/168) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/188) | thanks to [@jleidgens](/~https://github.com/jleidgens) for + reporting and [@drcolombo](/~https://github.com/drcolombo) for fixing # 1.64 -* Add shouldBeEquivalentTo and shouldNotBeEquivalentTo | [Docs](/~https://github.com/MarkusAmshove/Kluent/blob/master/docs/Equivalency.md) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/184) | thanks to [@drcolombo](/~https://github.com/drcolombo) + +* Add shouldBeEquivalentTo and shouldNotBeEquivalentTo + | [Docs](/~https://github.com/MarkusAmshove/Kluent/blob/master/docs/Equivalency.md) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/184) | thanks to [@drcolombo](/~https://github.com/drcolombo) # 1.63 -* Make numerical backtick assertions accept Comparable | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/182) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/183) | thanks to [@CiprianU](/~https://github.com/CiprianU) + +* Make numerical backtick assertions accept Comparable | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/182) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/183) | thanks to [@CiprianU](/~https://github.com/CiprianU) # 1.62 -* Make shouldBeNear to consider NaN as being near itself | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/179) | thanks to [@jcornaz](/~https://github.com/jcornaz) -* Make the shouldBeLess/Greater family of assertion accept anything comparable | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/180) | thanks to [@jcornaz](/~https://github.com/jcornaz) + +* Make shouldBeNear to consider NaN as being near itself | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/179) | + thanks to [@jcornaz](/~https://github.com/jcornaz) +* Make the shouldBeLess/Greater family of assertion accept anything comparable + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/180) | thanks to [@jcornaz](/~https://github.com/jcornaz) # 1.61 -* Add `shouldBeAfter` and `shouldBeBefore` for `Instant` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/175) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/176) | thanks to [@samneirinck](/~https://github.com/samneirinck) + +* Add `shouldBeAfter` and `shouldBeBefore` for `Instant` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/175) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/176) | thanks to [@samneirinck](/~https://github.com/samneirinck) # 1.60 -* Add `shouldBeInRange` and `shouldNotBeInRange` for ClosedRanges | [Issue](/~https://github.com/markusamshove/kluent/issues/119) | [PR](/~https://github.com/markusamshove/kluent/pull/160) | thanks to [@javatarz](/~https://github.com/javatarz) and [@Kshitij09](/~https://github.com/Kshitij09) -* Implement VerificationMode `times` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/49) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/174) | thanks to [@Tenkei](/~https://github.com/Tenkei) + +* Add `shouldBeInRange` and `shouldNotBeInRange` for ClosedRanges + | [Issue](/~https://github.com/markusamshove/kluent/issues/119) | [PR](/~https://github.com/markusamshove/kluent/pull/160) + | thanks to [@javatarz](/~https://github.com/javatarz) and [@Kshitij09](/~https://github.com/Kshitij09) +* Implement VerificationMode `times` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/49) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/174) | thanks to [@Tenkei](/~https://github.com/Tenkei) # 1.59 -* Rename some assertions to keep consistent naming strategy | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/96) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/172/) | thanks to [@JcMinarro](/~https://github.com/JcMinarro) -* Support assertion for sorted collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/167) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/173/) | thanks to [@JcMinarro](/~https://github.com/JcMinarro) + +* Rename some assertions to keep consistent naming strategy | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/96) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/172/) | thanks to [@JcMinarro](/~https://github.com/JcMinarro) +* Support assertion for sorted collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/167) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/173/) | thanks to [@JcMinarro](/~https://github.com/JcMinarro) + # 1.58 -* Fix implementation of `Map.shouldContainSame` to compare all pairs |[Issue](/~https://github.com/MarkusAmshove/Kluent/issues/170) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/171) | thanks to [@Murtaught](/~https://github.com/Murtaught) + +* Fix implementation of `Map.shouldContainSame` to compare all pairs + |[Issue](/~https://github.com/MarkusAmshove/Kluent/issues/170) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/171) + | thanks to [@Murtaught](/~https://github.com/Murtaught) # 1.57 -* Add assertions for sequences | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/159) | thanks to [@jcornaz](/~https://github.com/jcornaz) -* Add `shouldHaveSingleItem` assertions for various arrays | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/165) | thanks to [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) -* Add `shouldContainAny` with lambda predicates | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/153) | thanks to [@javatarz](/~https://github.com/javatarz) -* Various gradle fixes | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/161) | thanks to [@javatarz](/~https://github.com/javatarz) + +* Add assertions for sequences | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/159) | thanks + to [@jcornaz](/~https://github.com/jcornaz) +* Add `shouldHaveSingleItem` assertions for various arrays | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/165) | + thanks to [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) +* Add `shouldContainAny` with lambda predicates | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/153) | thanks + to [@javatarz](/~https://github.com/javatarz) +* Various gradle fixes | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/161) | thanks + to [@javatarz](/~https://github.com/javatarz) # 1.56 -* Support for validating custom exception values | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/158) | thanks to [@jeggy](/~https://github.com/jeggy) + +* Support for validating custom exception values | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/158) | thanks + to [@jeggy](/~https://github.com/jeggy) # 1.55 -* Add `shouldBeNear` for `BigDecimal` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/155) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/156) | thanks to [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) + +* Add `shouldBeNear` for `BigDecimal` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/155) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/156) | thanks + to [@ChristianIvicevic](/~https://github.com/ChristianIvicevic) # 1.54 -* Support asserting suspend function | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/151) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/154) | thanks to [@ychescale9](/~https://github.com/ychescale9) + +* Support asserting suspend function | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/151) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/154) | thanks to [@ychescale9](/~https://github.com/ychescale9) # 1.53 -* Add `shouldEqualUnordered` and `shouldNotEqualUnordered` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/150) | thanks to [@jeggy](/~https://github.com/jeggy) + +* Add `shouldEqualUnordered` and `shouldNotEqualUnordered` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/150) | + thanks to [@jeggy](/~https://github.com/jeggy) # 1.52 -* Update mockito-kotlin to add Gradle 5.1.1 compatibility | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/147) | thanks to [@St4B](/~https://github.com/St4B) + +* Update mockito-kotlin to add Gradle 5.1.1 compatibility | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/147) | + thanks to [@St4B](/~https://github.com/St4B) # 1.51 -* Add predicate matchers for collections (`shouldMatchAtLeastOneOf` and `shouldMatchAllWith`) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/144) | thanks to [@sheix](/~https://github.com/sheix) + +* Add predicate matchers for collections (`shouldMatchAtLeastOneOf` and `shouldMatchAllWith`) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/144) | thanks to [@sheix](/~https://github.com/sheix) # 1.50 -* Add `shouldHaveSize` and `shouldHaveSingleItem` to collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/142) + +* Add `shouldHaveSize` and `shouldHaveSingleItem` to collections + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/142) # 1.49 -* Add `shouldBeNear` for Float and Double | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/139) | thanks to [@wangjuechen](/~https://github.com/wangjuechen) + +* Add `shouldBeNear` for Float and Double | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/139) | thanks + to [@wangjuechen](/~https://github.com/wangjuechen) # 1.48 -* Add `runtime` dependencies for Android | fixes [#130](/~https://github.com/MarkusAmshove/Kluent/issues/130) and [#133](/~https://github.com/MarkusAmshove/Kluent/issues/133) + +* Add `runtime` dependencies for Android | fixes [#130](/~https://github.com/MarkusAmshove/Kluent/issues/130) + and [#133](/~https://github.com/MarkusAmshove/Kluent/issues/133) # 1.47 -* Provide a wrapper function for asserting exceptions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/111) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/132) | thanks to [@rubengees](/~https://github.com/rubengees) + +* Provide a wrapper function for asserting exceptions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/111) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/132) | thanks to [@rubengees](/~https://github.com/rubengees) # 1.46 -* Add backtick-assertions for `should contain some` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/129) | thanks to [@IvanAtanasov89](/~https://github.com/IvanAtanasov89) + +* Add backtick-assertions for `should contain some` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/129) | thanks + to [@IvanAtanasov89](/~https://github.com/IvanAtanasov89) # 1.45 -* Fix `shouldNotThrow` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/128) | thanks to [@svenjacobs](/~https://github.com/svenjacobs) + +* Fix `shouldNotThrow` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/128) | thanks + to [@svenjacobs](/~https://github.com/svenjacobs) # 1.44 -* Implement kotlin `contracts` where possible | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/126) | thanks to [@jcornaz](/~https://github.com/jcornaz) -* Allow to call `isInstanceOf` and equivalent assertions on nullable types | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/127) | thanks to [@jcornaz](/~https://github.com/jcornaz) + +* Implement kotlin `contracts` where possible | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/126) | thanks + to [@jcornaz](/~https://github.com/jcornaz) +* Allow to call `isInstanceOf` and equivalent assertions on nullable types + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/127) | thanks to [@jcornaz](/~https://github.com/jcornaz) # 1.43 + * Update Kotlin to 1.3 -* Update `mockito-kotlin` to 2.0.0 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/116) | thanks to [@floralvikings](/~https://github.com/floralvikings) +* Update `mockito-kotlin` to 2.0.0 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/116) | thanks + to [@floralvikings](/~https://github.com/floralvikings) # 1.42 + * Use jvmTarget `1.6` for Android builds # 1.41 -* Implement numerical assertions for `BigDecimal` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/114) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/116) + +* Implement numerical assertions for `BigDecimal` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/114) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/116) # 1.40 -* Implement `shouldContainSame` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/113) | thanks to [@fabriciorissetto](/~https://github.com/fabriciorissetto) + +* Implement `shouldContainSame` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/113) | thanks + to [@fabriciorissetto](/~https://github.com/fabriciorissetto) # 1.39 -* Provide `shouldBeDigit` and `shouldNotBeDigit` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/107) | thanks to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) -* Implement `shouldHaveTheSameClassAs` and `shouldNotHaveTheSameClassAs` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/110) | thanks to [@igorwojda](/~https://github.com/igorwojda) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) -* Add checked exceptions to `itThrows` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/109) | thanks to [@thetric](/~https://github.com/thetric) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) + +* Provide `shouldBeDigit` and `shouldNotBeDigit` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/107) | thanks + to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) +* Implement `shouldHaveTheSameClassAs` and `shouldNotHaveTheSameClassAs` + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/110) | thanks to [@igorwojda](/~https://github.com/igorwojda) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) +* Add checked exceptions to `itThrows` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/109) | thanks + to [@thetric](/~https://github.com/thetric) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) * Restructure project into platform modules to prepare for 2.0 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) -* Create more overloads for Collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/108) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) +* Create more overloads for Collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/108) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/106) # 1.38 -* Return correct subtype of `CharSequence` assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/104) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/105) | thanks to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) + +* Return correct subtype of `CharSequence` assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/104) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/105) | thanks + to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) # 1.37 -* Add `shouldContainAll` for `CharSequence` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/100) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/102) | thanks to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) + +* Add `shouldContainAll` for `CharSequence` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/100) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/102) | thanks + to [@AndreasVolkmann](/~https://github.com/AndreasVolkmann) # 1.36 + * Assert that a CharSequence contains a Char | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/98) * Include the file path in `File` assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/99) # 1.35 -* Revisit return types of assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/93) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/94) + +* Revisit return types of assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/93) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/94) # 1.34 -* Allow chaining of assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/91) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/92) -* Return non-null instance when using `shouldNotBeNull` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/90) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) -* Add a more descriptive failure message for `shouldBeTrue` and `shouldBeFalse` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/89) | thanks to [@damelines](/~https://github.com/damelines) -* Add a more descriptive failure message for not null | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/88) | thanks to [@kamilchm](/~https://github.com/kamilchm) +* Allow chaining of assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/91) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/92) +* Return non-null instance when using `shouldNotBeNull` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/90) | + thanks to [@goreRatzete](/~https://github.com/goreRatzete) +* Add a more descriptive failure message for `shouldBeTrue` and `shouldBeFalse` + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/89) | thanks to [@damelines](/~https://github.com/damelines) +* Add a more descriptive failure message for not null | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/88) | + thanks to [@kamilchm](/~https://github.com/kamilchm) # 1.33 -* Add missing backtick verifier | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/87) | thanks to [@athkalia](/~https://github.com/athkalia) + +* Add missing backtick verifier | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/87) | thanks + to [@athkalia](/~https://github.com/athkalia) * Kluent now uses fixed dependency version # 1.32 -* More overloads for collection assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/82) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/85) | Issue by [@goreRatzete](/~https://github.com/goreRatzete) + +* More overloads for collection assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/82) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/85) | Issue by [@goreRatzete](/~https://github.com/goreRatzete) * Update to Kotlin 1.2 | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/80) -* `itAnswers` should allow original Mockito Answer types | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/83) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/84) | thanks to [@jpopadak](/~https://github.com/jpopadak) -* Support lambda logic assertion | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/77) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/81) | Issue by [@goreRatzete](/~https://github.com/goreratzete) +* `itAnswers` should allow original Mockito Answer types | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/83) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/84) | thanks to [@jpopadak](/~https://github.com/jpopadak) +* Support lambda logic assertion | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/77) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/81) | Issue by [@goreRatzete](/~https://github.com/goreratzete) # 1.31 -* Expect an Exception instance to be thrown compared by equals | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/78) | thanks to [@nhellwig](/~https://github.com/nhellwig) + +* Expect an Exception instance to be thrown compared by equals | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/78) | + thanks to [@nhellwig](/~https://github.com/nhellwig) # 1.30 -* Allow should(Not)Throw to on functions returning nullables | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/63) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/64) | thanks to [@gregwoodfill](/~https://github.com/gregwoodfill) + +* Allow should(Not)Throw to on functions returning nullables + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/63) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/64) | + thanks to [@gregwoodfill](/~https://github.com/gregwoodfill) * Update mockito-kotlin to kt1.1 | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/61) # 1.29 -* Add shouldContainSome and shouldContainNone to collections | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/59) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/60) + +* Add shouldContainSome and shouldContainNone to collections + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/59) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/60) # 1.28 -* Starting with this version, Kluent is now available for Android! Thanks to [@eburke](/~https://github.com/eburke56) for making this possible! | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/58) | thanks to [@eburke](/~https://github.com/eburke56) -* Fix order of arguments to assertArrayEquals() calls | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/56) | thanks to [@cketti](/~https://github.com/cketti) + +* Starting with this version, Kluent is now available for Android! Thanks to [@eburke](/~https://github.com/eburke56) for + making this possible! | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/58) | thanks + to [@eburke](/~https://github.com/eburke56) +* Fix order of arguments to assertArrayEquals() calls | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/56) | thanks + to [@cketti](/~https://github.com/cketti) # 1.27 -* Deprecate `shouldThrowTheException` for `shouldThrow` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/54) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) + +* Deprecate `shouldThrowTheException` for `shouldThrow` | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/54) | thanks + to [@goreRatzete](/~https://github.com/goreRatzete) * Update `mockito-kotlin` to 1.5.0 # 1.26 -* Fix wrong assertion in `shouldNotBeGreaterThan` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/51) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/52) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) and [@guenhter](/~https://github.com/guenhter) + +* Fix wrong assertion in `shouldNotBeGreaterThan` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/51) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/52) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) + and [@guenhter](/~https://github.com/guenhter) # 1.25 -* Allow Errors to be thrown from a stub | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/50) | thanks to [@guenhter](/~https://github.com/guenhter) + +* Allow Errors to be thrown from a stub | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/50) | thanks + to [@guenhter](/~https://github.com/guenhter) # 1.24 -* Add assertions for `java.io.File` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/47) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/48) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) + +* Add assertions for `java.io.File` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/47) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/48) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) # 1.23 -* Add shouldContainAll and shouldNotContainAny assertions | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/44) | thanks to [@Egorand](/~https://github.com/Egorand) + +* Add shouldContainAll and shouldNotContainAny assertions | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/44) | + thanks to [@Egorand](/~https://github.com/Egorand) # 1.22 -* Verify that a method was not called | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/43) | thanks to [@miszmaniac](/~https://github.com/miszmaniac) + +* Verify that a method was not called | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/43) | thanks + to [@miszmaniac](/~https://github.com/miszmaniac) # 1.21 -* Support primitive Arrays | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/42) | thanks to [@Tapchicoma](/~https://github.com/Tapchicoma) + +* Support primitive Arrays | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/42) | thanks + to [@Tapchicoma](/~https://github.com/Tapchicoma) # 1.20 -* Use `Throwable` instead of `Exception` as base type for asserts on `Exception`s | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/40) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/41) | thanks to [@westonal](/~https://github.com/westonal) + +* Use `Throwable` instead of `Exception` as base type for asserts on `Exception`s + | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/40) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/41) | + thanks to [@westonal](/~https://github.com/westonal) # 1.19 -* ExceptionResult is now Typed and withCause and withMessage are now fluent | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/38) | thanks to [@vjames19](/~https://github.com/vjames19) + +* ExceptionResult is now Typed and withCause and withMessage are now fluent + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/38) | thanks to [@vjames19](/~https://github.com/vjames19) # 1.18 -* Fix generation of maven poms | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/37) | thanks to [@binkley](/~https://github.com/binkley) + +* Fix generation of maven poms | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/37) | thanks + to [@binkley](/~https://github.com/binkley) # 1.17 -* Update Kotlin to 1.1.1 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/28) | thanks to [@Egorand](/~https://github.com/Egorand) -* Update Gradle to 3.4.1 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/29) | thanks to [@Egorand](/~https://github.com/Egorand) -* Fix compiler warnings in tests | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/30) | thanks to [@Egorand](/~https://github.com/Egorand) -* Update JUnit and Mockito | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/31) | thanks to [@Jeevuz](/~https://github.com/Jeevuz)) -* Fix reversed message in ShouldNotThrow | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/33) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/34) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) -* Use mockito-kotlin for mocking | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/32) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/35) | thanks to [@fishb6nes](/~https://github.com/fishb6nes) -* Add Assertions for LocalDateTime, LocalTime, LocalDate | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/36) | [Documentation](JavaTime.md) + +* Update Kotlin to 1.1.1 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/28) | thanks + to [@Egorand](/~https://github.com/Egorand) +* Update Gradle to 3.4.1 | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/29) | thanks + to [@Egorand](/~https://github.com/Egorand) +* Fix compiler warnings in tests | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/30) | thanks + to [@Egorand](/~https://github.com/Egorand) +* Update JUnit and Mockito | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/31) | thanks + to [@Jeevuz](/~https://github.com/Jeevuz)) +* Fix reversed message in ShouldNotThrow | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/33) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/34) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) +* Use mockito-kotlin for mocking | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/32) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/35) | thanks to [@fishb6nes](/~https://github.com/fishb6nes) +* Add Assertions for LocalDateTime, LocalTime, LocalDate | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/36) + | [Documentation](JavaTime.md) # 1.16 + * Update Kotlin to 1.1.0 * Correct assertion message for `Collection.shouldBeEmpty` | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/27) # 1.15 + * Rework failure messages of shouldNotContain assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/20) * Extract assertions into different files -* Add withCause for Exception-Assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/24) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/25) | thanks to [@okkero](/~https://github.com/okkero) -* Add common non infix assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/21) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/26) +* Add withCause for Exception-Assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/24) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/25) | thanks to [@okkero](/~https://github.com/okkero) +* Add common non infix assertions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/21) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/26) # 1.14 -* Introduce numerical operations | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/17) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/18) - shouldBeGreaterOrEqualTo +* Introduce numerical operations | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/17) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/18) + + shouldBeGreaterOrEqualTo - shouldBeGreaterThan + shouldBeGreaterThan - shouldBeLessOrEqualTo + shouldBeLessOrEqualTo - shouldBeLessThan + shouldBeLessThan - shouldBePositive + shouldBePositive - shouldBeNegative + shouldBeNegative - shouldBeInRange + shouldBeInRange # 1.13 -* Provide methods to check if an object is a given instance | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/16) | thanks to [@GAumala](/~https://github.com/GAumala) - shouldBeInstanceOf +* Provide methods to check if an object is a given instance | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/16) | + thanks to [@GAumala](/~https://github.com/GAumala) - shouldNotBeInstanceOf + shouldBeInstanceOf + + shouldNotBeInstanceOf # 1.12 -* Update Kotlin to 1.0.6 | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/14) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/15) + +* Update Kotlin to 1.0.6 | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/14) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/15) # 1.11 -* Provide methods for common String operations | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/12) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/13) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) - shouldStartWith +* Provide methods for common String operations | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/12) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/13) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) - shouldNotStartWith + shouldStartWith - shouldEndWith + shouldNotStartWith - shouldNotEndWith + shouldEndWith - shouldContain + shouldNotEndWith - shouldNotContain + shouldContain - shouldMatch + shouldNotContain - shouldNotMatch + shouldMatch + + shouldNotMatch # 1.10 -* Provide methods to test maps | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/10) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/11) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) +* Provide methods to test maps | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/10) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/11) | thanks to [@goreRatzete](/~https://github.com/goreRatzete) + + shouldHaveKey + + shouldNotHaveKey + + shouldHaveValue + + shouldNotHaveValue - shouldHaveKey - - shouldNotHaveKey - - shouldHaveValue - - shouldNotHaveValue - - shouldContain (pair) - - shouldNotContain (pair) + shouldContain (pair) + shouldNotContain (pair) # 1.9 -* Allow subtyping of exceptions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/7) | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/8) | thanks to [@neyb](/~https://github.com/neyb) +* Allow subtyping of exceptions | [Issue](/~https://github.com/MarkusAmshove/Kluent/issues/7) + | [PR](/~https://github.com/MarkusAmshove/Kluent/pull/8) | thanks to [@neyb](/~https://github.com/neyb) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 8a0dfa5f..f462aab1 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,7 +2,10 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making +participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, +disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, +religion, or sexual identity and orientation. ## Our Standards @@ -24,23 +27,35 @@ Examples of unacceptable behavior by participants include: ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take +appropriate and fair corrective action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, +issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the +project or its community. Examples of representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed representative at an online or offline +event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at scm@amshove.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at +scm@amshove.org. The project team will review and investigate all complaints, and will respond in a way that it deems +appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter +of an incident. Further details of specific enforcement policies may be posted separately. -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent +repercussions as determined by other members of the project's leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available +at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org + [version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d628c427..766fc682 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,8 @@ A lot of the assertions within this library come from the community, which is aw # Development Guide -We're looking for all kinds of contributions, may it be additional assertions, updates to the docs, better assertion failure messages or filing issues. +We're looking for all kinds of contributions, may it be additional assertions, updates to the docs, better assertion +failure messages or filing issues. ## GitHub Workflow @@ -27,8 +28,8 @@ We're looking for all kinds of contributions, may it be additional assertions, u $ ./gradlew build ``` - This will download gradle if it isn't already on your machine and also download all dependencies of Kluent. - Furthermore it'll build the project and execute all tests. + This will download gradle if it isn't already on your machine and also download all dependencies of Kluent. + Furthermore it'll build the project and execute all tests. 5. Create a branch for your bugfix or feature based off the `master` branch: @@ -36,7 +37,8 @@ We're looking for all kinds of contributions, may it be additional assertions, u $ git checkout -b master ``` -6. If the changes you make take a few days, be sure to occasionally pull the latest changes from `upstream`, to ensure that your local branch is up-to-date: +6. If the changes you make take a few days, be sure to occasionally pull the latest changes from `upstream`, to ensure + that your local branch is up-to-date: ```bash $ git pull upstream master @@ -51,9 +53,8 @@ We're looking for all kinds of contributions, may it be additional assertions, u 8. [Create a pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) on GitHub. - -NOTE: When the build fails after your changes and you don't know why, don't hesitate to create a pull request anyway, -we might be able to help you! +NOTE: When the build fails after your changes and you don't know why, don't hesitate to create a pull request anyway, we +might be able to help you! # Building Kluent @@ -61,13 +62,12 @@ All projects of Kluent are built with [Gradle](http://gradle.org/) The default `gradlew build` will only build the `common` and `jvm` module, to keep the build times as small as possible. -If you plan to submit a pull request, it is also fine if you just make sure it builds and tests against `common` and `jvm` (which `gradlew build` will make sure of), -because the rest of the heavy work will be done by Travis and AppVeyor. -That way you can keep your machine free from NodeJS and Kotlin Native :-) +If you plan to submit a pull request, it is also fine if you just make sure it builds and tests against `common` +and `jvm` (which `gradlew build` will make sure of), because the rest of the heavy work will be done by Travis and +AppVeyor. That way you can keep your machine free from NodeJS and Kotlin Native :-) -To build the Android library, pass the parameter `ANDROID` to Gradle. -This will build the `common` and `android` artifacts. -To pass the parameter, type: +To build the Android library, pass the parameter `ANDROID` to Gradle. This will build the `common` and `android` +artifacts. To pass the parameter, type: `gradlew build -PANDROID` @@ -79,8 +79,8 @@ To build native, pass: `gradlew build -PNATIVE` -In these cases, the JVM module will also be built, because it is our primary target and everything should pass on the JVM. -To skip the JVM build, e.g. for testing only against Native or JS, pass `SKIPVM`: +In these cases, the JVM module will also be built, because it is our primary target and everything should pass on the +JVM. To skip the JVM build, e.g. for testing only against Native or JS, pass `SKIPVM`: `gradlew build -PJS -PNATIVE -PSKIPJVM` @@ -88,22 +88,29 @@ This command will build `common`, `js`, `native`, but not `jvm`. ## Where to put new features -If you plan to add a feature (e.g. an Assertion), it would be nice to first try adding it to the `common` module, as it would then be available to all platforms. -If it uses specific APIs, like classes from the Java standard library, then it needs to go to the `jvm` module. - -If you're unsure where to put a feature, or if you want to put something in the `common` module which needs platform specific -implementations, you can have a look [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/Basic.kt) (`platformIsDigit` or `platformClassName`) -where a function in the `common` module calls a so called `expect` function, which is defined [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) -in the `common` module and has specific [JVM](/~https://github.com/MarkusAmshove/Kluent/blob/master/jvm/src/main/kotlin/org/amshove/kluent/internal/Platform.kt), +If you plan to add a feature (e.g. an Assertion), it would be nice to first try adding it to the `common` module, as it +would then be available to all platforms. If it uses specific APIs, like classes from the Java standard library, then it +needs to go to the `jvm` module. + +If you're unsure where to put a feature, or if you want to put something in the `common` module which needs platform +specific implementations, you can have a +look [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/Basic.kt) (`platformIsDigit` +or `platformClassName`) +where a function in the `common` module calls a so called `expect` function, which is +defined [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +in the `common` module and has +specific [JVM](/~https://github.com/MarkusAmshove/Kluent/blob/master/jvm/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +, [JS](/~https://github.com/MarkusAmshove/Kluent/blob/master/js/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) -and [Native](/~https://github.com/MarkusAmshove/Kluent/blob/master/native/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) implementation. +and [Native](/~https://github.com/MarkusAmshove/Kluent/blob/master/native/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +implementation. If you're still unsure how to make something platform independent, we can have a look together inside the PR :-) ## Compatibility with assertSoftly -When adding assertions, do not throw AssertionError directly. -Insead, use existing assertions, internal helpers or the `fail` method. -This way your assertion will be compatible with `assertSoftly`. + +When adding assertions, do not throw AssertionError directly. Insead, use existing assertions, internal helpers or +the `fail` method. This way your assertion will be compatible with `assertSoftly`. If your assertion can't fail softly, for example `fun T?.shouldNotBeNull(): T = ...`, then call `hardFail`. diff --git a/README.md b/README.md index 618129c4..599107bd 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,12 @@ [Kluent](https://markusamshove.github.io/Kluent/) is a "Fluent Assertions" library written specifically for Kotlin. -It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.html#infix-notation "Infix-Notation") and [Extension Functions](https://kotlinlang.org/docs/reference/extensions.html#extension-functions "Extension Functions") of Kotlin to provide a fluent wrapper around the JUnit-Assertions. +It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.html#infix-notation "Infix-Notation") +and [Extension Functions](https://kotlinlang.org/docs/reference/extensions.html#extension-functions "Extension Functions") +of Kotlin to provide a fluent wrapper around the JUnit-Assertions. [How to contribute](CONTRIBUTING.md) - [ ![Download](https://api.bintray.com/packages/markusamshove/maven/kluent/images/download.svg) ](https://bintray.com/markusamshove/maven/kluent/_latestVersion) ---------- @@ -22,7 +23,9 @@ Kluent is hosted [here at mavenCentral](https://mvnrepository.com/artifact/org.a Kluent-Android is hosted [here at mavenCentral](https://mvnrepository.com/artifact/org.amshove.kluent/kluent-android) ## Gradle + Replace {version} with the current version and chose one of the two artifacts, based on your target platform: + ```groovy // Add jcenter as a repository for dependencies repositories { @@ -42,6 +45,7 @@ dependencies { ``` ## Maven + Replace {version} with the current version ```xml @@ -65,7 +69,8 @@ Replace {version} with the current version # Examples -More examples can be seen on the [Site](https://markusamshove.github.io/Kluent/) or in the [tests](/~https://github.com/MarkusAmshove/Kluent/tree/master/src/test/kotlin/org/amshove/kluent/tests). +More examples can be seen on the [Site](https://markusamshove.github.io/Kluent/) or in +the [tests](/~https://github.com/MarkusAmshove/Kluent/tree/master/src/test/kotlin/org/amshove/kluent/tests). ### assertEquals ## @@ -87,6 +92,7 @@ val jon = Person("Jon", "Doe") val list = listOf(alice, jon) list shouldContain jon ``` + ## Using backticks Every method that is included in Kluent also has a "backtick version", to make it feel more like a describing sentence. @@ -100,6 +106,7 @@ Some examples: ``` ### assertNotEquals ## + ```kotlin "hello" `should not be equal to` "world" ``` @@ -110,13 +117,12 @@ All projects of Kluent are built with [Gradle](http://gradle.org/) The default `gradlew build` will only build the `common` and `jvm` module, to keep the build times as small as possible. -If you plan to submit a pull request, it is also fine if you just make sure it builds and tests against `common` and `jvm` (which `gradlew build` will make sure of), -because the rest of the heavy work will be done by Travis and AppVeyor. -That way you can keep your machine free from NodeJS and Kotlin Native :-) +If you plan to submit a pull request, it is also fine if you just make sure it builds and tests against `common` +and `jvm` (which `gradlew build` will make sure of), because the rest of the heavy work will be done by Travis and +AppVeyor. That way you can keep your machine free from NodeJS and Kotlin Native :-) -To build the Android library, pass the parameter `ANDROID` to Gradle. -This will build the `common` and `android` artifacts. -To pass the parameter, type: +To build the Android library, pass the parameter `ANDROID` to Gradle. This will build the `common` and `android` +artifacts. To pass the parameter, type: `gradlew build -PANDROID` @@ -128,8 +134,8 @@ To build native, pass: `gradlew build -PNATIVE` -In these cases, the JVM module will also be built, because it is our primary target and everything should pass on the JVM. -To skip the JVM build, e.g. for testing only against Native or JS, pass `SKIPVM`: +In these cases, the JVM module will also be built, because it is our primary target and everything should pass on the +JVM. To skip the JVM build, e.g. for testing only against Native or JS, pass `SKIPVM`: `gradlew build -PJS -PNATIVE -PSKIPJVM` @@ -137,18 +143,26 @@ This command will build `common`, `js`, `native`, but not `jvm`. ## Where to put new features -If you plan to add a feature (e.g. an Assertion), it would be nice to first try adding it to the `common` module, as it would then be available to all platforms. -If it uses specific APIs, like classes from the Java standard library, then it needs to go to the `jvm` module. - -If you're unsure where to put a feature, or if you want to put something in the `common` module which needs platform specific -implementations, you can have a look [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/Basic.kt) (`platformIsDigit` or `platformClassName`) -where a function in the `common` module calls a so called `expect` function, which is defined [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) -in the `common` module and has specific [JVM](/~https://github.com/MarkusAmshove/Kluent/blob/master/jvm/src/main/kotlin/org/amshove/kluent/internal/Platform.kt), +If you plan to add a feature (e.g. an Assertion), it would be nice to first try adding it to the `common` module, as it +would then be available to all platforms. If it uses specific APIs, like classes from the Java standard library, then it +needs to go to the `jvm` module. + +If you're unsure where to put a feature, or if you want to put something in the `common` module which needs platform +specific implementations, you can have a +look [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/Basic.kt) (`platformIsDigit` +or `platformClassName`) +where a function in the `common` module calls a so called `expect` function, which is +defined [here](/~https://github.com/MarkusAmshove/Kluent/blob/master/common/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +in the `common` module and has +specific [JVM](/~https://github.com/MarkusAmshove/Kluent/blob/master/jvm/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +, [JS](/~https://github.com/MarkusAmshove/Kluent/blob/master/js/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) -and [Native](/~https://github.com/MarkusAmshove/Kluent/blob/master/native/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) implementation. +and [Native](/~https://github.com/MarkusAmshove/Kluent/blob/master/native/src/main/kotlin/org/amshove/kluent/internal/Platform.kt) +implementation. If you're still unsure how to make something platform independent, we can have a look together inside the PR :-) # Attribution -[Parts of the `assertSoftly` feature](/~https://github.com/MarkusAmshove/Kluent/pull/185#issuecomment-731777949) are based upon the great work of [Kotest](/~https://github.com/kotest/kotest) under the Apache 2.0 License. +[Parts of the `assertSoftly` feature](/~https://github.com/MarkusAmshove/Kluent/pull/185#issuecomment-731777949) are based +upon the great work of [Kotest](/~https://github.com/kotest/kotest) under the Apache 2.0 License. diff --git a/build.gradle b/build.gradle index 7ca2a147..cc9fc452 100644 --- a/build.gradle +++ b/build.gradle @@ -1,128 +1,128 @@ -buildscript { - repositories { - jcenter() - mavenCentral() - maven { url "https://plugins.gradle.org/m2/" } - } - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version" - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_gradle_plugin_version" - classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+" - classpath 'com.adarshr:gradle-test-logger-plugin:1.6.0' - } -} - -ext { - libs = [ - // Compile - kotlin_stdlib_common : "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version", - kotlin_stdlib_jvm : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version", - kotlin_stdlib_js : "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version", - kotlin_reflect : "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version", - - // Tests - kotlin_test_common : "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version", - kotlin_test_jvm : "org.jetbrains.kotlin:kotlin-test:$kotlin_version", - kotlin_test_junit : "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version", - kotlin_test_js : "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version", - kotlin_test_annotations : "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version", - kotlinx_coroutines_test : "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinx_coroutines_version", - - junit : "junit:junit:4.12", - ] -} - -allprojects { - group 'org.amshove.kluent' - version '1.68' - - apply plugin: 'com.adarshr.test-logger' - - repositories { - mavenCentral() - } -} - -subprojects { - ext.configurePublishing = { artifactName = null -> - - apply plugin: 'maven' - apply plugin: 'java' - apply plugin: 'signing' - - // Comment when publishing - tasks.withType(Sign) { - onlyIf { gradle.taskGraph.hasTask("publish") } - } - - signing { - useGpgCmd() - sign configurations.archives - } - - artifactName = artifactName ?: project.name - - task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource - } - - task javadocJar(type: Jar) { - classifier = 'javadoc' - from javadoc - } - - artifacts { - archives javadocJar, sourcesJar - } - - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') { - authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) - } - snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) - } - - pom.project { - name artifactName - packaging 'jar' - description 'Fluent Assertion-Library for Kotlin' - url '/~https://github.com/MarkusAmshove/Kluent' - - scm { - connection 'scm:git:git:github.com/MarkusAmshove/Kluent.git' - developerConnection 'scm:git:git:github.com/MarkusAmshove/Kluent.git' - url '/~https://github.com/MarkusAmshove/Kluent' - } - - licenses { - license { - name 'MIT' - url '/~https://github.com/MarkusAmshove/Kluent/blob/master/LICENSE' - } - } - - developers { - developer { - id 'markusamshove' - name 'Markus Amshove' - } - } - } - } - } - } - - task printArtifactName { - doLast { - logger.info("artifactName: $artifactName") - } - } - } -} +buildscript { + repositories { + jcenter() + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_gradle_plugin_version" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+" + classpath 'com.adarshr:gradle-test-logger-plugin:1.6.0' + } +} + +ext { + libs = [ + // Compile + kotlin_stdlib_common : "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version", + kotlin_stdlib_jvm : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version", + kotlin_stdlib_js : "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version", + kotlin_reflect : "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version", + + // Tests + kotlin_test_common : "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version", + kotlin_test_jvm : "org.jetbrains.kotlin:kotlin-test:$kotlin_version", + kotlin_test_junit : "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version", + kotlin_test_js : "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version", + kotlin_test_annotations: "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version", + kotlinx_coroutines_test: "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinx_coroutines_version", + + junit : "junit:junit:4.12", + ] +} + +allprojects { + group 'org.amshove.kluent' + version '1.68' + + apply plugin: 'com.adarshr.test-logger' + + repositories { + mavenCentral() + } +} + +subprojects { + ext.configurePublishing = { artifactName = null -> + + apply plugin: 'maven' + apply plugin: 'java' + apply plugin: 'signing' + + // Comment when publishing + tasks.withType(Sign) { + onlyIf { gradle.taskGraph.hasTask("publish") } + } + + signing { + useGpgCmd() + sign configurations.archives + } + + artifactName = artifactName ?: project.name + + task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource + } + + task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc + } + + artifacts { + archives javadocJar, sourcesJar + } + + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') { + authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) + } + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword')) + } + + pom.project { + name artifactName + packaging 'jar' + description 'Fluent Assertion-Library for Kotlin' + url '/~https://github.com/MarkusAmshove/Kluent' + + scm { + connection 'scm:git:git:github.com/MarkusAmshove/Kluent.git' + developerConnection 'scm:git:git:github.com/MarkusAmshove/Kluent.git' + url '/~https://github.com/MarkusAmshove/Kluent' + } + + licenses { + license { + name 'MIT' + url '/~https://github.com/MarkusAmshove/Kluent/blob/master/LICENSE' + } + } + + developers { + developer { + id 'markusamshove' + name 'Markus Amshove' + } + } + } + } + } + } + + task printArtifactName { + doLast { + logger.info("artifactName: $artifactName") + } + } + } +} diff --git a/common/build.gradle b/common/build.gradle index 09adb690..494a2683 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -13,7 +13,7 @@ configurePublishing() compileKotlinCommon { kotlinOptions { freeCompilerArgs += [ - '-Xuse-experimental=kotlin.Experimental' + '-Xuse-experimental=kotlin.Experimental' ] } } diff --git a/common/src/main/kotlin/org/amshove/kluent/Basic.kt b/common/src/main/kotlin/org/amshove/kluent/Basic.kt index ec0c386c..9ca3c426 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Basic.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Basic.kt @@ -9,9 +9,11 @@ infix fun T.shouldEqual(expected: T?): T = this.shouldBeEqualTo(expected) infix fun T.shouldBeEqualTo(expected: T?): T = this.apply { assertEquals(expected, this) } -infix fun Char.shouldBeEqualToIgnoringCase(expected: Char): Char = this.apply { assertEqualsIgnoringCase(expected, this) } +infix fun Char.shouldBeEqualToIgnoringCase(expected: Char): Char = + this.apply { assertEqualsIgnoringCase(expected, this) } -infix fun CharSequence.shouldBeEqualToIgnoringCase(expected: CharSequence): CharSequence = this.apply { assertEqualsIgnoringCase(expected, this) } +infix fun CharSequence.shouldBeEqualToIgnoringCase(expected: CharSequence): CharSequence = + this.apply { assertEqualsIgnoringCase(expected, this) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun T.shouldNotEqual(expected: T?) = this.shouldNotBeEqualTo(expected) @@ -77,7 +79,8 @@ fun Char.shouldBeDigit() = this.apply { assertTrue("Expected '$this' to be a dig fun Char.shouldNotBeDigit() = this.apply { assertTrue("Expected '$this' to be no digit", !this.platformIsDigit()) } -infix fun T.should(assertion: T.() -> Boolean) = should("Expected the assertion to return true, but returned false", assertion) +infix fun T.should(assertion: T.() -> Boolean) = + should("Expected the assertion to return true, but returned false", assertion) fun T.should(message: String, assertion: T.() -> Boolean): T = also { try { @@ -85,11 +88,13 @@ fun T.should(message: String, assertion: T.() -> Boolean): T = also { fail(message) } } catch (t: Throwable) { - fail("""$message + fail( + """$message | | An exception occured: | ${t.platformClassName()}: ${t.message} | ${"\tat "}${t.platformJoinStackTrace()} - """.trimMargin()) + """.trimMargin() + ) } } diff --git a/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt b/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt index 80f70196..af79e729 100644 --- a/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt +++ b/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt @@ -1,69 +1,97 @@ package org.amshove.kluent import org.amshove.kluent.internal.* -import org.amshove.kluent.internal.assertEquals -import org.amshove.kluent.internal.assertFalse -import org.amshove.kluent.internal.assertTrue -import org.amshove.kluent.internal.messagePrefix import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract -import kotlin.math.exp -infix fun T.shouldStartWith(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to start with $expected", this.startsWith(expected)) } +infix fun T.shouldStartWith(expected: T) = + this.apply { assertTrue("Expected the CharSequence $this to start with $expected", this.startsWith(expected)) } -infix fun T.shouldStartWithIgnoringCase(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to start with $expected", this.startsWith(expected, true)) } +infix fun T.shouldStartWithIgnoringCase(expected: T) = this.apply { + assertTrue( + "Expected the CharSequence $this to start with $expected", + this.startsWith(expected, true) + ) +} -infix fun T.shouldEndWith(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to end with $expected", this.endsWith(expected)) } +infix fun T.shouldEndWith(expected: T) = + this.apply { assertTrue("Expected the CharSequence $this to end with $expected", this.endsWith(expected)) } -infix fun T.shouldEndWithIgnoringCase(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to end with $expected", this.endsWith(expected, true)) } +infix fun T.shouldEndWithIgnoringCase(expected: T) = + this.apply { assertTrue("Expected the CharSequence $this to end with $expected", this.endsWith(expected, true)) } -infix fun T.shouldContain(char: Char) = this.apply { assertTrue("Expected '$this' to contain '$char'", this.contains(char))} +infix fun T.shouldContain(char: Char) = + this.apply { assertTrue("Expected '$this' to contain '$char'", this.contains(char)) } -infix fun T.shouldContainIgnoringCase(char: Char) = this.apply { assertTrue("Expected '$this' to contain '$char'", this.contains(char, true))} +infix fun T.shouldContainIgnoringCase(char: Char) = + this.apply { assertTrue("Expected '$this' to contain '$char'", this.contains(char, true)) } -infix fun T.shouldContainSome(things: Iterable) = this.apply { assertTrue("Expected '$this' to contain at least one of $things", things.any { this.contains(it) }) } +infix fun T.shouldContainSome(things: Iterable) = + this.apply { assertTrue("Expected '$this' to contain at least one of $things", things.any { this.contains(it) }) } -infix fun T.shouldContainSomeIgnoringCase(things: Iterable) = this.apply { assertTrue("Expected '$this' to contain at least one of $things", things.any { this.contains(it, true) }) } +infix fun T.shouldContainSomeIgnoringCase(things: Iterable) = this.apply { + assertTrue( + "Expected '$this' to contain at least one of $things", + things.any { this.contains(it, true) }) +} fun T.shouldContainSome(vararg expected: CharSequence) = this.shouldContainSome(expected.toList()) -fun T.shouldContainSomeIgnoringCase(vararg expected: CharSequence) = this.shouldContainSomeIgnoringCase(expected.toList()) +fun T.shouldContainSomeIgnoringCase(vararg expected: CharSequence) = + this.shouldContainSomeIgnoringCase(expected.toList()) -infix fun T.shouldContainNone(things: Iterable) = this.apply { assertTrue("Expected '$this' to not contain any of $things", things.none { this.contains(it) }) } +infix fun T.shouldContainNone(things: Iterable) = + this.apply { assertTrue("Expected '$this' to not contain any of $things", things.none { this.contains(it) }) } -infix fun T.shouldContainNoneIgnoringCase(things: Iterable) = this.apply { assertTrue("Expected '$this' to not contain any of $things", things.none { this.contains(it, true) }) } +infix fun T.shouldContainNoneIgnoringCase(things: Iterable) = + this.apply { assertTrue("Expected '$this' to not contain any of $things", things.none { this.contains(it, true) }) } fun T.shouldContainNone(vararg expected: CharSequence) = this.shouldContainNone(expected.toList()) -fun T.shouldContainNoneIgnoringCase(vararg expected: CharSequence) = this.shouldContainNoneIgnoringCase(expected.toList()) +fun T.shouldContainNoneIgnoringCase(vararg expected: CharSequence) = + this.shouldContainNoneIgnoringCase(expected.toList()) -infix fun T.shouldContain(expected: CharSequence) = this.apply { assertTrue("Expected the CharSequence $this to contain $expected", this.contains(expected)) } +infix fun T.shouldContain(expected: CharSequence) = + this.apply { assertTrue("Expected the CharSequence $this to contain $expected", this.contains(expected)) } -infix fun T.shouldContainIgnoringCase(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to contain $expected", this.contains(expected, true)) } +infix fun T.shouldContainIgnoringCase(expected: T) = + this.apply { assertTrue("Expected the CharSequence $this to contain $expected", this.contains(expected, true)) } -infix fun T.shouldNotContain(char: Char) = this.apply { assertFalse("Expected '$this' to not contain '$char'", this.contains(char))} +infix fun T.shouldNotContain(char: Char) = + this.apply { assertFalse("Expected '$this' to not contain '$char'", this.contains(char)) } -infix fun T.shouldNotContainIgnoringCase(char: Char) = this.apply { assertFalse("Expected '$this' to not contain '$char'", this.contains(char, true))} +infix fun T.shouldNotContainIgnoringCase(char: Char) = + this.apply { assertFalse("Expected '$this' to not contain '$char'", this.contains(char, true)) } -infix fun T.shouldNotContainAny(things: Iterable) = this.apply { this shouldContainNone things } +infix fun T.shouldNotContainAny(things: Iterable) = + this.apply { this shouldContainNone things } -infix fun T.shouldNotContainAnyIgnoringCase(things: Iterable) = this.apply { this shouldContainNoneIgnoringCase things } +infix fun T.shouldNotContainAnyIgnoringCase(things: Iterable) = + this.apply { this shouldContainNoneIgnoringCase things } -fun T.shouldNotContainAny(vararg expected: CharSequence) = this.shouldNotContainAny(expected.toList()) +fun T.shouldNotContainAny(vararg expected: CharSequence) = + this.shouldNotContainAny(expected.toList()) -fun T.shouldNotContainAnyIgnoringCase(vararg expected: CharSequence) = this.shouldNotContainAnyIgnoringCase(expected.toList()) +fun T.shouldNotContainAnyIgnoringCase(vararg expected: CharSequence) = + this.shouldNotContainAnyIgnoringCase(expected.toList()) -infix fun T.shouldMatch(regex: String) = this.apply { assertTrue("Expected $this to match $regex", this.matches(Regex(regex))) } +infix fun T.shouldMatch(regex: String) = + this.apply { assertTrue("Expected $this to match $regex", this.matches(Regex(regex))) } -infix fun T.shouldMatch(regex: Regex) = this.apply { assertTrue("Expected $this to match ${regex.pattern}", this.matches(regex)) } +infix fun T.shouldMatch(regex: Regex) = + this.apply { assertTrue("Expected $this to match ${regex.pattern}", this.matches(regex)) } -fun T.shouldBeEmpty() = this.apply { assertTrue("Expected the CharSequence to be empty, but was $this", this.isEmpty()) } +fun T.shouldBeEmpty() = + this.apply { assertTrue("Expected the CharSequence to be empty, but was $this", this.isEmpty()) } -fun T?.shouldBeNullOrEmpty() = this.apply { assertTrue("Expected $this to be null or empty", this == null || this.isEmpty()) } +fun T?.shouldBeNullOrEmpty() = + this.apply { assertTrue("Expected $this to be null or empty", this == null || this.isEmpty()) } -fun T.shouldBeBlank() = this.apply { assertTrue("Expected the CharSequence to be blank, but was $this", this.isBlank()) } +fun T.shouldBeBlank() = + this.apply { assertTrue("Expected the CharSequence to be blank, but was $this", this.isBlank()) } -fun T?.shouldBeNullOrBlank() = this.apply { assertTrue("Expected $this to be null or blank", this == null || this.isBlank()) } +fun T?.shouldBeNullOrBlank() = + this.apply { assertTrue("Expected $this to be null or blank", this == null || this.isBlank()) } @Deprecated("Use shouldBeEqualTo", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun String.shouldEqualTo(expected: String) = shouldBeEqualTo(expected) @@ -77,26 +105,47 @@ infix fun String.shouldNotEqualTo(expected: String) = shouldNotBeEqualTo(expecte infix fun String.shouldNotBeEqualTo(expected: String) = this.apply { assertNotEquals(expected, this) } -infix fun String.shouldNotBeEqualToIgnoringCase(expected: String) = this.apply { assertNotEqualsIgnoringCase(expected, this) } +infix fun String.shouldNotBeEqualToIgnoringCase(expected: String) = + this.apply { assertNotEqualsIgnoringCase(expected, this) } -infix fun T.shouldNotStartWith(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not start with $expected", this.startsWith(expected)) } +infix fun T.shouldNotStartWith(expected: CharSequence) = + this.apply { assertFalse("Expected the CharSequence $this to not start with $expected", this.startsWith(expected)) } -infix fun T.shouldNotStartWithIgnoringCase(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not start with $expected", this.startsWith(expected, true)) } +infix fun T.shouldNotStartWithIgnoringCase(expected: CharSequence) = this.apply { + assertFalse( + "Expected the CharSequence $this to not start with $expected", + this.startsWith(expected, true) + ) +} -infix fun T.shouldNotEndWith(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not end with $expected", this.endsWith(expected)) } +infix fun T.shouldNotEndWith(expected: CharSequence) = + this.apply { assertFalse("Expected the CharSequence $this to not end with $expected", this.endsWith(expected)) } -infix fun T.shouldNotEndWithIgnoringCase(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not end with $expected", this.endsWith(expected, true)) } +infix fun T.shouldNotEndWithIgnoringCase(expected: CharSequence) = this.apply { + assertFalse( + "Expected the CharSequence $this to not end with $expected", + this.endsWith(expected, true) + ) +} -infix fun T.shouldNotContain(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not contain $expected", this.contains(expected)) } +infix fun T.shouldNotContain(expected: CharSequence) = + this.apply { assertFalse("Expected the CharSequence $this to not contain $expected", this.contains(expected)) } -infix fun T.shouldNotContainIgnoringCase(expected: CharSequence) = this.apply { assertFalse("Expected the CharSequence $this to not contain $expected", this.contains(expected, true)) } +infix fun T.shouldNotContainIgnoringCase(expected: CharSequence) = this.apply { + assertFalse( + "Expected the CharSequence $this to not contain $expected", + this.contains(expected, true) + ) +} -infix fun T.shouldNotMatch(regex: String) = this.apply { assertFalse("Expected $this to not match $regex", this.matches(Regex(regex))) } +infix fun T.shouldNotMatch(regex: String) = + this.apply { assertFalse("Expected $this to not match $regex", this.matches(Regex(regex))) } -infix fun T.shouldNotMatch(regex: Regex) = this.apply { assertFalse("Expected $this to not match ${regex.pattern}", this.matches(regex)) } +infix fun T.shouldNotMatch(regex: Regex) = + this.apply { assertFalse("Expected $this to not match ${regex.pattern}", this.matches(regex)) } fun T.shouldNotBeEmpty(): T = - this.apply { assertTrue("Expected the CharSequence to not be empty", this.isNotEmpty()) } + this.apply { assertTrue("Expected the CharSequence to not be empty", this.isNotEmpty()) } @UseExperimental(ExperimentalContracts::class) fun T?.shouldNotBeNullOrEmpty(): T { @@ -108,7 +157,7 @@ fun T?.shouldNotBeNullOrEmpty(): T { } fun T.shouldNotBeBlank(): T = - this.apply { assertTrue("Expected the CharSequence to not be blank", this.isNotBlank()) } + this.apply { assertTrue("Expected the CharSequence to not be blank", this.isNotBlank()) } @UseExperimental(ExperimentalContracts::class) fun T?.shouldNotBeNullOrBlank(): T { @@ -129,19 +178,23 @@ infix fun T.shouldContainAllIgnoringCase(items: Iterable T.shouldContainAll(vararg expected: CharSequence) = this.shouldContainAll(expected.toList()) -fun T.shouldContainAllIgnoringCase(vararg expected: CharSequence) = this.shouldContainAllIgnoringCase(expected.toList()) +fun T.shouldContainAllIgnoringCase(vararg expected: CharSequence) = + this.shouldContainAllIgnoringCase(expected.toList()) infix fun T.shouldNotContainAll(items: Iterable): CharSequence = this.apply { assertFalse("Expected the CharSequence to not contain all items: $items", items.all { this.contains(it) }) } -infix fun T.shouldNotContainAllIgnoringCase(items: Iterable): CharSequence = this.apply { - assertFalse("Expected the CharSequence to not contain all items: $items", items.all { this.contains(it, true) }) -} +infix fun T.shouldNotContainAllIgnoringCase(items: Iterable): CharSequence = + this.apply { + assertFalse("Expected the CharSequence to not contain all items: $items", items.all { this.contains(it, true) }) + } -fun T.shouldNotContainAll(vararg expected: CharSequence) = this.shouldNotContainAll(expected.toList()) +fun T.shouldNotContainAll(vararg expected: CharSequence) = + this.shouldNotContainAll(expected.toList()) -fun T.shouldNotContainAllIgnoringCase(vararg expected: CharSequence) = this.shouldNotContainAllIgnoringCase(expected.toList()) +fun T.shouldNotContainAllIgnoringCase(vararg expected: CharSequence) = + this.shouldNotContainAllIgnoringCase(expected.toList()) /** Asserts that the [expected] value is equal to the [actual] value ignoring case, with an optional [message]. */ fun assertEqualsIgnoringCase(expected: Any, actual: Any, message: String? = null) { @@ -178,15 +231,24 @@ fun assertEqualsIgnoringCase(message: String?, expected: Any, actual: Any) { fun assertNotEqualsIgnoringCase(message: String?, expected: Any, actual: Any) { if (actual is CharSequence && expected is CharSequence) { - assertTrue(!actual.toString().equals(expected.toString(), true)) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } - } - else if (actual is Char && expected is Char) { - assertTrue(!actual.equals(expected, true)) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } - } - else if (actual is String && expected is String) { - assertTrue(!actual.equals(expected, true)) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } - } - else { + assertTrue( + !actual.toString().equals(expected.toString(), true) + ) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } + } else if (actual is Char && expected is Char) { + assertTrue( + !actual.equals( + expected, + true + ) + ) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } + } else if (actual is String && expected is String) { + assertTrue( + !actual.equals( + expected, + true + ) + ) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } + } else { assertFails { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } } } diff --git a/common/src/main/kotlin/org/amshove/kluent/Collections.kt b/common/src/main/kotlin/org/amshove/kluent/Collections.kt index fdd991d6..22563b0f 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Collections.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Collections.kt @@ -3,64 +3,98 @@ package org.amshove.kluent import org.amshove.kluent.internal.* import kotlin.jvm.JvmName -infix fun Array.shouldContain(expected: T) = apply { if (this.contains(expected)) Unit else failExpectedActual("Array doesn't contain \"$expected\"", "the Array to contain \"$expected\"", join(this)) } +infix fun Array.shouldContain(expected: T) = apply { + if (this.contains(expected)) Unit else failExpectedActual( + "Array doesn't contain \"$expected\"", + "the Array to contain \"$expected\"", + join(this) + ) +} infix fun Array.shouldContainIgnoringCase(expected: Char) = apply { - if (this.any { it.equals(expected, true) }) Unit else failExpectedActual("Array doesn't contain \"$expected\"", "the Array to contain \"$expected\"", join(this)) + if (this.any { it.equals(expected, true) }) Unit else failExpectedActual( + "Array doesn't contain \"$expected\"", + "the Array to contain \"$expected\"", + join(this) + ) } -infix fun Array.shouldContainIgnoringCase(expected: T) = apply { - if (this.any { it.toString().equals(expected.toString(), true) }) Unit else failExpectedActual("Array doesn't contain \"$expected\"", "the Array to contain \"$expected\"", join(this)) +infix fun Array.shouldContainIgnoringCase(expected: T) = apply { + if (this.any { + it.toString().equals(expected.toString(), true) + }) Unit else failExpectedActual( + "Array doesn't contain \"$expected\"", + "the Array to contain \"$expected\"", + join(this) + ) } -infix fun Array.shouldContainSome(expected: Array) = apply { assertTrue("Expected Array to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } +infix fun Array.shouldContainSome(expected: Array) = + apply { assertTrue("Expected Array to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun Array.shouldContainSome(expected: Iterable) = apply { assertTrue("Expected Array to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } +infix fun Array.shouldContainSome(expected: Iterable) = + apply { assertTrue("Expected Array to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } -infix fun Array.shouldContainAny(check: (T) -> Boolean) = apply { assertTrue("Expected Array to contain at least one element that passes the check", this.any { check.invoke(it) }) } +infix fun Array.shouldContainAny(check: (T) -> Boolean) = apply { + assertTrue( + "Expected Array to contain at least one element that passes the check", + this.any { check.invoke(it) }) +} -infix fun Array.shouldContainNone(expected: Array) = apply { assertTrue("Expected Array to contain none of \"$expected\"", this.none { expected.contains(it) }) } +infix fun Array.shouldContainNone(expected: Array) = + apply { assertTrue("Expected Array to contain none of \"$expected\"", this.none { expected.contains(it) }) } -infix fun Array.shouldContainNoneIgnoringCase(expected: Array) = apply { +infix fun Array.shouldContainNoneIgnoringCase(expected: Array) = apply { assertTrue("Expected Array to contain none of \"$expected\"", - this.none { - expected.any { exp -> exp.equals(it, true) } - } + this.none { + expected.any { exp -> exp.equals(it, true) } + } ) } -infix fun Array.shouldContainNoneIgnoringCase(expected: Array) = apply { +infix fun Array.shouldContainNoneIgnoringCase(expected: Array) = apply { assertTrue("Expected Array to contain none of \"$expected\"", - this.none { - expected.any { exp -> exp.contains(it, true) } - } + this.none { + expected.any { exp -> exp.contains(it, true) } + } ) } -infix fun Array.shouldContainNone(expected: Iterable) = apply { assertTrue("Expected Array to contain none of \"$expected\"", this.none { expected.contains(it) }) } +infix fun Array.shouldContainNone(expected: Iterable) = + apply { assertTrue("Expected Array to contain none of \"$expected\"", this.none { expected.contains(it) }) } -infix fun Array.shouldContainNoneIgnoringCase(expected: Iterable) = apply { +infix fun Array.shouldContainNoneIgnoringCase(expected: Iterable) = apply { assertTrue("Expected Array to contain none of \"$expected\"", - this.none { - expected.any { exp -> exp.contains(it, true) } - } + this.none { + expected.any { exp -> exp.contains(it, true) } + } ) } infix fun Array.shouldContainAll(expected: Array) = apply { expected.forEach { shouldContain(it) } } -infix fun Array.shouldContainAllIgnoringCase(expected: Array) = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun Array.shouldContainAllIgnoringCase(expected: Array) = + apply { expected.forEach { shouldContainIgnoringCase(it) } } infix fun Array.shouldContainAll(expected: Iterable) = apply { expected.forEach { shouldContain(it) } } -infix fun Array.shouldContainAllIgnoringCase(expected: Iterable) = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun Array.shouldContainAllIgnoringCase(expected: Iterable) = + apply { expected.forEach { shouldContainIgnoringCase(it) } } -infix fun Array.shouldContainSame(expected: Array) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun Array.shouldContainSame(expected: Array) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun Array.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun Array.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun Array.shouldNotContain(expected: T) = apply { if (!this.contains(expected)) Unit else failExpectedActual("Array should not contain \"$expected\"", "the Array to not contain \"$expected\"", join(this)) } +infix fun Array.shouldNotContain(expected: T) = apply { + if (!this.contains(expected)) Unit else failExpectedActual( + "Array should not contain \"$expected\"", + "the Array to not contain \"$expected\"", + join(this) + ) +} infix fun Array.shouldNotContainAny(expected: Array) = apply { expected.forEach { shouldNotContain(it) } } @@ -84,19 +118,26 @@ fun Array.shouldNotBeEmpty() = apply { assertNotEmpty(this.toList(), "Arr infix fun Array.shouldHaveSize(expectedSize: Int) = apply { this.toList().shouldHaveSize(expectedSize) } -infix fun Array.shouldMatchAtLeastOneOf(predicate: (T) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun Array.shouldMatchAtLeastOneOf(predicate: (T) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun Array.shouldMatchAllWith(predicate: (T) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun Array.shouldMatchAllWith(predicate: (T) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun IntArray.shouldEqual(expected: IntArray) = shouldBeEqualTo(expected) -infix fun IntArray.shouldBeEqualTo(expected: IntArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun IntArray.shouldBeEqualTo(expected: IntArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } infix fun Array.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("Array is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("Array is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nArray was:\n <$this>") index++ } } @@ -104,12 +145,17 @@ infix fun Array.shouldBeSortedAccordingTo(comparator: Comparator) = ap @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun IntArray.shouldNotEqual(expected: IntArray) = shouldNotBeEqualTo(expected) -infix fun IntArray.shouldNotBeEqualTo(expected: IntArray) = apply { assertArrayNotEquals(expected.toTypedArray(), this.toTypedArray()) } +infix fun IntArray.shouldNotBeEqualTo(expected: IntArray) = + apply { assertArrayNotEquals(expected.toTypedArray(), this.toTypedArray()) } infix fun IntArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("IntArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nIntArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("IntArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nIntArray was:\n <$this>") index++ } } @@ -125,14 +171,16 @@ infix fun IntArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().sho infix fun IntArray.shouldContain(expected: Int) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun IntArray.shouldContainSome(expected: IntArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun IntArray.shouldContainSome(expected: IntArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun IntArray.shouldContainAny(check: (Int) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun IntArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun IntArray.shouldContainNone(expected: IntArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun IntArray.shouldContainNone(expected: IntArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } infix fun IntArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } @@ -140,9 +188,11 @@ infix fun IntArray.shouldContainAll(expected: IntArray) = apply { expected.forEa infix fun IntArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun IntArray.shouldContainSame(expected: IntArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun IntArray.shouldContainSame(expected: IntArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun IntArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun IntArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun IntArray.shouldNotContain(expected: Int) = apply { this.toTypedArray() shouldNotContain expected } @@ -154,19 +204,23 @@ infix fun Int.shouldBeIn(theArray: IntArray) = apply { this shouldBeIn theArray. infix fun Int.shouldNotBeIn(theArray: IntArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun IntArray.shouldMatchAtLeastOneOf(predicate: (Int) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun IntArray.shouldMatchAtLeastOneOf(predicate: (Int) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun IntArray.shouldMatchAllWith(predicate: (Int) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun IntArray.shouldMatchAllWith(predicate: (Int) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun BooleanArray.shouldEqual(expected: BooleanArray) = shouldBeEqualTo(expected) -infix fun BooleanArray.shouldBeEqualTo(expected: BooleanArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun BooleanArray.shouldBeEqualTo(expected: BooleanArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun BooleanArray.shouldNotEqual(expected: BooleanArray) = shouldNotBeEqualTo(expected) -infix fun BooleanArray.shouldNotBeEqualTo(expected: BooleanArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun BooleanArray.shouldNotBeEqualTo(expected: BooleanArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun BooleanArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -179,7 +233,8 @@ infix fun BooleanArray.shouldHaveSize(expectedSize: Int) = apply { this.toList() infix fun BooleanArray.shouldContain(expected: Boolean) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainTrue or shouldContainFalse", ReplaceWith("this.shouldContainTrue(check)")) -infix fun BooleanArray.shouldContainSome(expected: BooleanArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun BooleanArray.shouldContainSome(expected: BooleanArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } fun BooleanArray.shouldContainTrue() = apply { this.toTypedArray().shouldContainAny { it } } @@ -188,49 +243,64 @@ fun BooleanArray.shouldContainFalse() = apply { this.toTypedArray().shouldContai infix fun BooleanArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("BooleanArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nBooleanArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("BooleanArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nBooleanArray was:\n <$this>") index++ } } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun BooleanArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } +infix fun BooleanArray.shouldContainSome(expected: Iterable) = + apply { this.toList().shouldContainSome(expected) } -infix fun BooleanArray.shouldContainNone(expected: BooleanArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun BooleanArray.shouldContainNone(expected: BooleanArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } -infix fun BooleanArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } +infix fun BooleanArray.shouldContainNone(expected: Iterable) = + apply { this.toList().shouldContainNone(expected) } infix fun BooleanArray.shouldContainAll(expected: BooleanArray) = apply { expected.forEach { shouldContain(it) } } -infix fun BooleanArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } +infix fun BooleanArray.shouldContainAll(expected: Iterable) = + apply { this.toList().shouldContainAll(expected) } infix fun BooleanArray.shouldNotContain(expected: Boolean) = apply { this.toTypedArray() shouldNotContain expected } -infix fun BooleanArray.shouldContainSame(expected: BooleanArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun BooleanArray.shouldContainSame(expected: BooleanArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun BooleanArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun BooleanArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun BooleanArray.shouldNotContainAny(expected: BooleanArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun BooleanArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun BooleanArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } infix fun Boolean.shouldBeIn(theArray: BooleanArray) = apply { this shouldBeIn theArray.toTypedArray() } infix fun Boolean.shouldNotBeIn(theArray: BooleanArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun BooleanArray.shouldMatchAtLeastOneOf(predicate: (Boolean) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun BooleanArray.shouldMatchAtLeastOneOf(predicate: (Boolean) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun BooleanArray.shouldMatchAllWith(predicate: (Boolean) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun BooleanArray.shouldMatchAllWith(predicate: (Boolean) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun ByteArray.shouldEqual(expected: ByteArray) = shouldBeEqualTo(expected) -infix fun ByteArray.shouldBeEqualTo(expected: ByteArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun ByteArray.shouldBeEqualTo(expected: ByteArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun ByteArray.shouldNotEqual(expected: ByteArray) = shouldNotBeEqualTo(expected) -infix fun ByteArray.shouldNotBeEqualTo(expected: ByteArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun ByteArray.shouldNotBeEqualTo(expected: ByteArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun ByteArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -243,14 +313,16 @@ infix fun ByteArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().sh infix fun ByteArray.shouldContain(expected: Byte) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun ByteArray.shouldContainSome(expected: ByteArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun ByteArray.shouldContainSome(expected: ByteArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun ByteArray.shouldContainAny(check: (Byte) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun ByteArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun ByteArray.shouldContainNone(expected: ByteArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun ByteArray.shouldContainNone(expected: ByteArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } infix fun ByteArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } @@ -258,20 +330,27 @@ infix fun ByteArray.shouldContainAll(expected: ByteArray) = apply { expected.for infix fun ByteArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun ByteArray.shouldContainSame(expected: ByteArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun ByteArray.shouldContainSame(expected: ByteArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun ByteArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun ByteArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun ByteArray.shouldNotContain(expected: Byte) = apply { this.toTypedArray() shouldNotContain expected } infix fun ByteArray.shouldNotContainAny(expected: ByteArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun ByteArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun ByteArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } infix fun ByteArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("ByteArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nByteArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("ByteArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nByteArray was:\n <$this>") index++ } } @@ -280,19 +359,23 @@ infix fun Byte.shouldBeIn(theArray: ByteArray) = apply { this shouldBeIn theArra infix fun Byte.shouldNotBeIn(theArray: ByteArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun ByteArray.shouldMatchAtLeastOneOf(predicate: (Byte) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun ByteArray.shouldMatchAtLeastOneOf(predicate: (Byte) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun ByteArray.shouldMatchAllWith(predicate: (Byte) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun ByteArray.shouldMatchAllWith(predicate: (Byte) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun CharArray.shouldEqual(expected: CharArray) = shouldBeEqualTo(expected) -infix fun CharArray.shouldBeEqualTo(expected: CharArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun CharArray.shouldBeEqualTo(expected: CharArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun CharArray.shouldNotEqual(expected: CharArray) = shouldNotBeEqualTo(expected) -infix fun CharArray.shouldNotBeEqualTo(expected: CharArray) = apply { assertArrayNotEquals(expected.toTypedArray(), this.toTypedArray()) } +infix fun CharArray.shouldNotBeEqualTo(expected: CharArray) = + apply { assertArrayNotEquals(expected.toTypedArray(), this.toTypedArray()) } fun CharArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -304,71 +387,91 @@ infix fun CharArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().sh infix fun CharArray.shouldContain(expected: Char) = apply { this.toTypedArray() shouldContain expected } -infix fun CharArray.shouldContainIgnoringCase(expected: Char) = apply { this.toTypedArray() shouldContainIgnoringCase expected } +infix fun CharArray.shouldContainIgnoringCase(expected: Char) = + apply { this.toTypedArray() shouldContainIgnoringCase expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun CharArray.shouldContainSome(expected: CharArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun CharArray.shouldContainSome(expected: CharArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun CharArray.shouldContainAny(check: (Char) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun CharArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun CharArray.shouldContainNone(expected: CharArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun CharArray.shouldContainNone(expected: CharArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } -infix fun CharArray.shouldContainNoneIgnoringCase(expected: CharArray) = apply { this.toTypedArray().shouldContainNoneIgnoringCase(expected.toTypedArray()) } +infix fun CharArray.shouldContainNoneIgnoringCase(expected: CharArray) = + apply { this.toTypedArray().shouldContainNoneIgnoringCase(expected.toTypedArray()) } infix fun CharArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } -infix fun CharArray.shouldContainNoneIgnoringCase(expected: Iterable) = apply { this.toList().shouldContainNoneIgnoringCase(expected) } +infix fun CharArray.shouldContainNoneIgnoringCase(expected: Iterable) = + apply { this.toList().shouldContainNoneIgnoringCase(expected) } infix fun CharArray.shouldContainAll(expected: CharArray) = apply { expected.forEach { shouldContain(it) } } -infix fun CharArray.shouldContainAllIgnoringCase(expected: CharArray) = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun CharArray.shouldContainAllIgnoringCase(expected: CharArray) = + apply { expected.forEach { shouldContainIgnoringCase(it) } } infix fun CharArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun CharArray.shouldContainAllIgnoringCase(expected: Iterable) = apply { this.toList().shouldContainAllIgnoringCase(expected) } +infix fun CharArray.shouldContainAllIgnoringCase(expected: Iterable) = + apply { this.toList().shouldContainAllIgnoringCase(expected) } -infix fun CharArray.shouldContainSame(expected: CharArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun CharArray.shouldContainSame(expected: CharArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun CharArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun CharArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun CharArray.shouldNotContain(expected: Char) = apply { this.toTypedArray() shouldNotContain expected } infix fun CharArray.shouldNotContainAny(expected: CharArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun CharArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun CharArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } infix fun CharArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("ByteArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nByteArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("ByteArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nByteArray was:\n <$this>") index++ } } infix fun Char.shouldBeIn(theArray: CharArray) = apply { this shouldBeIn theArray.toTypedArray() } -infix fun Char.shouldBeInIgnoringCase(theArray: CharArray) = apply { this shouldBeInIgnoringCase theArray.toTypedArray() } +infix fun Char.shouldBeInIgnoringCase(theArray: CharArray) = + apply { this shouldBeInIgnoringCase theArray.toTypedArray() } infix fun Char.shouldNotBeIn(theArray: CharArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun Char.shouldNotBeInIgnoringCase(theArray: CharArray) = apply { this shouldNotBeInIgnoringCase theArray.toTypedArray() } +infix fun Char.shouldNotBeInIgnoringCase(theArray: CharArray) = + apply { this shouldNotBeInIgnoringCase theArray.toTypedArray() } -infix fun CharArray.shouldMatchAtLeastOneOf(predicate: (Char) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun CharArray.shouldMatchAtLeastOneOf(predicate: (Char) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun CharArray.shouldMatchAllWith(predicate: (Char) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun CharArray.shouldMatchAllWith(predicate: (Char) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun DoubleArray.shouldEqual(expected: DoubleArray) = shouldBeEqualTo(expected) -infix fun DoubleArray.shouldBeEqualTo(expected: DoubleArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun DoubleArray.shouldBeEqualTo(expected: DoubleArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun DoubleArray.shouldNotEqual(expected: DoubleArray) = shouldNotBeEqualTo(expected) -infix fun DoubleArray.shouldNotBeEqualTo(expected: DoubleArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun DoubleArray.shouldNotBeEqualTo(expected: DoubleArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun DoubleArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -381,39 +484,53 @@ infix fun DoubleArray.shouldHaveSize(expectedSize: Int) = apply { this.toList(). infix fun DoubleArray.shouldContain(expected: Double) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun DoubleArray.shouldContainSome(expected: DoubleArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun DoubleArray.shouldContainSome(expected: DoubleArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } -infix fun DoubleArray.shouldContainAny(check: (Double) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } +infix fun DoubleArray.shouldContainAny(check: (Double) -> Boolean) = + apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun DoubleArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } +infix fun DoubleArray.shouldContainSome(expected: Iterable) = + apply { this.toList().shouldContainSome(expected) } -infix fun DoubleArray.shouldContainNone(expected: DoubleArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun DoubleArray.shouldContainNone(expected: DoubleArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } -infix fun DoubleArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } +infix fun DoubleArray.shouldContainNone(expected: Iterable) = + apply { this.toList().shouldContainNone(expected) } infix fun DoubleArray.shouldContainAll(expected: DoubleArray) = apply { expected.forEach { shouldContain(it) } } infix fun DoubleArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun DoubleArray.shouldContainSame(expected: DoubleArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun DoubleArray.shouldContainSame(expected: DoubleArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun DoubleArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun DoubleArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun DoubleArray.shouldNotContain(expected: Double) = apply { this.toTypedArray() shouldNotContain expected } infix fun DoubleArray.shouldNotContainAny(expected: DoubleArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun DoubleArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun DoubleArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } -infix fun DoubleArray.shouldMatchAtLeastOneOf(predicate: (Double) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun DoubleArray.shouldMatchAtLeastOneOf(predicate: (Double) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun DoubleArray.shouldMatchAllWith(predicate: (Double) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun DoubleArray.shouldMatchAllWith(predicate: (Double) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } infix fun DoubleArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("DoubleArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nDoubleArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("DoubleArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nDoubleArray was:\n <$this>") index++ } } @@ -425,12 +542,14 @@ infix fun Double.shouldNotBeIn(theArray: DoubleArray) = apply { this shouldNotBe @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun FloatArray.shouldEqual(expected: FloatArray) = shouldBeEqualTo(expected) -infix fun FloatArray.shouldBeEqualTo(expected: FloatArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun FloatArray.shouldBeEqualTo(expected: FloatArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun FloatArray.shouldNotEqual(expected: FloatArray) = shouldNotBeEqualTo(expected) -infix fun FloatArray.shouldNotBeEqualTo(expected: FloatArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun FloatArray.shouldNotBeEqualTo(expected: FloatArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun FloatArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -443,14 +562,16 @@ infix fun FloatArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().s infix fun FloatArray.shouldContain(expected: Float) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun FloatArray.shouldContainSome(expected: FloatArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun FloatArray.shouldContainSome(expected: FloatArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun FloatArray.shouldContainAny(check: (Float) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun FloatArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun FloatArray.shouldContainNone(expected: FloatArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun FloatArray.shouldContainNone(expected: FloatArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } infix fun FloatArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } @@ -458,20 +579,27 @@ infix fun FloatArray.shouldContainAll(expected: FloatArray) = apply { expected.f infix fun FloatArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun FloatArray.shouldContainSame(expected: FloatArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun FloatArray.shouldContainSame(expected: FloatArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun FloatArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun FloatArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun FloatArray.shouldNotContain(expected: Float) = apply { this.toTypedArray() shouldNotContain expected } infix fun FloatArray.shouldNotContainAny(expected: FloatArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun FloatArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun FloatArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } infix fun FloatArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("FloatArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nFloatArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("FloatArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nFloatArray was:\n <$this>") index++ } } @@ -480,19 +608,23 @@ infix fun Float.shouldBeIn(theArray: FloatArray) = apply { this shouldBeIn theAr infix fun Float.shouldNotBeIn(theArray: FloatArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun FloatArray.shouldMatchAtLeastOneOf(predicate: (Float) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun FloatArray.shouldMatchAtLeastOneOf(predicate: (Float) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun FloatArray.shouldMatchAllWith(predicate: (Float) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun FloatArray.shouldMatchAllWith(predicate: (Float) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun LongArray.shouldEqual(expected: LongArray) = shouldBeEqualTo(expected) -infix fun LongArray.shouldBeEqualTo(expected: LongArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun LongArray.shouldBeEqualTo(expected: LongArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun LongArray.shouldNotEqual(expected: LongArray) = shouldNotBeEqualTo(expected) -infix fun LongArray.shouldNotBeEqualTo(expected: LongArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun LongArray.shouldNotBeEqualTo(expected: LongArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun LongArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -505,14 +637,16 @@ infix fun LongArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().sh infix fun LongArray.shouldContain(expected: Long) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun LongArray.shouldContainSome(expected: LongArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun LongArray.shouldContainSome(expected: LongArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun LongArray.shouldContainAny(check: (Long) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun LongArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun LongArray.shouldContainNone(expected: LongArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun LongArray.shouldContainNone(expected: LongArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } infix fun LongArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } @@ -520,20 +654,27 @@ infix fun LongArray.shouldContainAll(expected: LongArray) = apply { expected.for infix fun LongArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun LongArray.shouldContainSame(expected: LongArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun LongArray.shouldContainSame(expected: LongArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun LongArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun LongArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun LongArray.shouldNotContain(expected: Long) = apply { this.toTypedArray() shouldNotContain expected } infix fun LongArray.shouldNotContainAny(expected: LongArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun LongArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun LongArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } infix fun LongArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("LongArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nLongArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("LongArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nLongArray was:\n <$this>") index++ } } @@ -542,19 +683,23 @@ infix fun Long.shouldBeIn(theArray: LongArray) = apply { this shouldBeIn theArra infix fun Long.shouldNotBeIn(theArray: LongArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun LongArray.shouldMatchAtLeastOneOf(predicate: (Long) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun LongArray.shouldMatchAtLeastOneOf(predicate: (Long) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun LongArray.shouldMatchAllWith(predicate: (Long) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun LongArray.shouldMatchAllWith(predicate: (Long) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun ShortArray.shouldEqual(expected: ShortArray) = shouldBeEqualTo(expected) -infix fun ShortArray.shouldBeEqualTo(expected: ShortArray) = apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun ShortArray.shouldBeEqualTo(expected: ShortArray) = + apply { assertArrayEquals(this.toTypedArray(), expected.toTypedArray()) } @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun ShortArray.shouldNotEqual(expected: ShortArray) = shouldNotBeEqualTo(expected) -infix fun ShortArray.shouldNotBeEqualTo(expected: ShortArray) = apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } +infix fun ShortArray.shouldNotBeEqualTo(expected: ShortArray) = + apply { assertArrayNotEquals(this.toTypedArray(), expected.toTypedArray()) } fun ShortArray.shouldHaveSingleItem() = toList().shouldHaveSingleItem() @@ -567,14 +712,16 @@ infix fun ShortArray.shouldHaveSize(expectedSize: Int) = apply { this.toList().s infix fun ShortArray.shouldContain(expected: Short) = apply { this.toTypedArray() shouldContain expected } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun ShortArray.shouldContainSome(expected: ShortArray) = apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } +infix fun ShortArray.shouldContainSome(expected: ShortArray) = + apply { this.toTypedArray().shouldContainSome(expected.toTypedArray()) } infix fun ShortArray.shouldContainAny(check: (Short) -> Boolean) = apply { this.toTypedArray().shouldContainAny(check) } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) infix fun ShortArray.shouldContainSome(expected: Iterable) = apply { this.toList().shouldContainSome(expected) } -infix fun ShortArray.shouldContainNone(expected: ShortArray) = apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } +infix fun ShortArray.shouldContainNone(expected: ShortArray) = + apply { this.toTypedArray().shouldContainNone(expected.toTypedArray()) } infix fun ShortArray.shouldContainNone(expected: Iterable) = apply { this.toList().shouldContainNone(expected) } @@ -582,24 +729,33 @@ infix fun ShortArray.shouldContainAll(expected: ShortArray) = apply { expected.f infix fun ShortArray.shouldContainAll(expected: Iterable) = apply { this.toList().shouldContainAll(expected) } -infix fun ShortArray.shouldContainSame(expected: ShortArray) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun ShortArray.shouldContainSame(expected: ShortArray) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) -infix fun ShortArray.shouldContainSame(expected: Iterable) = assertBothCollectionsContainsSame(expected.toList(), this.toList()) +infix fun ShortArray.shouldContainSame(expected: Iterable) = + assertBothCollectionsContainsSame(expected.toList(), this.toList()) infix fun ShortArray.shouldNotContain(expected: Short) = apply { this.toTypedArray() shouldNotContain expected } infix fun ShortArray.shouldNotContainAny(expected: ShortArray) = apply { expected.forEach { shouldNotContain(it) } } -infix fun ShortArray.shouldNotContainAny(expected: Iterable) = apply { this.toList().shouldNotContainAny(expected) } +infix fun ShortArray.shouldNotContainAny(expected: Iterable) = + apply { this.toList().shouldNotContainAny(expected) } -infix fun ShortArray.shouldMatchAtLeastOneOf(predicate: (Short) -> Boolean) = apply { this.toList().shouldMatchAtLeastOneOf(predicate) } +infix fun ShortArray.shouldMatchAtLeastOneOf(predicate: (Short) -> Boolean) = + apply { this.toList().shouldMatchAtLeastOneOf(predicate) } -infix fun ShortArray.shouldMatchAllWith(predicate: (Short) -> Boolean) = apply { this.toList().shouldMatchAllWith(predicate) } +infix fun ShortArray.shouldMatchAllWith(predicate: (Short) -> Boolean) = + apply { this.toList().shouldMatchAllWith(predicate) } infix fun ShortArray.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 toList().zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("ShortArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nShortArray was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("ShortArray is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nShortArray was:\n <$this>") index++ } } @@ -608,14 +764,28 @@ infix fun Short.shouldBeIn(theArray: ShortArray) = apply { this shouldBeIn theAr infix fun Short.shouldNotBeIn(theArray: ShortArray) = apply { this shouldNotBeIn theArray.toTypedArray() } -infix fun > I.shouldContain(expected: T): I = apply { if (this.contains(expected)) Unit else failExpectedActual("Iterable doesn't contain \"$expected\"", "the Iterable to contain \"$expected\"", join(this)) } +infix fun > I.shouldContain(expected: T): I = apply { + if (this.contains(expected)) Unit else failExpectedActual( + "Iterable doesn't contain \"$expected\"", + "the Iterable to contain \"$expected\"", + join(this) + ) +} infix fun > I.shouldContainIgnoringCase(expected: Char): I = apply { - if (this.any { it.equals(expected, true) }) Unit else failExpectedActual("Iterable doesn't contain \"$expected\"", "the Iterable to contain \"$expected\"", join(this)) + if (this.any { it.equals(expected, true) }) Unit else failExpectedActual( + "Iterable doesn't contain \"$expected\"", + "the Iterable to contain \"$expected\"", + join(this) + ) } -infix fun > I.shouldContainIgnoringCase(expected: T): I = apply { - if (this.any { it.contains(expected, true) }) Unit else failExpectedActual("Iterable doesn't contain \"$expected\"", "the Iterable to contain \"$expected\"", join(this)) +infix fun > I.shouldContainIgnoringCase(expected: T): I = apply { + if (this.any { it.contains(expected, true) }) Unit else failExpectedActual( + "Iterable doesn't contain \"$expected\"", + "the Iterable to contain \"$expected\"", + join(this) + ) } infix fun > I.shouldContainAny(check: (T) -> Boolean): I = apply { @@ -625,66 +795,91 @@ infix fun > I.shouldContainAny(check: (T) -> Boolean): I = ap Unit } else { val failedItems = result - .filterNot { it.second } - .map { it.first } - .joinToString(", ") + .filterNot { it.second } + .map { it.first } + .joinToString(", ") failExpectedActual( - "Iterable doesn't contain \"$failedItems\"", - "the Iterable to contain \"$failedItems\"", - join(this) + "Iterable doesn't contain \"$failedItems\"", + "the Iterable to contain \"$failedItems\"", + join(this) ) } } @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun > I.shouldContainSome(expected: Iterable): I = apply { assertTrue("Expected Iterable to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } +infix fun > I.shouldContainSome(expected: Iterable): I = apply { + assertTrue( + "Expected Iterable to contain at least one of \"$expected\"", + this.any { expected.contains(it) }) +} @Deprecated("Use shouldContainAny", ReplaceWith("this.shouldContainAny(check)")) -infix fun > I.shouldContainSome(expected: Array): I = apply { assertTrue("Expected Iterable to contain at least one of \"$expected\"", this.any { expected.contains(it) }) } +infix fun > I.shouldContainSome(expected: Array): I = apply { + assertTrue( + "Expected Iterable to contain at least one of \"$expected\"", + this.any { expected.contains(it) }) +} -infix fun > I.shouldContainNone(expected: Iterable): I = apply { assertTrue("Expected Iterable to contain none of \"$expected\"", this.none { expected.contains(it) }) } +infix fun > I.shouldContainNone(expected: Iterable): I = + apply { assertTrue("Expected Iterable to contain none of \"$expected\"", this.none { expected.contains(it) }) } @JvmName("shouldContainNoneCharsIgnoringCase") infix fun > I.shouldContainNoneIgnoringCase(expected: Iterable): I = apply { assertTrue("Expected Iterable to contain none of \"$expected\"", - this.none { - expected.any { exp -> exp.equals(it, true) } - } + this.none { + expected.any { exp -> exp.equals(it, true) } + } ) } @JvmName("shouldContainNoneCharSequenceIgnoringCase") -infix fun > I.shouldContainNoneIgnoringCase(expected: Iterable): I = apply { +infix fun > I.shouldContainNoneIgnoringCase(expected: Iterable): I = apply { assertTrue("Expected Iterable to contain none of \"$expected\"", - this.none { - expected.any { exp -> exp.contains(it, true) } - } + this.none { + expected.any { exp -> exp.contains(it, true) } + } ) } -infix fun > I.shouldContainNone(expected: Array): I = apply { assertTrue("Expected Iterable to contain none of \"$expected\"", this.none { expected.contains(it) }) } +infix fun > I.shouldContainNone(expected: Array): I = + apply { assertTrue("Expected Iterable to contain none of \"$expected\"", this.none { expected.contains(it) }) } -infix fun > I.shouldContainAll(expected: Iterable): I = apply { expected.forEach { shouldContain(it) } } +infix fun > I.shouldContainAll(expected: Iterable): I = + apply { expected.forEach { shouldContain(it) } } @JvmName("shouldContainAllCharsIgnoringCase") -infix fun > I.shouldContainAllIgnoringCase(expected: Iterable): I = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun > I.shouldContainAllIgnoringCase(expected: Iterable): I = + apply { expected.forEach { shouldContainIgnoringCase(it) } } @JvmName("shouldContainAllCharSequenceIgnoringCase") -infix fun > I.shouldContainAllIgnoringCase(expected: Iterable): I = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun > I.shouldContainAllIgnoringCase(expected: Iterable): I = + apply { expected.forEach { shouldContainIgnoringCase(it) } } -infix fun > I.shouldContainAll(expected: Array): I = apply { expected.forEach { shouldContain(it) } } +infix fun > I.shouldContainAll(expected: Array): I = + apply { expected.forEach { shouldContain(it) } } -infix fun > I.shouldContainAllIgnoringCase(expected: Array): I = apply { expected.forEach { shouldContainIgnoringCase(it) } } +infix fun > I.shouldContainAllIgnoringCase(expected: Array): I = + apply { expected.forEach { shouldContainIgnoringCase(it) } } -infix fun > I.shouldContainSame(expected: Iterable): I = assertBothIterablesContainsSame(expected.toList(), this.toList()) +infix fun > I.shouldContainSame(expected: Iterable): I = + assertBothIterablesContainsSame(expected.toList(), this.toList()) -infix fun > I.shouldContainSame(expected: Array): I = assertBothIterablesContainsSame(expected.toList(), this.toList()) +infix fun > I.shouldContainSame(expected: Array): I = + assertBothIterablesContainsSame(expected.toList(), this.toList()) -infix fun > I.shouldNotContain(expected: T): I = apply { if (!this.contains(expected)) Unit else failExpectedActual("Iterable should not contain \"$expected\"", "the Iterable to not contain \"$expected\"", join(this)) } +infix fun > I.shouldNotContain(expected: T): I = apply { + if (!this.contains(expected)) Unit else failExpectedActual( + "Iterable should not contain \"$expected\"", + "the Iterable to not contain \"$expected\"", + join(this) + ) +} -infix fun > I.shouldNotContainAny(expected: Iterable): I = apply { expected.forEach { shouldNotContain(it) } } +infix fun > I.shouldNotContainAny(expected: Iterable): I = + apply { expected.forEach { shouldNotContain(it) } } -infix fun > I.shouldNotContainAny(expected: Array): I = apply { expected.forEach { shouldNotContain(it) } } +infix fun > I.shouldNotContainAny(expected: Array): I = + apply { expected.forEach { shouldNotContain(it) } } @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun > I.shouldEqual(expected: Iterable?): I = shouldBeEqualTo(expected) @@ -694,7 +889,8 @@ infix fun > I.shouldBeEqualTo(expected: Iterable?): I = ap @Deprecated("Use `shouldNotBeEqualTo`", ReplaceWith("this.shouldNotBeEqualTo(expected)")) infix fun > I.shouldNotEqual(expected: Iterable?): I = shouldNotBeEqualTo(expected) -infix fun > I.shouldNotBeEqualTo(expected: Iterable?): I = apply { assertNotEquals(expected, this) } +infix fun > I.shouldNotBeEqualTo(expected: Iterable?): I = + apply { assertNotEquals(expected, this) } fun , T> I.shouldHaveSingleItem(): T { shouldHaveSize(1) @@ -715,23 +911,31 @@ infix fun > I.shouldHaveSize(expectedSize: Int) = apply { infix fun > I.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("Iterable is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nIterable was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("Iterable is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nIterable was:\n <$this>") index++ } } @Deprecated("Equality should not be tested on sequences", level = DeprecationLevel.ERROR) infix fun > S.shouldEqual(expected: Sequence): S = - hardFail("Equality should not be tested on sequences") + hardFail("Equality should not be tested on sequences") @Deprecated("Equality should not be tested on sequences", level = DeprecationLevel.ERROR) infix fun > S.shouldNotEqual(expected: Sequence): S = - hardFail("Equality should not be tested on sequences") + hardFail("Equality should not be tested on sequences") infix fun > S.shouldBeSortedAccordingTo(comparator: Comparator) = apply { var index = 0 zipWithNext { a, b -> - if (comparator.compare(a, b) > 0) fail("Sequence is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nSequence was:\n <$this>") + if (comparator.compare( + a, + b + ) > 0 + ) fail("Sequence is not sorted according to $comparator comparator because element $index:\n <$a>\nis not less or equal than element ${index + 1}:\n <$b>\nSequence was:\n <$this>") index++ } } @@ -741,19 +945,31 @@ fun > S.shouldNotBeEmpty(): S = apply { assertNotEmpty(asIterabl infix fun > S.shouldContain(expected: T): S = apply { if (expected !in this) - failExpectedActual("Sequence doesn't contain \"$expected\"", "the Sequence to contain \"$expected\"", join(asIterable())) + failExpectedActual( + "Sequence doesn't contain \"$expected\"", + "the Sequence to contain \"$expected\"", + join(asIterable()) + ) } infix fun > I.shouldNotContain(expected: S): I = apply { if (expected in this) - failExpectedActual("Sequence should not contain \"$expected\"", "the Sequence to not contain \"$expected\"", join(asIterable())) + failExpectedActual( + "Sequence should not contain \"$expected\"", + "the Sequence to not contain \"$expected\"", + join(asIterable()) + ) } infix fun > S.shouldContainAll(expected: Sequence): S = apply { val set = toHashSet() expected.forEach { if (it !in set) - failExpectedActual("Sequence doesn't contain \"$expected\"", "the Sequence to contain \"$expected\"", join(asIterable())) + failExpectedActual( + "Sequence doesn't contain \"$expected\"", + "the Sequence to contain \"$expected\"", + join(asIterable()) + ) } } @@ -763,7 +979,7 @@ infix fun > S.shouldContainNone(expected: Sequence): S = a } } -infix fun > S.shouldContainNoneIgnoringCase(expected: Sequence): S = apply { +infix fun > S.shouldContainNoneIgnoringCase(expected: Sequence): S = apply { val expectedCollection: Collection = expected.map { it.toString() }.toList() assertTrue(none { it.findAnyOf(expectedCollection, 0, true) != null }) { "Expected Sequence to contain none of \"${join(expected.asIterable())}\"" @@ -786,7 +1002,7 @@ infix fun > S.shouldHaveSize(expectedSize: Int) = apply { } infix fun > S.shouldContainSame(expected: Sequence): S = - assertBothIterablesContainsSame(expected.toList(), this.toList()) + assertBothIterablesContainsSame(expected.toList(), this.toList()) @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun > M.shouldEqual(expected: M): M = shouldBeEqualTo(expected) @@ -800,25 +1016,65 @@ infix fun > M.shouldNotBeEqualTo(expected: M): M = apply { asse infix fun > M.shouldEqualUnordered(expected: M): M = apply { assertMapEqualsUnordered(this, expected) } -infix fun > M.shouldNotEqualUnordered(expected: M): M = apply { assertMapNotEqualsUnordered(this, expected) } +infix fun > M.shouldNotEqualUnordered(expected: M): M = + apply { assertMapNotEqualsUnordered(this, expected) } -infix fun > M.shouldHaveKey(theKey: K): M = apply { if (this.containsKey(theKey)) Unit else failExpectedActual("Map should contain key \"$theKey\"", "the Map to contain key \"$theKey\"", joinKeys(this)) } +infix fun > M.shouldHaveKey(theKey: K): M = apply { + if (this.containsKey(theKey)) Unit else failExpectedActual( + "Map should contain key \"$theKey\"", + "the Map to contain key \"$theKey\"", + joinKeys(this) + ) +} -infix fun > M.shouldNotHaveKey(theKey: K): M = apply { if (!this.containsKey(theKey)) Unit else failExpectedActual("Map should not contain key \"$theKey\"", "the Map to not contain the key \"$theKey\"", joinKeys(this)) } +infix fun > M.shouldNotHaveKey(theKey: K): M = apply { + if (!this.containsKey(theKey)) Unit else failExpectedActual( + "Map should not contain key \"$theKey\"", + "the Map to not contain the key \"$theKey\"", + joinKeys(this) + ) +} -infix fun > M.shouldHaveValue(theValue: V): M = apply { if (this.values.contains(theValue)) Unit else failExpectedActual("Map should contain the value \"$theValue\"", "the Map to contain value \"$theValue\"", joinValues(this)) } +infix fun > M.shouldHaveValue(theValue: V): M = apply { + if (this.values.contains(theValue)) Unit else failExpectedActual( + "Map should contain the value \"$theValue\"", + "the Map to contain value \"$theValue\"", + joinValues(this) + ) +} -infix fun > M.shouldNotHaveValue(theValue: V): M = apply { if (!this.values.contains(theValue)) Unit else failExpectedActual("Map should not contain the value \"$theValue\"", "the Map to not contain the value \"$theValue\"", joinValues(this)) } +infix fun > M.shouldNotHaveValue(theValue: V): M = apply { + if (!this.values.contains(theValue)) Unit else failExpectedActual( + "Map should not contain the value \"$theValue\"", + "the Map to not contain the value \"$theValue\"", + joinValues(this) + ) +} -infix fun > M.shouldContain(expected: Pair): M = apply { if (this[expected.first] == expected.second) Unit else failExpectedActual("Map should contain Pair $expected", "the Map to contain Pair $expected", joinPairs(this)) } +infix fun > M.shouldContain(expected: Pair): M = apply { + if (this[expected.first] == expected.second) Unit else failExpectedActual( + "Map should contain Pair $expected", + "the Map to contain Pair $expected", + joinPairs(this) + ) +} -infix fun > M.shouldContainAll(expected: M): M = apply { expected.forEach { shouldContain(it.toPair()) } } +infix fun > M.shouldContainAll(expected: M): M = + apply { expected.forEach { shouldContain(it.toPair()) } } -infix fun > M.shouldContainSame(expected: M): M = apply { expected.forEach { shouldContain(it.toPair()) }; this.forEach { expected.shouldContain(it.toPair()) } } +infix fun > M.shouldContainSame(expected: M): M = + apply { expected.forEach { shouldContain(it.toPair()) }; this.forEach { expected.shouldContain(it.toPair()) } } -infix fun > M.shouldNotContain(expected: Pair): M = apply { if (this[expected.first] != expected.second) Unit else failExpectedActual("Map should not contain Pair $expected", "the Map to not contain the Pair $expected", joinPairs(this)) } +infix fun > M.shouldNotContain(expected: Pair): M = apply { + if (this[expected.first] != expected.second) Unit else failExpectedActual( + "Map should not contain Pair $expected", + "the Map to not contain the Pair $expected", + joinPairs(this) + ) +} -infix fun > M.shouldNotContainAny(expected: M): M = apply { expected.forEach { shouldNotContain(it.toPair()) } } +infix fun > M.shouldNotContainAny(expected: M): M = + apply { expected.forEach { shouldNotContain(it.toPair()) } } fun > M.shouldBeEmpty(): M = apply { assertEmpty(this.toList(), "Map") } @@ -826,37 +1082,69 @@ fun > M.shouldNotBeEmpty(): M = apply { assertNotEmpty(this.toList fun > M.shouldHaveSize(expectedSize: Int) = apply { this.keys.shouldHaveSize(expectedSize) } -infix fun Any?.shouldNotBeIn(array: Array) = apply { if (!array.contains(this)) Unit else failExpectedActual("\"$this\" should not be in Array", "the value \"$this\" to not be in the Array", join(array)) } +infix fun Any?.shouldNotBeIn(array: Array) = apply { + if (!array.contains(this)) Unit else failExpectedActual( + "\"$this\" should not be in Array", + "the value \"$this\" to not be in the Array", + join(array) + ) +} infix fun Char.shouldNotBeInIgnoringCase(array: Array) = apply { - if (!array.contains(this.toLowerCase()) && !array.contains(this.toUpperCase())) Unit else failExpectedActual("\"$this\" should not be in Array", "the value \"$this\" to not be in the Array", join(array)) + if (!array.contains(this.toLowerCase()) && !array.contains(this.toUpperCase())) Unit else failExpectedActual( + "\"$this\" should not be in Array", + "the value \"$this\" to not be in the Array", + join(array) + ) } -infix fun Any?.shouldBeIn(iterable: Iterable) = apply { if (iterable.contains(this)) Unit else failExpectedActual("\"$this\" should be in Iterable", "the value \"$this\" inside the Iterable", join(iterable)) } +infix fun Any?.shouldBeIn(iterable: Iterable) = apply { + if (iterable.contains(this)) Unit else failExpectedActual( + "\"$this\" should be in Iterable", + "the value \"$this\" inside the Iterable", + join(iterable) + ) +} -infix fun Any?.shouldNotBeIn(iterable: Iterable) = apply { if (!iterable.contains(this)) Unit else failExpectedActual("\"$this\" should not be in Iterable", "the value \"$this\" to not be in the Iterable", join(iterable)) } +infix fun Any?.shouldNotBeIn(iterable: Iterable) = apply { + if (!iterable.contains(this)) Unit else failExpectedActual( + "\"$this\" should not be in Iterable", + "the value \"$this\" to not be in the Iterable", + join(iterable) + ) +} -infix fun Any?.shouldBeIn(array: Array) = apply { if (array.contains(this)) Unit else failExpectedActual("\"$this\" should be in Array", "the value \"$this\" inside the Array", join(array)) } +infix fun Any?.shouldBeIn(array: Array) = apply { + if (array.contains(this)) Unit else failExpectedActual( + "\"$this\" should be in Array", + "the value \"$this\" inside the Array", + join(array) + ) +} infix fun Char.shouldBeInIgnoringCase(array: Array) = apply { - if (array.contains(this.toLowerCase()) || array.contains(this.toUpperCase())) Unit else failExpectedActual("\"$this\" should be in Array", "the value \"$this\" inside the Array", join(array)) + if (array.contains(this.toLowerCase()) || array.contains(this.toUpperCase())) Unit else failExpectedActual( + "\"$this\" should be in Array", + "the value \"$this\" inside the Array", + join(array) + ) } infix fun > ClosedRange.shouldBeInRange(input: ClosedRange): ClosedRange = apply { if (this.contains(input.start) && this.contains(input.endInclusive)) Unit else failExpectedActual( - "ClosedRange does not contain all elements of \"$input\"", - "the ClosedRange to contain \"$input\"", - "the ClosedRange contains \"$this\"" + "ClosedRange does not contain all elements of \"$input\"", + "the ClosedRange to contain \"$input\"", + "the ClosedRange contains \"$this\"" ) } infix fun > ClosedRange.shouldNotBeInRange(input: ClosedRange): ClosedRange = apply { if (!(input.start <= this.start && input.endInclusive >= this.endInclusive)) Unit else failExpectedActual( - "ClosedRange contain elements of \"$input\"", - "the ClosedRange should not contain \"$input\"", - "the ClosedRange contains \"$this\"" + "ClosedRange contain elements of \"$input\"", + "the ClosedRange should not contain \"$input\"", + "the ClosedRange contains \"$this\"" ) } @@ -869,7 +1157,11 @@ fun Iterable.shouldMatchAtLeastOneOf(predicate: (E) -> Boolean): Iterable fun Iterable.shouldMatchAllWith(predicate: (E) -> Boolean): Iterable { this.forEach { if (!predicate(it)) - failExpectedActual("the Iterable contains \"$it\", which doesn't match the Predicate", "Iterable should match all with the Predicate", join(this)) + failExpectedActual( + "the Iterable contains \"$it\", which doesn't match the Predicate", + "Iterable should match all with the Predicate", + join(this) + ) } return this } @@ -897,5 +1189,9 @@ internal fun assertBothCollectionsContainsSame(expected: List, actual: Li } if (remainingItemsOnExpectedList.isNotEmpty() || notPresentOnList.isNotEmpty()) - failCollectionWithDifferentItems("The collection doesn't have the same items", join(remainingItemsOnExpectedList), join(notPresentOnList)) + failCollectionWithDifferentItems( + "The collection doesn't have the same items", + join(remainingItemsOnExpectedList), + join(notPresentOnList) + ) } diff --git a/common/src/main/kotlin/org/amshove/kluent/Numerical.kt b/common/src/main/kotlin/org/amshove/kluent/Numerical.kt index 235eef14..298bc60f 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Numerical.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Numerical.kt @@ -74,21 +74,29 @@ infix fun Double.shouldNotEqualTo(expected: Double) = this.shouldNotBeEqualTo(ex infix fun Double.shouldNotBeEqualTo(expected: Double) = this.apply { assertNotEquals(expected, this) } -infix fun > T.shouldBeGreaterThan(expected: T) = this.apply { assertTrue("Expected $this to be greater than $expected", this > expected) } +infix fun > T.shouldBeGreaterThan(expected: T) = + this.apply { assertTrue("Expected $this to be greater than $expected", this > expected) } -infix fun > T.shouldNotBeGreaterThan(expected: T) = this.apply { assertTrue("Expected $this to not be greater than $expected", this <= expected) } +infix fun > T.shouldNotBeGreaterThan(expected: T) = + this.apply { assertTrue("Expected $this to not be greater than $expected", this <= expected) } -infix fun > T.shouldBeGreaterOrEqualTo(expected: T) = this.apply { assertTrue("Expected $this to be greater or equal to $expected", this >= expected) } +infix fun > T.shouldBeGreaterOrEqualTo(expected: T) = + this.apply { assertTrue("Expected $this to be greater or equal to $expected", this >= expected) } -infix fun > T.shouldNotBeGreaterOrEqualTo(expected: T) = this.apply { assertTrue("Expected $this to be not be greater or equal to $expected", this < expected) } +infix fun > T.shouldNotBeGreaterOrEqualTo(expected: T) = + this.apply { assertTrue("Expected $this to be not be greater or equal to $expected", this < expected) } -infix fun > T.shouldBeLessThan(expected: T) = this.apply { assertTrue("Expected $this to be less than $expected", this < expected) } +infix fun > T.shouldBeLessThan(expected: T) = + this.apply { assertTrue("Expected $this to be less than $expected", this < expected) } -infix fun > T.shouldNotBeLessThan(expected: T) = this.apply { assertTrue("Expected $this to not be less than $expected", this >= expected) } +infix fun > T.shouldNotBeLessThan(expected: T) = + this.apply { assertTrue("Expected $this to not be less than $expected", this >= expected) } -infix fun > T.shouldBeLessOrEqualTo(expected: T) = this.apply { assertTrue("Expected $this to be less or equal to $expected", this <= expected) } +infix fun > T.shouldBeLessOrEqualTo(expected: T) = + this.apply { assertTrue("Expected $this to be less or equal to $expected", this <= expected) } -infix fun > T.shouldNotBeLessOrEqualTo(expected: T) = this.apply { assertTrue("Expected $this to not be less or equal to $expected", this > expected) } +infix fun > T.shouldNotBeLessOrEqualTo(expected: T) = + this.apply { assertTrue("Expected $this to not be less or equal to $expected", this > expected) } fun Byte.shouldBePositive() = this.apply { assertTrue("Expected $this to be positive", this > 0) } @@ -124,9 +132,19 @@ fun Double.shouldBeNear(expected: Double, delta: Double): Double { return shouldBeInRange(expected - delta, expected + delta) } -fun > T.shouldBeInRange(lowerBound: T, upperBound: T) = this.apply { assertTrue("Expected $this to be between (and including) $lowerBound and $upperBound", this >= lowerBound && this <= upperBound) } +fun > T.shouldBeInRange(lowerBound: T, upperBound: T) = this.apply { + assertTrue( + "Expected $this to be between (and including) $lowerBound and $upperBound", + this >= lowerBound && this <= upperBound + ) +} -fun > T.shouldNotBeInRange(lowerBound: T, upperBound: T) = this.apply { assertTrue("Expected $this to not be between (and including) $lowerBound and $upperBound", this < lowerBound || this > upperBound) } +fun > T.shouldNotBeInRange(lowerBound: T, upperBound: T) = this.apply { + assertTrue( + "Expected $this to not be between (and including) $lowerBound and $upperBound", + this < lowerBound || this > upperBound + ) +} infix fun Byte.shouldBeInRange(range: IntRange) = this.apply { (this.toInt()).shouldBeInRange(range) } @@ -134,7 +152,8 @@ infix fun Short.shouldBeInRange(range: IntRange) = this.apply { (this.toInt()).s infix fun Int.shouldBeInRange(range: IntRange) = this.apply { this.shouldBeInRange(range.first, range.last) } -infix fun > T.shouldBeInRange(range: ClosedFloatingPointRange) = this.assertIsInFloatingRange(range) +infix fun > T.shouldBeInRange(range: ClosedFloatingPointRange) = + this.assertIsInFloatingRange(range) infix fun > T.shouldBeInRange(range: ClosedRange) = this.assertIsInFloatingRange(range) @@ -146,12 +165,23 @@ infix fun Short.shouldNotBeInRange(range: IntRange) = this.apply { (this.toInt() infix fun Int.shouldNotBeInRange(range: IntRange) = this.apply { this.shouldNotBeInRange(range.first, range.last) } -infix fun > T.shouldNotBeInRange(range: ClosedFloatingPointRange) = this.assertIsNotInFloatingRange(range) +infix fun > T.shouldNotBeInRange(range: ClosedFloatingPointRange) = + this.assertIsNotInFloatingRange(range) infix fun > T.shouldNotBeInRange(range: ClosedRange) = this.assertIsNotInFloatingRange(range) infix fun Long.shouldNotBeInRange(range: LongRange) = this.apply { this.shouldNotBeInRange(range.first, range.last) } -private fun > T.assertIsInFloatingRange(range: ClosedRange): T = this.apply { assertTrue("Expected $this to be between (and including) ${range.start} and ${range.endInclusive}", range.contains(this)) } +private fun > T.assertIsInFloatingRange(range: ClosedRange): T = this.apply { + assertTrue( + "Expected $this to be between (and including) ${range.start} and ${range.endInclusive}", + range.contains(this) + ) +} -private fun > T.assertIsNotInFloatingRange(range: ClosedRange): T = this.apply { assertTrue("Expected $this to not be between (and including) ${range.start} and ${range.endInclusive}", !range.contains(this)) } +private fun > T.assertIsNotInFloatingRange(range: ClosedRange): T = this.apply { + assertTrue( + "Expected $this to not be between (and including) ${range.start} and ${range.endInclusive}", + !range.contains(this) + ) +} diff --git a/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt b/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt index 431c5b3d..93525533 100644 --- a/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt +++ b/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt @@ -1,6 +1,5 @@ package org.amshove.kluent.internal -import org.amshove.kluent.ErrorCollectionMode import org.amshove.kluent.collectOrThrow import org.amshove.kluent.errorCollector import org.amshove.kluent.fail @@ -91,19 +90,24 @@ internal fun > mapsEqualUnordered(m1: M?, m2: M?): Boolean { return true } -internal fun failExpectedActual(message: String, expected: String?, actual: String?) = fail(""" +internal fun failExpectedActual(message: String, expected: String?, actual: String?) = fail( + """ |$message | Expected: $expected | Actual: $actual -""".trimMargin()) +""".trimMargin() +) -internal fun failCollectionWithDifferentItems(message: String, expected: String?, actual: String?) = fail(""" +internal fun failCollectionWithDifferentItems(message: String, expected: String?, actual: String?) = fail( + """ |$message |${if (!expected.isNullOrEmpty()) "Items included on the expected collection but not in the actual: $expected" else ""} |${if (!actual.isNullOrEmpty()) "Items included on the actual collection but not in the expected: $actual" else ""} -""".trimMargin()) +""".trimMargin() +) -internal fun failFirstSecond(message: String, first: String?, second: String?) : Nothing = throw ComparisonFailedException(message, first, second) +internal fun failFirstSecond(message: String, first: String?, second: String?): Nothing = + throw ComparisonFailedException(message, first, second) // TODO: assertSame and notSame currently not implemented in native 0.6 fun assertSame(expected: Any?, actual: Any?) { @@ -140,7 +144,7 @@ fun assertNotEquals(illegal: T, actual: T, message: String? = null) { * * @param message the message to report if the assertion fails. */ -fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit { +fun assertNotEquals(message: String?, illegal: Any?, actual: Any?) { assertTrue(actual != illegal) { messagePrefix(message) + "Illegal value: <$actual>." } } @@ -152,7 +156,7 @@ fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit { */ @JvmName("assertFailsInline") inline fun assertFails(block: () -> Unit): Throwable = - checkResultIsFailure(null, runCatching(block)) + checkResultIsFailure(null, runCatching(block)) /** * Asserts that given function [block] fails by throwing an exception. @@ -164,17 +168,17 @@ inline fun assertFails(block: () -> Unit): Throwable = */ @JvmName("assertFailsInline") inline fun assertFails(message: String?, block: () -> Unit): Throwable = - checkResultIsFailure(message, runCatching(block)) + checkResultIsFailure(message, runCatching(block)) @PublishedApi internal fun checkResultIsFailure(message: String?, blockResult: Result): Throwable { blockResult.fold( - onSuccess = { - asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.") - }, - onFailure = { e -> - return e - } + onSuccess = { + asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.") + }, + onFailure = { e -> + return e + } ) } @@ -186,7 +190,7 @@ internal fun checkResultIsFailure(message: String?, blockResult: Result): * The returned exception can be inspected further, for example by asserting its property values. */ inline fun assertFailsWith(message: String? = null, block: () -> Unit): T = - assertFailsWith(T::class, message, block) + assertFailsWith(T::class, message, block) /** * Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. @@ -195,7 +199,8 @@ inline fun assertFailsWith(message: String? = null, bloc * The returned exception can be inspected further, for example by asserting its property values. */ @JvmName("assertFailsWithInline") -inline fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block) +inline fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = + assertFailsWith(exceptionClass, null, block) /** * Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. @@ -207,13 +212,13 @@ inline fun assertFailsWith(exceptionClass: KClass, block: () */ @JvmName("assertFailsWithInline") inline fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = - checkResultIsFailure(exceptionClass, message, runCatching(block)) + checkResultIsFailure(exceptionClass, message, runCatching(block)) -class ComparisonFailedException(val customMessage: String?, val expected: String?, val actual: String?) : RuntimeException( +class ComparisonFailedException(customMessage: String?, val expected: String?, val actual: String?) : RuntimeException( """${customMessage ?: ""} |Expected: <$expected> but was: <$actual> """.trimMargin().trim() ) { constructor(customMessage: String?, expected: Any?, actual: Any?) - : this(customMessage, expected?.toString(), actual?.toString()) -} \ No newline at end of file + : this(customMessage, expected?.toString(), actual?.toString()) +} diff --git a/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt b/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt index 1a7f1505..31db8043 100644 --- a/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt +++ b/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt @@ -2,7 +2,9 @@ package org.amshove.kluent.internal import kotlin.reflect.KClass -internal fun join(theArray: Array?): String = if (theArray == null) "null" else "[${theArray.joinToString(", ")}]" +internal fun join(theArray: Array?): String = + if (theArray == null) "null" else "[${theArray.joinToString(", ")}]" + internal fun join(theIterable: Iterable): String = "[${theIterable.joinToString(", ")}]" internal fun join(theMap: Map): String = "Entries: [${theMap.entries.joinToString(", ")}]" @@ -14,7 +16,11 @@ internal fun messagePrefix(message: String?) = if (message == null) "" else "$me /** Asserts that a [blockResult] is a failure with the specific exception type being thrown. */ @PublishedApi -internal expect fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T +internal expect fun checkResultIsFailure( + exceptionClass: KClass, + message: String?, + blockResult: Result +): T /** Use this function in places where a soft fail in assertSoftly would not make sense - for example shouldNotBeNull. */ @PublishedApi diff --git a/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt b/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt index 40a2b117..1fcb801f 100644 --- a/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt +++ b/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt @@ -4,7 +4,8 @@ fun assertMessage(message: String, func: () -> Unit) { try { func() } catch (e: Throwable) { - e.message?.replace("\\s+|\\t|\\n".toRegex(), " ")?.trim().shouldBeEqualTo(message.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + e.message?.replace("\\s+|\\t|\\n".toRegex(), " ")?.trim() + .shouldBeEqualTo(message.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) } } diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt index edcb704c..650cd151 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt @@ -16,7 +16,8 @@ class ShouldBeDigitShould { @Test fun passWhenTestingAnyUnicodeDigit() { - val digits = listOf('\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039') + val digits = + listOf('\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039') digits.forEach { it.shouldBeDigit() diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt index d85edc39..d6375c74 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt @@ -2,7 +2,6 @@ package org.amshove.kluent.tests.basic import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNull -import org.amshove.kluent.shouldNotBeNull import kotlin.test.Test class ShouldBeNullShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt index 08ecf46a..273b830d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic import org.amshove.kluent.internal.assertFails -import kotlin.test.Test import org.amshove.kluent.shouldBe import org.amshove.kluent.tests.Person +import kotlin.test.Test class ShouldBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt index d81b2872..f9bb3b61 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt @@ -34,7 +34,8 @@ class ShouldNotBeDigitShould { @Test fun failWhenTestingAnyUnicodeDigit() { - val digits = listOf('\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039') + val digits = + listOf('\u0030', '\u0031', '\u0032', '\u0033', '\u0034', '\u0035', '\u0036', '\u0037', '\u0038', '\u0039') digits.forEach { assertFails { it.shouldNotBeDigit() } diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt index 247d5d0b..a4d1c8c0 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic import org.amshove.kluent.internal.assertFails -import kotlin.test.Test import org.amshove.kluent.shouldNotBe import org.amshove.kluent.tests.Person +import kotlin.test.Test class ShouldNotBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt index 87432975..c76dbdb1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic import org.amshove.kluent.internal.assertFails -import kotlin.test.Test import org.amshove.kluent.should import org.amshove.kluent.tests.Person +import kotlin.test.Test class ShouldShould { @Test @@ -11,8 +11,8 @@ class ShouldShould { val person = Person("Peter", "Pan") person - .should { name.startsWith("P") } - .should { surname.startsWith("P") } + .should { name.startsWith("P") } + .should { surname.startsWith("P") } } @Test @@ -50,14 +50,17 @@ class ShouldShould { fun Person.shouldHaveUppercaseName() = this.should("The name of $this should be uppercase") { name[0].toUpperCase() == name[0] } + val peter = Person("peter", "pan") try { peter.shouldHaveUppercaseName() } catch (e: AssertionError) { - e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().startsWith(""" + e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().startsWith( + """ The following assertion failed: The name of $peter should be uppercase""" - .replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + .replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) } } diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt index 8c9ed4bb..459c3fc7 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt @@ -18,11 +18,11 @@ class ShouldStartWithShould { @Test fun failWhenTestingACharSequenceWhichDoesNotStartWithASubSequence() { - assertFails { "Bye" shouldStartWith "H" } + assertFails { "Bye" shouldStartWith "H" } } @Test fun failWhenTestingACharSequenceWhichDoesNotStartWithASubSequenceIgnoringCase() { - assertFails { "Bye" shouldStartWithIgnoringCase "H" } + assertFails { "Bye" shouldStartWithIgnoringCase "H" } } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt index 319098a2..a86d5511 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.internal.assertFails -import kotlin.test.Test -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldBeIn import org.amshove.kluent.shouldBeInIgnoringCase +import org.amshove.kluent.tests.Person +import kotlin.test.Test class ShouldBeInShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt index ddb333b6..83f79416 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.internal.assertFails -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldBeSortedAccordingTo +import org.amshove.kluent.tests.Person import kotlin.random.Random import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt index 411d8d0d..cb584ea6 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections -import org.amshove.kluent.* import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.shouldContainAny import kotlin.test.Test class ShouldContainAnyShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt index f032a594..47951ebb 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.internal.assertFails -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldContain +import org.amshove.kluent.tests.Person import kotlin.test.Test class ShouldContainShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt index f4f0e86c..bd597019 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt @@ -1,6 +1,5 @@ package org.amshove.kluent.tests.collections -import org.amshove.kluent.shouldContainFalse import org.amshove.kluent.shouldContainTrue import kotlin.test.Test import kotlin.test.assertFails diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt index d38b9433..10267cff 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt @@ -2,8 +2,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.tests.Person -import kotlin.test.assertFails import kotlin.test.Test +import kotlin.test.assertFails class ShouldEqualShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt index dbdfe1ae..14b937c0 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt @@ -2,9 +2,9 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldEqualUnordered +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails -import org.amshove.kluent.tests.Person class ShouldEqualUnorderedShould { @Test @@ -12,7 +12,7 @@ class ShouldEqualUnorderedShould { val firstMap = mapOf(2 to Person("C", "D"), 1 to Person("A", "B")) val secondMap = mapOf(1 to Person("A", "B"), 2 to Person("C", "D")) - assertFails { firstMap shouldBeEqualTo secondMap } + assertFails { firstMap shouldBeEqualTo secondMap } } @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt index 12214ba3..825d5f65 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt @@ -2,8 +2,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldHaveValue import org.amshove.kluent.tests.Person -import kotlin.test.assertFails import kotlin.test.Test +import kotlin.test.assertFails class ShouldHaveValueShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt index 28ed0f57..8f8aed3d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldMatchAllWith import org.amshove.kluent.shouldMatchAtLeastOneOf +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails @@ -43,9 +43,9 @@ class ShouldMatchPredicateShould { fun supportChaining() { val list = listOf(Person("Anton", "Chekhov"), Person("Alexander", "Pushkin"), Person("Fyodor", "Dostoevsky")) list - .shouldMatchAtLeastOneOf { it.name.startsWith("A") } - .shouldMatchAtLeastOneOf { it.name.startsWith("F") } - .shouldMatchAllWith { it.name.length > 3 } + .shouldMatchAtLeastOneOf { it.name.startsWith("A") } + .shouldMatchAtLeastOneOf { it.name.startsWith("F") } + .shouldMatchAllWith { it.name.length > 3 } } @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt index bf508c43..99eb8300 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt @@ -136,6 +136,7 @@ class ShouldNotBeEmptyShould { val theArray = charArrayOf() assertFails { theArray.shouldNotBeEmpty() } } + @Test fun passWhenTestingAPrimitiveBooleanArrayWhichIsNotEmpty() { val theArray = booleanArrayOf(true, false, true) diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt index 48edc099..c2aaafa5 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections -import kotlin.test.assertFails -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotBeIn +import org.amshove.kluent.tests.Person import kotlin.test.Test +import kotlin.test.assertFails class ShouldNotBeInShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt index 8dd4d858..dc00c8ac 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotContainAny -import kotlin.test.assertFails import kotlin.test.Test +import kotlin.test.assertFails class ShouldNotContainAnyShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt index bed2ec6b..78041768 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.internal.assertFails -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotBeEqualTo +import org.amshove.kluent.tests.Person import kotlin.test.Test class ShouldNotEqualShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt index 0e639a3b..1d80e734 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections import org.amshove.kluent.internal.assertFails -import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotHaveValue +import org.amshove.kluent.tests.Person import kotlin.test.Test class ShouldNotHaveValueShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt index 7825b940..a6704218 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt @@ -6,16 +6,16 @@ import kotlin.test.Test class ChainingAssertionsShould { @Test fun allowChainingOfCollectionAssertions() { - val list = listOf(1, 2, 3, 4, 5, 6, 7, 8) + val list = listOf(1, 2, 3, 4, 5, 6, 7, 8) list - .shouldNotBeEmpty() - .shouldContain(2) - .shouldContain(4) - .shouldContainSome(arrayOf(5, 7)) - .should { - size > 5 - } + .shouldNotBeEmpty() + .shouldContain(2) + .shouldContain(4) + .shouldContainSome(arrayOf(5, 7)) + .should { + size > 5 + } } @Test @@ -23,11 +23,11 @@ class ChainingAssertionsShould { val number = 42 number - .shouldBePositive() - .shouldBeGreaterThan(10) - .shouldBeLessThan(43) - .shouldBeInRange(40..45) - .shouldNotBeInRange(45..50) + .shouldBePositive() + .shouldBeGreaterThan(10) + .shouldBeLessThan(43) + .shouldBeInRange(40..45) + .shouldNotBeInRange(45..50) } @Test @@ -35,10 +35,10 @@ class ChainingAssertionsShould { val sequence = "Hello World!" sequence - .shouldNotBeEmpty() - .shouldNotBeBlank() - .shouldStartWith("Hello") - .shouldEndWith("!") - .shouldContainSome("e", "l") + .shouldNotBeEmpty() + .shouldNotBeBlank() + .shouldStartWith("Hello") + .shouldEndWith("!") + .shouldContainSome("e", "l") } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt index 51426cf1..8602e49a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldNotBeInRange -import kotlin.test.assertFails import kotlin.test.Test +import kotlin.test.assertFails class ShouldNotBeInRangeShould { @Test diff --git a/docs/BasicAssertions.md b/docs/BasicAssertions.md index 7358959a..2c100d1e 100644 --- a/docs/BasicAssertions.md +++ b/docs/BasicAssertions.md @@ -1,40 +1,46 @@ -# Basic assertions - -This assertions are available for all objects: - -## Testing for equality -```kt -anObject shouldBeEqualTo anotherObject -anObject shouldNotBeEqualTo anotherObject -``` - -## Testing for referential equality -```kt -anObject shouldBe anObject -anObject shouldNotBe anotherObject -``` - -## Testing for subtypes -```kt -anObject shouldBeInstanceOf Any::class -anObject shouldNotBeInstanceOf Int::class -``` - -## Test for nullability -```kt -anObject.shouldBeNull() -anObject.shouldNotBeNull() -``` - -## Testing booleans -```kt -isMale.shouldBeTrue() -isMale.shouldBeFalse() -isMale.shouldNotBeTrue() -isMale.shouldNotBeFalse() -``` - -## Failing with a message -```kt -fail("You did not know the airspeed velocity of an unladen swallow!") +# Basic assertions + +This assertions are available for all objects: + +## Testing for equality + +```kt +anObject shouldBeEqualTo anotherObject +anObject shouldNotBeEqualTo anotherObject +``` + +## Testing for referential equality + +```kt +anObject shouldBe anObject +anObject shouldNotBe anotherObject +``` + +## Testing for subtypes + +```kt +anObject shouldBeInstanceOf Any::class +anObject shouldNotBeInstanceOf Int::class +``` + +## Test for nullability + +```kt +anObject.shouldBeNull() +anObject.shouldNotBeNull() +``` + +## Testing booleans + +```kt +isMale.shouldBeTrue() +isMale.shouldBeFalse() +isMale.shouldNotBeTrue() +isMale.shouldNotBeFalse() +``` + +## Failing with a message + +```kt +fail("You did not know the airspeed velocity of an unladen swallow!") ``` \ No newline at end of file diff --git a/docs/CharSequenceAssertions.md b/docs/CharSequenceAssertions.md index 7781857e..8de2cbef 100644 --- a/docs/CharSequenceAssertions.md +++ b/docs/CharSequenceAssertions.md @@ -1,56 +1,57 @@ -# CharSequence assertions - -The following assertions work with every subtype of `CharSequence` (e.g. `String`) - -```kt -"name" shouldBeEqualTo "name" -"name" shouldNotBeEqualTo "abc" - -"name" shouldStartWith "n" -"age" shouldNotStartWith "n" - -"name" shouldEndWith "me" -"name" shouldNotEndWith "ee" - -"name" shouldContain "am" -"name" shouldNotContain "abc" - -"I like fluent assertions" shouldContainSome listOf("fluent", "not", "test") -"I like fluent assertions" shouldContainNone listOf("test, "compile") - -"name" shouldMatch "\\w+" -"name" shouldNotMatch "\\d+" - -"name" shouldMatch Regex("\\w+") -"name" shouldNotMatch Regex("\\d+") - -"".shouldBeEmpty() -"name".shouldNotBeEmpty() - -"".shouldBeNullOrEmpty() -"name".shouldNotBeNullOrEmpty() - -" ".shouldBeBlank() -"name".shouldNotBeBlank() - -" ".shouldBeNullOrBlank() -"".shouldNotBeNullOrBlank() -``` - -In case if you need to assert Char or CharSequence ignoring the characters case, you can use the following assertions: -```kt -"name" shouldBeEqualToIgnoringCase "nAmE" -"name" shouldNotBeEqualToIgnoringCase "abc" - -"name" shouldStartWithIgnoringCase "N" -"age" shouldNotStartWithIgnoringCase "n" - -"name" shouldEndWithIgnoringCase "ME" -"name" shouldNotEndWithIgnoringCase "ee" - -"name" shouldContainIgnoringCase "Am" -"name" shouldNotContainIgnoringCase "abc" - -"I like fluent assertions" shouldContainSomeIgnoringCase listOf("Fluent", "NOT", "tesT") -"I like fluent assertions" shouldContainNoneIgnoringCase listOf("test, "compile") -``` +# CharSequence assertions + +The following assertions work with every subtype of `CharSequence` (e.g. `String`) + +```kt +"name" shouldBeEqualTo "name" +"name" shouldNotBeEqualTo "abc" + +"name" shouldStartWith "n" +"age" shouldNotStartWith "n" + +"name" shouldEndWith "me" +"name" shouldNotEndWith "ee" + +"name" shouldContain "am" +"name" shouldNotContain "abc" + +"I like fluent assertions" shouldContainSome listOf("fluent", "not", "test") +"I like fluent assertions" shouldContainNone listOf("test, "compile") + +"name" shouldMatch "\\w+" +"name" shouldNotMatch "\\d+" + +"name" shouldMatch Regex("\\w+") +"name" shouldNotMatch Regex("\\d+") + +"".shouldBeEmpty() +"name".shouldNotBeEmpty() + +"".shouldBeNullOrEmpty() +"name".shouldNotBeNullOrEmpty() + +" ".shouldBeBlank() +"name".shouldNotBeBlank() + +" ".shouldBeNullOrBlank() +"".shouldNotBeNullOrBlank() +``` + +In case if you need to assert Char or CharSequence ignoring the characters case, you can use the following assertions: + +```kt +"name" shouldBeEqualToIgnoringCase "nAmE" +"name" shouldNotBeEqualToIgnoringCase "abc" + +"name" shouldStartWithIgnoringCase "N" +"age" shouldNotStartWithIgnoringCase "n" + +"name" shouldEndWithIgnoringCase "ME" +"name" shouldNotEndWithIgnoringCase "ee" + +"name" shouldContainIgnoringCase "Am" +"name" shouldNotContainIgnoringCase "abc" + +"I like fluent assertions" shouldContainSomeIgnoringCase listOf("Fluent", "NOT", "tesT") +"I like fluent assertions" shouldContainNoneIgnoringCase listOf("test, "compile") +``` diff --git a/docs/CollectionAssertions.md b/docs/CollectionAssertions.md index 43f77b08..66143964 100644 --- a/docs/CollectionAssertions.md +++ b/docs/CollectionAssertions.md @@ -26,7 +26,9 @@ listOf(10, 15, 20) shouldNotContainAny listOf(5, 7) listOf(1, 2, 3) shouldContainSame listOf(3, 1, 2) ``` -In case of Array or Iterable contain Chars or CharSequences and do not care about the characters case you can use the following assertions: +In case of Array or Iterable contain Chars or CharSequences and do not care about the characters case you can use the +following assertions: + ```kt listOf('abc', 'cda', 'FGT') shouldContainAllIgnoringCase listOf('AbC', 'cDa', 'fgT') listOf('abc', 'cda', 'FGT') shouldNotContainAnyIgnoringCase listOf('ab', 'CD') diff --git a/docs/DefineOwn.md b/docs/DefineOwn.md index 549d2ee1..9ecd5a4c 100644 --- a/docs/DefineOwn.md +++ b/docs/DefineOwn.md @@ -2,7 +2,8 @@ Starting with Kluent 1.32, a generic `should` method was added to build domain specific assertions. -When the receiver function passed to `should` returns `false` *or* throws an exception, it will fail with an optional failure message. +When the receiver function passed to `should` returns `false` *or* throws an exception, it will fail with an optional +failure message. ## Example diff --git a/docs/Equivalency.md b/docs/Equivalency.md index 5008c298..37560da7 100644 --- a/docs/Equivalency.md +++ b/docs/Equivalency.md @@ -4,8 +4,9 @@ Inspired by [Fluent Assertions](/~https://github.com/fluentassertions/fluentassert ## shouldBeEquivalentTo / shouldNotBeEquivalentTo -These assertions are purposed to compare objects and lists of objects not using overridden equals() method, but comparing their property values. -Example. You have a data class: +These assertions are purposed to compare objects and lists of objects not using overridden equals() method, but +comparing their property values. Example. You have a data class: + ```kt data class Person (firstName: String, lastName: String) { var address: String? = null @@ -13,6 +14,7 @@ data class Person (firstName: String, lastName: String) { ``` In case of usual way of comparison, let's say, using shouldBeEqualTo, this assertion will pass: + ```kt // arrange val person1 = Person("John", "Johnson").apply { @@ -24,10 +26,11 @@ val person2 = Person("John", "Johnson") person1.shouldBeEqualTo(person2) ``` -The reason is that the getHashCode()/equals() method of the Person class is called to compare two objects. -But what if you like to compare all object properties one by one? +The reason is that the getHashCode()/equals() method of the Person class is called to compare two objects. But what if +you like to compare all object properties one by one? Here is what you can do: + ```kt // arrange val person1 = Person("John", "Johnson").apply { @@ -38,8 +41,10 @@ Here is what you can do: // assert person1.shouldBeEquivalentTo(person2) ``` -In this case assertion will fail, as the address property of two objects are not the same. -More over, you can compare a hierarchy of objects in the same way: + +In this case assertion will fail, as the address property of two objects are not the same. More over, you can compare a +hierarchy of objects in the same way: + ```kt class Team(val name: String) { var persons: List = listOf() @@ -66,6 +71,7 @@ More over, you can compare a hierarchy of objects in the same way: ``` Both assertions work against a single object, as well as Iterables: + ```kt @ExperimentalStdlibApi fun T.shouldBeEquivalentTo(expected: T, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): T @@ -73,7 +79,9 @@ fun T.shouldBeEquivalentTo(expected: T, config: ((EquivalencyAssertion fun > I.shouldBeEquivalentTo(expected: Iterable, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): I ``` -An important part of both shouldBeEquivalentTo and shouldNotBeEquivalentTo assertions is EquivalencyAssertionOptions which has the following helper methods that you can use to specify the way how you want to compare: +An important part of both shouldBeEquivalentTo and shouldNotBeEquivalentTo assertions is EquivalencyAssertionOptions +which has the following helper methods that you can use to specify the way how you want to compare: + ```kt fun compareByProperties(): EquivalencyAssertionOptions @@ -89,12 +97,15 @@ An important part of both shouldBeEquivalentTo and shouldNotBeEquivalentTo asser ``` ### compareByProperties() + Calling of this function is not necessary, as by default equivalency assertions compare objects exactly by properties. ### excluding/including -By default equivalency assertions use all non-private properties of an object for comparison. And only if all properties are the same, the objects will be treated as equivalent. -Using excluding/including you can specify what properties should be used for comparison. All other properties will be skipped. -Example: + +By default equivalency assertions use all non-private properties of an object for comparison. And only if all properties +are the same, the objects will be treated as equivalent. Using excluding/including you can specify what properties +should be used for comparison. All other properties will be skipped. Example: + ```kt // arrange val team1 = Team("team1").apply { @@ -127,9 +138,12 @@ Example: it.including(Team::persons) } ``` -Although the name property of two objects of the Team class are the same, the assertion will fail, as using including(Team::persons) only the persons property is used for comparison. + +Although the name property of two objects of the Team class are the same, the assertion will fail, as using including( +Team::persons) only the persons property is used for comparison. Another example using excluding: + ```kt // arrange val team1 = Team("team1").apply { @@ -162,11 +176,13 @@ Another example using excluding: it.excluding(Team::persons) } ``` + Here the assertion will pass, as the persons property is excluded - therefore, only the name is compared. ### excludingNestedObjects If you do not want to compare the nested objects and only limit it by the top level object in your hierarchy: + ```kt // arrange val team1 = Team("team1").apply { @@ -189,16 +205,23 @@ If you do not want to compare the nested objects and only limit it by the top le it.excludingNestedObjects() } ``` -In this case only the properties of [primitive types](https://kotlinlang.org/docs/tutorials/kotlin-for-py/primitive-data-types-and-their-limitations.html) and strings are compared. + +In this case only the properties +of [primitive types](https://kotlinlang.org/docs/tutorials/kotlin-for-py/primitive-data-types-and-their-limitations.html) +and strings are compared. ### allowingInfiniteRecursion -The default level of recurrsion in the equivalency assertions is 10. That means, if your object hierarchy contains more than 10 nested objects, even if on the 11th level some object properties are not the same, but everything before that level passed comparision, the assertion will also pass. -Using allowingInfiniteRecursion() you can instruct the Kluent to perform infinite recursion. +The default level of recurrsion in the equivalency assertions is 10. That means, if your object hierarchy contains more +than 10 nested objects, even if on the 11th level some object properties are not the same, but everything before that +level passed comparision, the assertion will also pass. Using allowingInfiniteRecursion() you can instruct the Kluent to +perform infinite recursion. ### withStrictOrdering -By default, if you compare lists of objects, the order they appear in such lists is not important. But if you need to verify also the order, you can use withStrictOrdering: +By default, if you compare lists of objects, the order they appear in such lists is not important. But if you need to +verify also the order, you can use withStrictOrdering: + ```kt // arrange val teams1 = listOf( @@ -251,5 +274,7 @@ By default, if you compare lists of objects, the order they appear in such lists it.withStrictOrdering() } ``` -In this case assertion will fail, as the "team3" in the 2nd list of teams is not at the same position like in the 1st list of teams. + +In this case assertion will fail, as the "team3" in the 2nd list of teams is not at the same position like in the 1st +list of teams. diff --git a/docs/JavaTime.md b/docs/JavaTime.md index 45eeaa4a..890cf897 100644 --- a/docs/JavaTime.md +++ b/docs/JavaTime.md @@ -1,8 +1,11 @@ # java.time Assertions -The following documentation is a overview around the assertions for `java.time.LocalDateTime`, `java.time.LocalDate` and `java.time.LocalTime` +The following documentation is a overview around the assertions for `java.time.LocalDateTime`, `java.time.LocalDate` +and `java.time.LocalTime` -Not all cases are covered, but all methods work as appropriate to the tested datetype. All examples can be found in the [testsuites](/~https://github.com/MarkusAmshove/Kluent/tree/master/src/test/kotlin/org/amshove/kluent/tests/assertions/datetime). +Not all cases are covered, but all methods work as appropriate to the tested datetype. All examples can be found in +the [testsuites](/~https://github.com/MarkusAmshove/Kluent/tree/master/src/test/kotlin/org/amshove/kluent/tests/assertions/datetime) +. There are extension functions for x.years(), x.months(), x.days(), x.hours(), x.minutes() and x.seconds(). diff --git a/docs/NumericalAssertions.md b/docs/NumericalAssertions.md index 2b231695..cadc8f94 100644 --- a/docs/NumericalAssertions.md +++ b/docs/NumericalAssertions.md @@ -26,6 +26,7 @@ The following assertions work for all subtypes of `Number`(`Int`, `Byte`, `Float ``` ## Ranges + ```kt 5.shouldBeInRange(1, 10) 5 shouldBeInRange 1..10 diff --git a/docs/README.md b/docs/README.md index c23b9e67..a8191fe1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,9 @@ Kluent is a "Fluent Assertions" library written specifically for Kotlin. -It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.html#infix-notation "Infix-Notation") and [Extension Functions](https://kotlinlang.org/docs/reference/extensions.html#extension-functions "Extension Functions") of Kotlin to provide a fluent wrapper around JUnit-Asserts and Mockito. +It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.html#infix-notation "Infix-Notation") +and [Extension Functions](https://kotlinlang.org/docs/reference/extensions.html#extension-functions "Extension Functions") +of Kotlin to provide a fluent wrapper around JUnit-Asserts and Mockito. [How to contribute](../CONTRIBUTING.md) @@ -10,8 +12,7 @@ It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.ht [Changelog](/~https://github.com/MarkusAmshove/Kluent/blob/master/CHANGELOG.md) -[ ![Download](https://api.bintray.com/packages/markusamshove/maven/kluent/images/download.svg) ](https://bintray.com/markusamshove/maven/Kluent/_latestVersion) - +[ ![Download](https://api.bintray.com/packages/markusamshove/maven/kluent/images/download.svg) ](https://bintray.com/markusamshove/maven/Kluent/_latestVersion) | Platform | Status | | --- | --- | @@ -49,11 +50,13 @@ Every method that is included in Kluent also has a "backtick version", to make i Some examples: ### assertEquals ## + "hello" shouldBeEqualTo "hello" "hello".shouldBeEqualTo("hello") "hello" `should be equal to` "hello" ### assertNotEquals ## + "hello" shouldNotBeEqualTo "world" "hello".shouldNotBeEqualTo("world") "hello" `should not be equal to` "world" diff --git a/docs/SoftlyAssertions.md b/docs/SoftlyAssertions.md index f74907a9..ff85224c 100644 --- a/docs/SoftlyAssertions.md +++ b/docs/SoftlyAssertions.md @@ -1,8 +1,9 @@ -#Softly Assertions +# Softly Assertions Inspired by [Kotest](/~https://github.com/kotest/kotest): Usually if an assertion fails, it throws an exception, so you can immediately note that your test fails: + ```kt fun houseTest() { // arrange @@ -75,8 +76,7 @@ As the result: *The following assertion failed:* *Expected <2>, actual <3>.* -But why is it failed? Why 6 guests occupied 3 rooms? -Now let's move our assertions into assertSoftly: +But why is it failed? Why 6 guests occupied 3 rooms? Now let's move our assertions into assertSoftly: ```kt fun houseTest() { @@ -151,11 +151,12 @@ Now we get all assertions at once: *org.amshove.kluent.MultiAssertionError:* *The following 2 assertions failed:* *1) Expected <2>, actual <3>.* - *at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:147)* +*at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:147)* *2) Expected <6>, actual <5>.* - *at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:148)* +*at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:148)* If you like, you can use a bit different syntax achieving the same result: + ```kt assertSoftly(house) { rooms.size.shouldBeEqualTo(2) @@ -164,7 +165,9 @@ If you like, you can use a bit different syntax achieving the same result: ``` ## Compatibility note + The following assertions are not compatible with `assertSoftly` and exit the test immediately after failure: + * `assertFails` * `shouldNotBeNull` * `a.shouldBeInstanceOf()` \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4c0811c3..ab902053 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,7 @@ -kotlin_version = 1.3.50 -kotlin_native_gradle_plugin_version = 1.3.41 -kotlinx_coroutines_version = 1.3.0 - -gradle_node_version = 1.2.0 -node_version = 8.9.3 -npm_version = 5.5.1 - +kotlin_version=1.3.50 +kotlin_native_gradle_plugin_version=1.3.41 +kotlinx_coroutines_version=1.3.0 +gradle_node_version=1.2.0 +node_version=8.9.3 +npm_version=5.5.1 kotlin.incremental.multiplatform=true diff --git a/js/build.gradle b/js/build.gradle index 28fdfc68..cab4b26d 100644 --- a/js/build.gradle +++ b/js/build.gradle @@ -57,7 +57,7 @@ test.dependsOn runMocha compileKotlin2Js { kotlinOptions { freeCompilerArgs += [ - '-Xuse-experimental=kotlin.Experimental' + '-Xuse-experimental=kotlin.Experimental' ] } } diff --git a/js/package.json b/js/package.json index f3e54387..77c4b588 100644 --- a/js/package.json +++ b/js/package.json @@ -1,12 +1,12 @@ { - "name": "kotlin-js", - "description": "Kluent JavaScript implementation", - "licesnse": "MIT", - "repository": "/~https://github.com/MarkusAmshove/Kluent", - "devDependencies": { - "mocha": "^4.1.0" - }, - "dependencies": { - "source-map-support": "^0.5.19" - } + "name": "kotlin-js", + "description": "Kluent JavaScript implementation", + "licesnse": "MIT", + "repository": "/~https://github.com/MarkusAmshove/Kluent", + "devDependencies": { + "mocha": "^4.1.0" + }, + "dependencies": { + "source-map-support": "^0.5.19" + } } diff --git a/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt index 8bb00f31..32ebc5bc 100644 --- a/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt +++ b/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -8,17 +8,21 @@ internal actual fun hardFail(message: String?): Nothing { } @PublishedApi -internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { +internal actual fun checkResultIsFailure( + exceptionClass: KClass, + message: String?, + blockResult: Result +): T { blockResult.fold( - onSuccess = { - hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") - }, - onFailure = { e -> - if (exceptionClass.isInstance(e)) { - @Suppress("UNCHECKED_CAST") - return e as T - } - hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + onSuccess = { + hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T } + hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + } ) } diff --git a/js/src/test/kotlin/assertions/softly/AssertSoftly.kt b/js/src/test/kotlin/assertions/softly/AssertSoftly.kt index 89589a12..fa9b8748 100644 --- a/js/src/test/kotlin/assertions/softly/AssertSoftly.kt +++ b/js/src/test/kotlin/assertions/softly/AssertSoftly.kt @@ -15,11 +15,13 @@ class AssertSoftly { length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following 2 assertions failed: |1) Expected the CharSequence ab1 to contain 2 |2) Expected 3 to be greater or equal to 4""" - .trimMargin(), e.message!!.trimMargin()) + .trimMargin(), e.message!!.trimMargin() + ) } } @@ -49,10 +51,12 @@ class AssertSoftly { length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following assertion failed: |Expected the CharSequence ab1 to contain 2""" - .trimMargin(), e.message!!.trimMargin()) + .trimMargin(), e.message!!.trimMargin() + ) } } @@ -70,11 +74,13 @@ class AssertSoftly { a.length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ | |The following assertion failed: |Expected 3 to be greater or equal to 4 - |""".trimMargin(), e.message!!) + |""".trimMargin(), e.message!! + ) } } @@ -98,6 +104,7 @@ class AssertSoftly { return true } } + class House(val maxGuests: Int = 5) { private var _rooms: MutableList = mutableListOf() private var _guests: MutableList = mutableListOf() @@ -146,11 +153,13 @@ class AssertSoftly { house.guests.size.shouldBeEqualTo(5) } } catch (e: Throwable) { - e.message!!.trimMargin().shouldBeEqualTo(""" + e.message!!.trimMargin().shouldBeEqualTo( + """ The following 2 assertions failed: 1) Expected <2>, actual <3>. 2) Expected <6>, actual <5>. - """.trimMargin()) + """.trimMargin() + ) } } @@ -187,13 +196,15 @@ class AssertSoftly { list shouldContainSame listOf('x', 'z') } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following 2 assertions failed: |1) Expected collection size to be 2 but was 3 |2) The collection doesn't have the same items |Items included on the expected collection but not in the actual: [] |Items included on the actual collection but not in the expected: [y] - """.trimMargin(), e.message!!.trimMargin()) + """.trimMargin(), e.message!!.trimMargin() + ) } } diff --git a/jvm/build.gradle b/jvm/build.gradle index 3f4ffd2f..44656dc0 100644 --- a/jvm/build.gradle +++ b/jvm/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'kotlin-platform-jvm' apply plugin: 'jacoco' def isAndroid = project.rootProject.hasProperty("ANDROID") -if(isAndroid) { +if (isAndroid) { logger.warn("Android build!") } @@ -29,7 +29,7 @@ sourceSets { kotlin { srcDir 'src/main/kotlin' - if(isAndroid) { + if (isAndroid) { exclude '**/*Backtick*' } } @@ -38,7 +38,7 @@ sourceSets { kotlin { srcDir 'src/test/kotlin' - if(isAndroid) { + if (isAndroid) { exclude '**/backtick*/**', '**/*Backtick*' } } @@ -50,7 +50,7 @@ tasks.withType(compileKotlin.getClass()) { jvmTarget = isAndroid ? '1.6' : '1.8' freeCompilerArgs += [ - '-Xuse-experimental=kotlin.Experimental' + '-Xuse-experimental=kotlin.Experimental' ] } } diff --git a/jvm/src/main/kotlin/org/amshove/kluent/BasicBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/BasicBacktick.kt index b8bd25c0..d756a84f 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/BasicBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/BasicBacktick.kt @@ -82,7 +82,9 @@ fun Char.`should be digit`(): Char = this.shouldBeDigit() fun Char.`should not be digit`(): Char = this.shouldNotBeDigit() @ExperimentalStdlibApi -infix fun T.`should be equivalent to`(expected: Pair EquivalencyAssertionOptions)?>): T = this.shouldBeEquivalentTo(expected.first, expected.second) +infix fun T.`should be equivalent to`(expected: Pair EquivalencyAssertionOptions)?>): T = + this.shouldBeEquivalentTo(expected.first, expected.second) @ExperimentalStdlibApi -infix fun T.`should not be equivalent to`(expected: Pair EquivalencyAssertionOptions)?>): T = this.shouldNotBeEquivalentTo(expected.first, expected.second) +infix fun T.`should not be equivalent to`(expected: Pair EquivalencyAssertionOptions)?>): T = + this.shouldNotBeEquivalentTo(expected.first, expected.second) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/BigDecimal.kt b/jvm/src/main/kotlin/org/amshove/kluent/BigDecimal.kt index 094df8d0..aa27b024 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/BigDecimal.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/BigDecimal.kt @@ -5,6 +5,7 @@ package org.amshove.kluent import org.amshove.kluent.internal.assertTrue import java.math.BigDecimal + @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun BigDecimal.shouldEqualTo(expected: BigDecimal) = this.shouldBeEqualTo(expected) @@ -42,10 +43,10 @@ infix fun BigDecimal.shouldNotBeLessOrEqualTo(expected: BigDecimal) = this.apply { assertTrue("Expected $this to not be less or equal to $expected", this.compareTo(expected) > 0) } fun BigDecimal.shouldBePositive() = - this.apply { assertTrue("Expected $this to be positive", this.compareTo(java.math.BigDecimal.ZERO) > 0) } + this.apply { assertTrue("Expected $this to be positive", this.compareTo(BigDecimal.ZERO) > 0) } fun BigDecimal.shouldBeNegative() = - this.apply { assertTrue("Expected $this to be negative", this.compareTo(java.math.BigDecimal.ZERO) < 0) } + this.apply { assertTrue("Expected $this to be negative", this.compareTo(BigDecimal.ZERO) < 0) } fun BigDecimal.shouldBeInRange(lowerBound: BigDecimal, upperBound: BigDecimal) = this.apply { assertTrue( diff --git a/jvm/src/main/kotlin/org/amshove/kluent/CharSequenceBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/CharSequenceBacktick.kt index 9be33c0c..57656432 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/CharSequenceBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/CharSequenceBacktick.kt @@ -17,7 +17,8 @@ infix fun T.`should contain`(expected: CharSequence) = this.s infix fun T.`should not contain`(char: Char) = this.shouldNotContain(char) -infix fun T.`should not contain any`(things: Iterable) = this.shouldNotContainAny(things) +infix fun T.`should not contain any`(things: Iterable) = + this.shouldNotContainAny(things) infix fun T.`should match`(regex: String) = this.shouldMatch(regex) @@ -51,10 +52,10 @@ infix fun T.`should not match`(regex: String) = this.shouldNo infix fun T.`should not match`(regex: Regex) = this.shouldNotMatch(regex) -fun T.`should not be empty`(): T = this.shouldNotBeEmpty() +fun T.`should not be empty`(): T = this.shouldNotBeEmpty() @UseExperimental(ExperimentalContracts::class) -fun T?.`should not be null or empty`(): T { +fun T?.`should not be null or empty`(): T { contract { returns() implies (this@`should not be null or empty` != null) } @@ -62,10 +63,10 @@ fun T?.`should not be null or empty`(): T { return this.shouldNotBeNullOrEmpty() } -fun T.`should not be blank`(): T = this.shouldNotBeBlank() +fun T.`should not be blank`(): T = this.shouldNotBeBlank() @UseExperimental(ExperimentalContracts::class) -fun T?.`should not be null or blank`(): T { +fun T?.`should not be null or blank`(): T { contract { returns() implies (this@`should not be null or blank` != null) } @@ -73,7 +74,8 @@ fun T?.`should not be null or blank`(): T { return this.shouldNotBeNullOrBlank() } -infix fun T.`should contain all`(items: Iterable): CharSequence = this.shouldContainAll(items) +infix fun T.`should contain all`(items: Iterable): CharSequence = + this.shouldContainAll(items) infix fun T.`should not contain all`(items: Iterable): CharSequence = this.shouldNotContainAll(items) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt index 55eeb2ec..4475e44f 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/CollectionsBacktick.kt @@ -48,17 +48,20 @@ infix fun IntArray.`should not contain`(expected: Int) = this.shouldNotContain(e infix fun IntArray.`should not contain any`(expected: IntArray) = this.shouldNotContainAny(expected) -infix fun IntArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun IntArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun Int.`should be in`(theArray: IntArray) = this.shouldBeIn(theArray) infix fun Int.`should not be in`(theArray: IntArray) = this.shouldNotBeIn(theArray) + @Deprecated("Use `should be equal to`", ReplaceWith("this.`should be equal to`(expected)")) infix fun BooleanArray.`should equal`(expected: BooleanArray) = this.`should be equal to`(expected) infix fun BooleanArray.`should be equal to`(expected: BooleanArray) = this.shouldBeEqualTo(expected) -infix fun BooleanArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun BooleanArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) fun BooleanArray.`should be empty`() = this.shouldBeEmpty() @@ -95,7 +98,8 @@ fun ByteArray.`should not be empty`() = this.shouldNotBeEmpty() infix fun ByteArray.`should contain`(expected: Byte) = this.shouldContain(expected) -infix fun ByteArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun ByteArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) @Deprecated("Use `should contain any`", ReplaceWith("this `should contain any` check")) infix fun ByteArray.`should contain some`(expected: ByteArray) = this.shouldContainSome(expected) @@ -125,7 +129,8 @@ fun CharArray.`should not be empty`() = this.shouldNotBeEmpty() infix fun CharArray.`should contain`(expected: Char) = this.shouldContain(expected) -infix fun CharArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun CharArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) @Deprecated("Use `should contain any`", ReplaceWith("this `should contain any` check")) infix fun CharArray.`should contain some`(expected: CharArray) = this.shouldContainSome(expected) @@ -153,7 +158,8 @@ fun DoubleArray.`should be empty`() = this.shouldBeEmpty() fun DoubleArray.`should not be empty`() = this.shouldNotBeEmpty() -infix fun DoubleArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun DoubleArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun DoubleArray.`should contain`(expected: Double) = this.shouldContain(expected) @@ -198,7 +204,8 @@ infix fun FloatArray.`should not contain`(expected: Float) = this.shouldNotConta infix fun FloatArray.`should not contain any`(expected: FloatArray) = this.shouldNotContainAny(expected) -infix fun FloatArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun FloatArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun Float.`should be in`(theArray: FloatArray) = this.shouldBeIn(theArray) @@ -228,7 +235,8 @@ infix fun LongArray.`should not contain`(expected: Long) = this.shouldNotContain infix fun LongArray.`should not contain any`(expected: LongArray) = this.shouldNotContainAny(expected) -infix fun LongArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun LongArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun Long.`should be in`(theArray: LongArray) = this.shouldBeIn(theArray) @@ -258,7 +266,8 @@ infix fun ShortArray.`should not contain`(expected: Short) = this.shouldNotConta infix fun ShortArray.`should not contain any`(expected: ShortArray) = this.shouldNotContainAny(expected) -infix fun ShortArray.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun ShortArray.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun Short.`should be in`(theArray: ShortArray) = this.shouldBeIn(theArray) @@ -297,7 +306,8 @@ fun > I.`should be empty`(): I = this.shouldBeEmpty() fun > I.`should not be empty`(): I = this.shouldNotBeEmpty() -infix fun > I.`should be sorted according to`(comparator: Comparator) = this.shouldBeSortedAccordingTo(comparator) +infix fun > I.`should be sorted according to`(comparator: Comparator) = + this.shouldBeSortedAccordingTo(comparator) infix fun > M.`should have key`(theKey: K): M = this.shouldHaveKey(theKey) @@ -343,7 +353,8 @@ infix fun CharArray.`should contain same`(expected: CharArray) = this.shouldCont infix fun > ClosedRange.`should be in range`(target: ClosedRange) = this.shouldBeInRange(target) -infix fun > ClosedRange.`should not be in range`(target: ClosedRange) = this.shouldNotBeInRange(target) +infix fun > ClosedRange.`should not be in range`(target: ClosedRange) = + this.shouldNotBeInRange(target) infix fun Array.`should match at least one of`(predicate: (E) -> Boolean): Array { return shouldMatchAtLeastOneOf(predicate) @@ -376,6 +387,7 @@ infix fun CharArray.`should match at least one of`(predicate: (Char) -> Boolean) infix fun IntArray.`should match at least one of`(predicate: (Int) -> Boolean): IntArray { return shouldMatchAtLeastOneOf(predicate) } + infix fun Array.`should match all with`(predicate: (E) -> Boolean): Array { return shouldMatchAllWith(predicate) } @@ -409,8 +421,14 @@ infix fun IntArray.`should match all with`(predicate: (Int) -> Boolean): IntArra } @ExperimentalStdlibApi -fun > I.`should be equivalent to`(expected: Iterable, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null) = this.shouldBeEquivalentTo(expected, config) +fun > I.`should be equivalent to`( + expected: Iterable, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +) = this.shouldBeEquivalentTo(expected, config) @ExperimentalStdlibApi -fun > I.`should not be equivalent to`(expected: Iterable, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null) = this.shouldNotBeEquivalentTo(expected, config) +fun > I.`should not be equivalent to`( + expected: Iterable, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +) = this.shouldNotBeEquivalentTo(expected, config) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/DateTime.kt b/jvm/src/main/kotlin/org/amshove/kluent/DateTime.kt index 69d1845f..4c4df339 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/DateTime.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/DateTime.kt @@ -3,13 +3,17 @@ package org.amshove.kluent import org.amshove.kluent.internal.assertTrue import java.time.* -infix fun LocalDateTime.shouldBeAfter(expected: LocalDateTime) = assertTrue("Expected $this to be after $expected", this > expected) +infix fun LocalDateTime.shouldBeAfter(expected: LocalDateTime) = + assertTrue("Expected $this to be after $expected", this > expected) -infix fun LocalDateTime.shouldBeAfter(theTime: LocalTime) = assertTrue("Expected $this to be after $theTime", this.toLocalTime() > theTime) +infix fun LocalDateTime.shouldBeAfter(theTime: LocalTime) = + assertTrue("Expected $this to be after $theTime", this.toLocalTime() > theTime) -infix fun LocalDateTime.shouldBeBefore(expected: LocalDateTime) = assertTrue("Expected $this to be before $expected", this < expected) +infix fun LocalDateTime.shouldBeBefore(expected: LocalDateTime) = + assertTrue("Expected $this to be before $expected", this < expected) -infix fun LocalDateTime.shouldBeBefore(theTime: LocalTime) = assertTrue("Expected $this to be before $theTime", this.toLocalTime() < theTime) +infix fun LocalDateTime.shouldBeBefore(theTime: LocalTime) = + assertTrue("Expected $this to be before $theTime", this.toLocalTime() < theTime) infix fun LocalDateTime.shouldBeInHour(theHour: Int) = this.toLocalTime() shouldBeInHour theHour @@ -23,41 +27,56 @@ infix fun LocalDateTime.shouldBeInSecond(theSecond: Int) = this.toLocalTime() sh infix fun LocalDateTime.shouldNotBeInSecond(theSecond: Int) = this.toLocalTime() shouldNotBeInSecond theSecond -infix fun LocalDateTime.shouldBeOnOrAfter(theDate: LocalDateTime) = assertTrue("Expected $this to be on or after $theDate", this >= theDate) +infix fun LocalDateTime.shouldBeOnOrAfter(theDate: LocalDateTime) = + assertTrue("Expected $this to be on or after $theDate", this >= theDate) -infix fun LocalDateTime.shouldBeOnOrBefore(theDate: LocalDateTime) = assertTrue("Expected $this to be on or before $theDate", this <= theDate) +infix fun LocalDateTime.shouldBeOnOrBefore(theDate: LocalDateTime) = + assertTrue("Expected $this to be on or before $theDate", this <= theDate) -infix fun LocalDateTime.shouldBeOn(theDay: DayOfWeek) = assertTrue("Expected $this to be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek == theDay) +infix fun LocalDateTime.shouldBeOn(theDay: DayOfWeek) = + assertTrue("Expected $this to be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek == theDay) infix fun LocalDateTime.shouldNotBeOn(theDay: DayOfWeek) = this.toLocalDate() shouldNotBeOn theDay -infix fun LocalDateTime.shouldBeIn(theMonth: Month) = assertTrue("Expected $this to be in $theMonth, but was ${this.month}", this.month == theMonth) +infix fun LocalDateTime.shouldBeIn(theMonth: Month) = + assertTrue("Expected $this to be in $theMonth, but was ${this.month}", this.month == theMonth) infix fun LocalDateTime.shouldNotBeIn(theMonth: Month) = this.toLocalDate() shouldNotBeIn theMonth -infix fun LocalDateTime.shouldBeInYear(theYear: Int) = assertTrue("Expected $this to be in $theYear, but was ${this.year}", this.year == theYear) +infix fun LocalDateTime.shouldBeInYear(theYear: Int) = + assertTrue("Expected $this to be in $theYear, but was ${this.year}", this.year == theYear) infix fun LocalDateTime.shouldNotBeInYear(theYear: Int) = this.toLocalDate() shouldNotBeInYear theYear -infix fun LocalDate.shouldBeAfter(expected: LocalDate) = assertTrue("Expected $this to be after $expected", this > expected) +infix fun LocalDate.shouldBeAfter(expected: LocalDate) = + assertTrue("Expected $this to be after $expected", this > expected) -infix fun LocalDate.shouldBeBefore(expected: LocalDate) = assertTrue("Expected $this to be before $expected", this < expected) +infix fun LocalDate.shouldBeBefore(expected: LocalDate) = + assertTrue("Expected $this to be before $expected", this < expected) -infix fun LocalDate.shouldBeOnOrAfter(theDate: LocalDate) = assertTrue("Expected $this to be on or after $theDate", this >= theDate) +infix fun LocalDate.shouldBeOnOrAfter(theDate: LocalDate) = + assertTrue("Expected $this to be on or after $theDate", this >= theDate) -infix fun LocalDate.shouldBeOnOrBefore(theDate: LocalDate) = assertTrue("Expected $this to be on or before $theDate", this <= theDate) +infix fun LocalDate.shouldBeOnOrBefore(theDate: LocalDate) = + assertTrue("Expected $this to be on or before $theDate", this <= theDate) -infix fun LocalDate.shouldBeOn(theDay: DayOfWeek) = assertTrue("Expected $this to be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek == theDay) +infix fun LocalDate.shouldBeOn(theDay: DayOfWeek) = + assertTrue("Expected $this to be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek == theDay) -infix fun LocalDate.shouldNotBeOn(theDay: DayOfWeek) = assertTrue("Expected $this to not be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek != theDay) +infix fun LocalDate.shouldNotBeOn(theDay: DayOfWeek) = + assertTrue("Expected $this to not be a $theDay, but was ${this.dayOfWeek}", this.dayOfWeek != theDay) -infix fun LocalDate.shouldBeIn(theMonth: Month) = assertTrue("Expected $this to be in $theMonth, but was ${this.month}", this.month == theMonth) +infix fun LocalDate.shouldBeIn(theMonth: Month) = + assertTrue("Expected $this to be in $theMonth, but was ${this.month}", this.month == theMonth) -infix fun LocalDate.shouldNotBeIn(theMonth: Month) = assertTrue("Expected $this to not be in $theMonth, but was ${this.month}", this.month != theMonth) +infix fun LocalDate.shouldNotBeIn(theMonth: Month) = + assertTrue("Expected $this to not be in $theMonth, but was ${this.month}", this.month != theMonth) -infix fun LocalDate.shouldBeInYear(theYear: Int) = assertTrue("Expected $this to be in $theYear, but was ${this.year}", this.year == theYear) +infix fun LocalDate.shouldBeInYear(theYear: Int) = + assertTrue("Expected $this to be in $theYear, but was ${this.year}", this.year == theYear) -infix fun LocalDate.shouldNotBeInYear(theYear: Int) = assertTrue("Expected $this to not be in $theYear, but was ${this.year}", this.year != theYear) +infix fun LocalDate.shouldNotBeInYear(theYear: Int) = + assertTrue("Expected $this to not be in $theYear, but was ${this.year}", this.year != theYear) fun Int.hours() = TimeComparator(addedHours = this) fun Int.minutes() = TimeComparator(addedMinutes = this) @@ -68,39 +87,55 @@ fun Int.days() = DateComparator(addedDays = this) infix fun LocalTime.shouldBe(timeComparator: TimeComparator) = timeComparator.withStartValue(this) -infix fun LocalTime.shouldBeAtLeast(timeComparator: TimeComparator) = timeComparator.withStartValue(this).withComparatorType(ComparatorType.AtLeast) +infix fun LocalTime.shouldBeAtLeast(timeComparator: TimeComparator) = + timeComparator.withStartValue(this).withComparatorType(ComparatorType.AtLeast) -infix fun LocalTime.shouldBeAtMost(timeComparator: TimeComparator) = timeComparator.withStartValue(this).withComparatorType(ComparatorType.AtMost) +infix fun LocalTime.shouldBeAtMost(timeComparator: TimeComparator) = + timeComparator.withStartValue(this).withComparatorType(ComparatorType.AtMost) -infix fun LocalTime.shouldBeInHour(theHour: Int) = assertTrue("Expected $this to be in hour $theHour", this.hour == theHour) +infix fun LocalTime.shouldBeInHour(theHour: Int) = + assertTrue("Expected $this to be in hour $theHour", this.hour == theHour) -infix fun LocalTime.shouldNotBeInHour(theHour: Int) = assertTrue("Expected $this to not be in hour $theHour", this.hour != theHour) +infix fun LocalTime.shouldNotBeInHour(theHour: Int) = + assertTrue("Expected $this to not be in hour $theHour", this.hour != theHour) -infix fun LocalTime.shouldBeInMinute(theMinute: Int) = assertTrue("Expected $this to be in minute $theMinute", this.minute == theMinute) +infix fun LocalTime.shouldBeInMinute(theMinute: Int) = + assertTrue("Expected $this to be in minute $theMinute", this.minute == theMinute) -infix fun LocalTime.shouldNotBeInMinute(theMinute: Int) = assertTrue("Expected $this to not be in minute $theMinute", this.minute != theMinute) +infix fun LocalTime.shouldNotBeInMinute(theMinute: Int) = + assertTrue("Expected $this to not be in minute $theMinute", this.minute != theMinute) -infix fun LocalTime.shouldBeInSecond(theSecond: Int) = assertTrue("Expected $this to be in second $theSecond", this.second == theSecond) +infix fun LocalTime.shouldBeInSecond(theSecond: Int) = + assertTrue("Expected $this to be in second $theSecond", this.second == theSecond) -infix fun LocalTime.shouldNotBeInSecond(theSecond: Int) = assertTrue("Expected $this to not be in second $theSecond", this.second != theSecond) +infix fun LocalTime.shouldNotBeInSecond(theSecond: Int) = + assertTrue("Expected $this to not be in second $theSecond", this.second != theSecond) infix fun LocalDate.shouldBe(dateComparator: DateComparator) = dateComparator.withStartValue(this) -infix fun LocalDate.shouldBeAtLeast(dateComparator: DateComparator) = dateComparator.withStartValue(this).withComparatorType(ComparatorType.AtLeast) +infix fun LocalDate.shouldBeAtLeast(dateComparator: DateComparator) = + dateComparator.withStartValue(this).withComparatorType(ComparatorType.AtLeast) -infix fun LocalDate.shouldBeAtMost(dateComparator: DateComparator) = dateComparator.withStartValue(this).withComparatorType(ComparatorType.AtMost) +infix fun LocalDate.shouldBeAtMost(dateComparator: DateComparator) = + dateComparator.withStartValue(this).withComparatorType(ComparatorType.AtMost) -infix fun LocalDateTime.shouldBe(dateComparator: DateComparator): DateTimeComparator = DateTimeComparator(dateComparator).withStartValue(this) as DateTimeComparator +infix fun LocalDateTime.shouldBe(dateComparator: DateComparator): DateTimeComparator = + DateTimeComparator(dateComparator).withStartValue(this) as DateTimeComparator -infix fun LocalDateTime.shouldBeAtLeast(dateComparator: DateComparator) = DateTimeComparator(dateComparator).withStartValue(this).withComparatorType(ComparatorType.AtLeast) +infix fun LocalDateTime.shouldBeAtLeast(dateComparator: DateComparator) = + DateTimeComparator(dateComparator).withStartValue(this).withComparatorType(ComparatorType.AtLeast) -infix fun LocalDateTime.shouldBeAtMost(dateComparator: DateComparator) = DateTimeComparator(dateComparator).withStartValue(this).withComparatorType(ComparatorType.AtMost) +infix fun LocalDateTime.shouldBeAtMost(dateComparator: DateComparator) = + DateTimeComparator(dateComparator).withStartValue(this).withComparatorType(ComparatorType.AtMost) -infix fun LocalDateTime.shouldBe(timeComparator: TimeComparator) = DateTimeComparator(timeComparator = timeComparator).withStartValue(this) as DateTimeComparator +infix fun LocalDateTime.shouldBe(timeComparator: TimeComparator) = + DateTimeComparator(timeComparator = timeComparator).withStartValue(this) as DateTimeComparator -infix fun LocalDateTime.shouldBeAtLeast(timeComparator: TimeComparator) = DateTimeComparator(timeComparator = timeComparator).withStartValue(this).withComparatorType(ComparatorType.AtLeast) +infix fun LocalDateTime.shouldBeAtLeast(timeComparator: TimeComparator) = + DateTimeComparator(timeComparator = timeComparator).withStartValue(this).withComparatorType(ComparatorType.AtLeast) -infix fun LocalDateTime.shouldBeAtMost(timeComparator: TimeComparator) = DateTimeComparator(timeComparator = timeComparator).withStartValue(this).withComparatorType(ComparatorType.AtMost) +infix fun LocalDateTime.shouldBeAtMost(timeComparator: TimeComparator) = + DateTimeComparator(timeComparator = timeComparator).withStartValue(this).withComparatorType(ComparatorType.AtMost) infix fun > AbstractJavaTimeComparator.after(expected: T) = this.assertAfter(expected) infix fun > AbstractJavaTimeComparator.before(expected: T) = this.assertBefore(expected) @@ -119,4 +154,5 @@ internal enum class ComparatorType { infix fun Instant.shouldBeAfter(expected: Instant) = assertTrue("Expected $this to be after $expected", this > expected) -infix fun Instant.shouldBeBefore(expected: Instant) = assertTrue("Expected $this to be before $expected", this < expected) +infix fun Instant.shouldBeBefore(expected: Instant) = + assertTrue("Expected $this to be before $expected", this < expected) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt b/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt index 2927907c..011599f3 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt @@ -8,29 +8,44 @@ import kotlin.reflect.KVisibility import kotlin.reflect.full.declaredMemberProperties @ExperimentalStdlibApi -fun T.shouldBeEquivalentTo(expected: T, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): T = this.apply { assertEquivalency(false, expected, this, config) } +fun T.shouldBeEquivalentTo( + expected: T, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +): T = this.apply { assertEquivalency(false, expected, this, config) } @ExperimentalStdlibApi -fun T.shouldNotBeEquivalentTo(expected: T, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null) = this.apply { assertEquivalency(true, expected, this, config) } +fun T.shouldNotBeEquivalentTo( + expected: T, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +) = this.apply { assertEquivalency(true, expected, this, config) } @ExperimentalStdlibApi -fun > I.shouldBeEquivalentTo(expected: Iterable, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): I = assertBothIterablesBeEquivalent(expected.toList(), this.toList(), config) +fun > I.shouldBeEquivalentTo( + expected: Iterable, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +): I = assertBothIterablesBeEquivalent(expected.toList(), this.toList(), config) @ExperimentalStdlibApi -fun > I.shouldNotBeEquivalentTo(expected: Iterable, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): I = assertBothIterablesBeNotEquivalent(expected.toList(), this.toList(), config) +fun > I.shouldNotBeEquivalentTo( + expected: Iterable, + config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +): I = assertBothIterablesBeNotEquivalent(expected.toList(), this.toList(), config) @ExperimentalStdlibApi @Throws(NoSuchMethodException::class, InvocationTargetException::class, IllegalAccessException::class) @Suppress("UNCHECKED_CAST") -internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T, equivalencyAssertionOptions: EquivalencyAssertionOptions): Boolean { +internal fun areEquivalent( + recursionLevel: Int, + actual: T, + expected: T, + equivalencyAssertionOptions: EquivalencyAssertionOptions +): Boolean { val currentLevelOfRecursion = recursionLevel + 1 - if (actual is Boolean || actual is Byte || actual is Short || actual is Int || actual is Long || actual is Float || actual is Double || actual is Char) - { + if (actual is Boolean || actual is Byte || actual is Short || actual is Int || actual is Long || actual is Float || actual is Double || actual is Char) { return actual == expected } - if (actual is CharSequence || actual is String) - { + if (actual is CharSequence || actual is String) { return (actual as String).equals(expected as String, true) } @@ -38,9 +53,24 @@ internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T val expectedKClass = expected::class // make the list of properties to compare - val propertiesToCompare = actualKClass.declaredMemberProperties.filter { it.visibility != KVisibility.PRIVATE }.toMutableList() - equivalencyAssertionOptions.excludedProperties.forEach { excludedProperty -> propertiesToCompare.removeIf { it.name.equals(excludedProperty.name, true) } } - equivalencyAssertionOptions.includedProperties.forEach { includedProperty -> propertiesToCompare.removeAll { !it.name.equals(includedProperty.name, true) } } + val propertiesToCompare = + actualKClass.declaredMemberProperties.filter { it.visibility != KVisibility.PRIVATE }.toMutableList() + equivalencyAssertionOptions.excludedProperties.forEach { excludedProperty -> + propertiesToCompare.removeIf { + it.name.equals( + excludedProperty.name, + true + ) + } + } + equivalencyAssertionOptions.includedProperties.forEach { includedProperty -> + propertiesToCompare.removeAll { + !it.name.equals( + includedProperty.name, + true + ) + } + } for (mA in propertiesToCompare) { val mB = expectedKClass.declaredMemberProperties.single { it.name == mA.name } as KProperty1 @@ -54,12 +84,14 @@ internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T return false } else -> if (subA != null && subB == null - || subA == null && subB != null) { + || subA == null && subB != null + ) { return false } else if (subA != null && subB != null) { if (subA is Iterable<*>) { if ((currentLevelOfRecursion == equivalencyAssertionOptions.maxLevelOfRecursion && !equivalencyAssertionOptions.allowingInfiniteRecursion) - || equivalencyAssertionOptions.excludingNestedObjects) { + || equivalencyAssertionOptions.excludingNestedObjects + ) { return true } val actualList = subA.toList() @@ -72,7 +104,12 @@ internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T if (expectedList.size > j) { equivalencyAssertionOptions.includedProperties.clear() equivalencyAssertionOptions.excludedProperties.clear() - val deepEquals = areEquivalent(currentLevelOfRecursion, actualList[i]!!, expectedList[j]!!, equivalencyAssertionOptions) + val deepEquals = areEquivalent( + currentLevelOfRecursion, + actualList[i]!!, + expectedList[j]!!, + equivalencyAssertionOptions + ) if (deepEquals) { expectedList.removeAt(j) } @@ -82,14 +119,20 @@ internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T for (i in expectedList.indices) { equivalencyAssertionOptions.includedProperties.clear() equivalencyAssertionOptions.excludedProperties.clear() - val deepEquals = areEquivalent(currentLevelOfRecursion, actualList[i]!!, expectedList[i]!!, equivalencyAssertionOptions) + val deepEquals = areEquivalent( + currentLevelOfRecursion, + actualList[i]!!, + expectedList[i]!!, + equivalencyAssertionOptions + ) if (!deepEquals) { return false } } } else { if ((currentLevelOfRecursion == equivalencyAssertionOptions.maxLevelOfRecursion && !equivalencyAssertionOptions.allowingInfiniteRecursion) - || equivalencyAssertionOptions.excludingNestedObjects) { + || equivalencyAssertionOptions.excludingNestedObjects + ) { return true } equivalencyAssertionOptions.includedProperties.clear() @@ -105,7 +148,11 @@ internal fun areEquivalent(recursionLevel: Int, actual: T, expected: T } @Suppress("UNCHECKED_CAST") -private fun T.toStructuredString(recursionLevel: Int, structuredStringBuilder: StringBuilder, writeClassName: Boolean = true) { +private fun T.toStructuredString( + recursionLevel: Int, + structuredStringBuilder: StringBuilder, + writeClassName: Boolean = true +) { val objClass = this::class var className = "${objClass.simpleName}" className = className.padStart(className.length + recursionLevel, '-') @@ -117,10 +164,10 @@ private fun T.toStructuredString(recursionLevel: Int, structuredString var primitiveTypesAdded = false // enumerate through primitive types for (property in objClass.declaredMemberProperties.filter { it.visibility != KVisibility.PRIVATE } - .map { it to (it as KProperty1).invoke(this) } - .filter { - it.second is Number || it.second is Date || it.second is Boolean || it.second is String || it.second is Enum<*> - } + .map { it to (it as KProperty1).invoke(this) } + .filter { + it.second is Number || it.second is Date || it.second is Boolean || it.second is String || it.second is Enum<*> + } ) { if (!primitiveTypesAdded) { structuredStringBuilder.append(" (") @@ -144,36 +191,42 @@ private fun T.toStructuredString(recursionLevel: Int, structuredString // enumerate through complex types for (property in objClass.declaredMemberProperties.filter { it.visibility != KVisibility.PRIVATE } - .map { it to (it as KProperty1).invoke(this) } - .filter { - !(it.second is Number || it.second is Date || it.second is Boolean || it.second is String || it.second is Enum<*>) && it.second != null - } + .map { it to (it as KProperty1).invoke(this) } + .filter { + !(it.second is Number || it.second is Date || it.second is Boolean || it.second is String || it.second is Enum<*>) && it.second != null + } ) - try { - structuredStringBuilder.append('˪') + try { + structuredStringBuilder.append('˪') - if (property.second!!::class.declaredMemberProperties.all { it.visibility == KVisibility.PRIVATE }) { - structuredStringBuilder.append("${property.first.name} = ${property.second!!}") - } else { - if (property.second is Iterable<*>) { - var propertyName = property.first.name - propertyName = propertyName.padStart(propertyName.length + recursionLevel + 1, '-') - structuredStringBuilder.append("${propertyName}${System.lineSeparator()}") - (property.second!! as Iterable<*>).iterableToStructuredString(recursionLevel + 1, structuredStringBuilder) + if (property.second!!::class.declaredMemberProperties.all { it.visibility == KVisibility.PRIVATE }) { + structuredStringBuilder.append("${property.first.name} = ${property.second!!}") } else { - property.second!!.toStructuredString(recursionLevel + 1, structuredStringBuilder) + if (property.second is Iterable<*>) { + var propertyName = property.first.name + propertyName = propertyName.padStart(propertyName.length + recursionLevel + 1, '-') + structuredStringBuilder.append("${propertyName}${System.lineSeparator()}") + (property.second!! as Iterable<*>).iterableToStructuredString( + recursionLevel + 1, + structuredStringBuilder + ) + } else { + property.second!!.toStructuredString(recursionLevel + 1, structuredStringBuilder) + } } + } catch (e: NoSuchMethodException) { + structuredStringBuilder.append("${property.first.name} = ") + } catch (e: InvocationTargetException) { + structuredStringBuilder.append("${property.first.name} = ") + } catch (e: IllegalAccessException) { + structuredStringBuilder.append("${property.first.name} = ") } - } catch (e: NoSuchMethodException) { - structuredStringBuilder.append("${property.first.name} = ") - } catch (e: InvocationTargetException) { - structuredStringBuilder.append("${property.first.name} = ") - } catch (e: IllegalAccessException) { - structuredStringBuilder.append("${property.first.name} = ") - } } -private fun > T.iterableToStructuredString(recursionLevel: Int, structuredStringBuilder: StringBuilder) { +private fun > T.iterableToStructuredString( + recursionLevel: Int, + structuredStringBuilder: StringBuilder +) { val list = this.toList() for (i in list.indices) { @@ -186,24 +239,37 @@ private fun > T.iterableToStructuredString(recursionLevel: Int, } @ExperimentalStdlibApi -private fun assertEquivalency(not: Boolean = false, expected: T, actual: T, equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null) { +private fun assertEquivalency( + not: Boolean = false, + expected: T, + actual: T, + equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +) { val actualStructure: StringBuilder = StringBuilder() val expectedStructure: StringBuilder = StringBuilder() val options = equivalencyAssertionOptions?.invoke(EquivalencyAssertionOptions()) - ?: EquivalencyAssertionOptions() + ?: EquivalencyAssertionOptions() if (options.compareByProperties) { if (!not.xor(areEquivalent(0, actual, expected, options))) { actual.toStructuredString(0, actualStructure) expected.toStructuredString(0, expectedStructure) if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { try { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } catch (ex: ComparisonFailure) { errorCollector.pushError(ex) } } else { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } } } else { @@ -216,19 +282,32 @@ private fun assertEquivalency(not: Boolean = false, expected: T, actua } @ExperimentalStdlibApi -private fun C.assertBothIterablesBeEquivalent(expected: Iterable, actual: Iterable, equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): C { +private fun C.assertBothIterablesBeEquivalent( + expected: Iterable, + actual: Iterable, + equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +): C { assertBothCollectionsEquivalency(false, expected.toList(), actual.toList(), equivalencyAssertionOptions) return this } @ExperimentalStdlibApi -private fun C.assertBothIterablesBeNotEquivalent(expected: Iterable, actual: Iterable, equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): C { +private fun C.assertBothIterablesBeNotEquivalent( + expected: Iterable, + actual: Iterable, + equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +): C { assertBothCollectionsEquivalency(true, expected.toList(), actual.toList(), equivalencyAssertionOptions) return this } @ExperimentalStdlibApi -private fun assertBothCollectionsEquivalency(not: Boolean = false, expectedList: List, actualList: List, equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null) { +private fun assertBothCollectionsEquivalency( + not: Boolean = false, + expectedList: List, + actualList: List, + equivalencyAssertionOptions: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null +) { val actualStructure: StringBuilder = java.lang.StringBuilder() val expectedStructure: StringBuilder = java.lang.StringBuilder() @@ -241,12 +320,20 @@ private fun assertBothCollectionsEquivalency(not: Boolean = false, exp } if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { try { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } catch (ex: ComparisonFailure) { errorCollector.pushError(ex) } } else { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } } @@ -256,7 +343,7 @@ private fun assertBothCollectionsEquivalency(not: Boolean = false, exp } val options = equivalencyAssertionOptions?.invoke(EquivalencyAssertionOptions()) - ?: EquivalencyAssertionOptions() + ?: EquivalencyAssertionOptions() if (options.withStrictOrdering) { var areEquivalentWithStrictOrdering = true @@ -275,12 +362,20 @@ private fun assertBothCollectionsEquivalency(not: Boolean = false, exp val exceptionMessage = "Are not equivalent with strict ordering:" if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { try { - fail(exceptionMessage, expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + exceptionMessage, + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } catch (ex: ComparisonFailure) { errorCollector.pushError(ex) } } else { - fail(exceptionMessage, expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + exceptionMessage, + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } } } else { @@ -295,7 +390,8 @@ private fun assertBothCollectionsEquivalency(not: Boolean = false, exp } } for (i in remainingItemIndicesOnExpectedList.indices) { - val deepEquals = areEquivalent(0, actualList[i], expectedList[remainingItemIndicesOnExpectedList[i]], options) + val deepEquals = + areEquivalent(0, actualList[i], expectedList[remainingItemIndicesOnExpectedList[i]], options) if (deepEquals) { remainingItemIndicesOnExpectedList.remove(i) } @@ -308,12 +404,20 @@ private fun assertBothCollectionsEquivalency(not: Boolean = false, exp } if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { try { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } catch (ex: ComparisonFailure) { errorCollector.pushError(ex) } } else { - fail(EquivalencyExceptionMessage.exceptionMessage(not), expectedStructure.toString().plus(System.lineSeparator()), actualStructure.toString().plus(System.lineSeparator())) + fail( + EquivalencyExceptionMessage.exceptionMessage(not), + expectedStructure.toString().plus(System.lineSeparator()), + actualStructure.toString().plus(System.lineSeparator()) + ) } } } diff --git a/jvm/src/main/kotlin/org/amshove/kluent/EquivalencyAssertionOptions.kt b/jvm/src/main/kotlin/org/amshove/kluent/EquivalencyAssertionOptions.kt index 69c730e3..8e547e7b 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/EquivalencyAssertionOptions.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/EquivalencyAssertionOptions.kt @@ -15,18 +15,24 @@ class EquivalencyAssertionOptions { internal var compareByProperties get() = _compareByProperties - private set(value) { _compareByProperties = value } + private set(value) { + _compareByProperties = value + } internal val includedProperties: MutableList> = mutableListOf() internal val excludedProperties: MutableList> = mutableListOf() internal var excludingNestedObjects get() = _excludingNestedObjects - private set(value) { _excludingNestedObjects = value } + private set(value) { + _excludingNestedObjects = value + } internal var allowingInfiniteRecursion get() = _allowingInfiniteRecursion - private set(value) { _allowingInfiniteRecursion = value } + private set(value) { + _allowingInfiniteRecursion = value + } internal var maxLevelOfRecursion get() = _maxLevelOfRecursion @@ -36,7 +42,9 @@ class EquivalencyAssertionOptions { internal var withStrictOrdering get() = _withStrictOrdering - private set(value) { _withStrictOrdering = value } + private set(value) { + _withStrictOrdering = value + } fun compareByProperties(): EquivalencyAssertionOptions { diff --git a/jvm/src/main/kotlin/org/amshove/kluent/Exceptions.kt b/jvm/src/main/kotlin/org/amshove/kluent/Exceptions.kt index f2a3f596..300b21b4 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/Exceptions.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/Exceptions.kt @@ -19,7 +19,11 @@ actual infix fun (() -> Any?).shouldThrow(expectedException: KCl e.isA(ComparisonFailure::class) -> throw e e.isA(ComparisonFailedException::class) -> throw e e.isA(expectedException) -> return ExceptionResult(e as T) - else -> throw ComparisonFailure("Expected ${expectedException.javaObjectType} to be thrown", "${expectedException.javaObjectType}", "${e.javaClass}") + else -> throw ComparisonFailure( + "Expected ${expectedException.javaObjectType} to be thrown", + "${expectedException.javaObjectType}", + "${e.javaClass}" + ) } } } @@ -35,7 +39,11 @@ suspend infix fun (suspend () -> Any?).shouldThrow(expectedExcep e.isA(ComparisonFailure::class) -> throw e e.isA(ComparisonFailedException::class) -> throw e e.isA(expectedException) -> return ExceptionResult(e as T) - else -> throw ComparisonFailure("Expected ${expectedException.javaObjectType} to be thrown", "${expectedException.javaObjectType}", "${e.javaClass}") + else -> throw ComparisonFailure( + "Expected ${expectedException.javaObjectType} to be thrown", + "${expectedException.javaObjectType}", + "${e.javaClass}" + ) } } } @@ -49,7 +57,11 @@ infix fun (() -> Any?).shouldNotThrow(expectedException: KClass< fail("Expected no Exception to be thrown", "No Exception", "${e.javaClass}") } if (e.isA(expectedException)) { - fail("Expected no Exception of type ${e::class.qualifiedName} to be thrown", "No Exception", e.toInformativeString()) + fail( + "Expected no Exception of type ${e::class.qualifiedName} to be thrown", + "No Exception", + e.toInformativeString() + ) } NotThrowExceptionResult(e) } @@ -64,7 +76,11 @@ suspend infix fun (suspend () -> Any?).shouldNotThrow(expectedEx fail("Expected no Exception to be thrown", "No Exception", "${e.javaClass}") } if (e.isA(expectedException)) { - fail("Expected no Exception of type ${e::class.qualifiedName} to be thrown", "No Exception", e.toInformativeString()) + fail( + "Expected no Exception of type ${e::class.qualifiedName} to be thrown", + "No Exception", + e.toInformativeString() + ) } NotThrowExceptionResult(e) } @@ -93,10 +109,12 @@ suspend infix fun (suspend () -> Any?).shouldThrow(expectedExcep } @Deprecated("Use shouldThrow instead", ReplaceWith("this shouldThrow expectedException")) -infix fun (() -> Any).shouldThrowTheException(expectedException: KClass): ExceptionResult = this shouldThrow expectedException +infix fun (() -> Any).shouldThrowTheException(expectedException: KClass): ExceptionResult = + this shouldThrow expectedException @Deprecated("Use shouldNotThrow instead", ReplaceWith("this shouldNotThrow expectedException")) -infix fun (() -> Any).shouldNotThrowTheException(expectedException: KClass): NotThrowExceptionResult = this.shouldNotThrow(expectedException) +infix fun (() -> Any).shouldNotThrowTheException(expectedException: KClass): NotThrowExceptionResult = + this.shouldNotThrow(expectedException) infix fun ExceptionResult.withMessage(theMessage: String): ExceptionResult { this.exceptionMessage shouldBeEqualTo theMessage @@ -118,14 +136,16 @@ infix fun NotThrowExceptionResult.withCause(expectedCause: KClass return this } -infix fun ExceptionResult.with(block: T.() -> R): R = block(exception) +infix fun ExceptionResult.with(block: T.() -> R): R = block(exception) val AnyException = AnyExceptionType::class class AnyExceptionType : Throwable() internal val noException = Exception("None") -internal fun Throwable.isA(expected: KClass) = expected.isAnyException() || expected.java.isAssignableFrom(this.javaClass) +internal fun Throwable.isA(expected: KClass) = + expected.isAnyException() || expected.java.isAssignableFrom(this.javaClass) + internal fun KClass.isAnyException() = this.javaObjectType == AnyException.javaObjectType actual fun fail(message: String, expected: Any?, actual: Any?) { errorCollector.collectOrThrow(ComparisonFailedException(message, expected, actual)) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/ExceptionsBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/ExceptionsBacktick.kt index b953b611..637acaf1 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/ExceptionsBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/ExceptionsBacktick.kt @@ -2,21 +2,26 @@ package org.amshove.kluent import kotlin.reflect.KClass -infix fun (() -> Any?).`should throw`(expectedException: KClass) = this.shouldThrow(expectedException) +infix fun (() -> Any?).`should throw`(expectedException: KClass) = + this.shouldThrow(expectedException) -infix fun (() -> Any?).`should not throw`(expectedException: KClass) = this.shouldNotThrow(expectedException) +infix fun (() -> Any?).`should not throw`(expectedException: KClass) = + this.shouldNotThrow(expectedException) @Deprecated("Use `should throw` instead", ReplaceWith("this `should throw` expectedException")) -infix fun (() -> Any).`should throw the Exception`(expectedException: KClass) = this.shouldThrow(expectedException) +infix fun (() -> Any).`should throw the Exception`(expectedException: KClass) = + this.shouldThrow(expectedException) @Deprecated("Use `should not throw` instead", ReplaceWith("this `should not throw` expectedException")) -infix fun (() -> Any).`should not throw the Exception`(expectedException: KClass) = this `should not throw` expectedException +infix fun (() -> Any).`should not throw the Exception`(expectedException: KClass) = + this `should not throw` expectedException infix fun ExceptionResult.`with message`(theMessage: String) = this.withMessage(theMessage) infix fun NotThrowExceptionResult.`with message`(theMessage: String) = this.withMessage(theMessage) -infix fun ExceptionResult.`with cause`(expectedCause: KClass) = this.withCause(expectedCause) +infix fun ExceptionResult.`with cause`(expectedCause: KClass) = + this.withCause(expectedCause) infix fun NotThrowExceptionResult.`with cause`(expectedCause: KClass) = this.withCause(expectedCause) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/File.kt b/jvm/src/main/kotlin/org/amshove/kluent/File.kt index 8b0285e9..b0ae0cd9 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/File.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/File.kt @@ -8,8 +8,11 @@ import java.nio.charset.Charset fun File.shouldExist() = assertTrue("The file '${this.absolutePath}' should exist, but does not", this.exists()) fun File.shouldNotExist() = assertFalse("The file '${this.absolutePath}' should not exist, but does", this.exists()) -fun File.shouldBeDir() = assertTrue("The file '${this.absolutePath}' should be a directory, but is not", this.isDirectory) -fun File.shouldNotBeDir() = assertFalse("The file '${this.absolutePath}' should not be a directory, but is", this.isDirectory) +fun File.shouldBeDir() = + assertTrue("The file '${this.absolutePath}' should be a directory, but is not", this.isDirectory) + +fun File.shouldNotBeDir() = + assertFalse("The file '${this.absolutePath}' should not be a directory, but is", this.isDirectory) fun File.shouldBeFile() = assertTrue("The file '${this.absolutePath}' should be a file, but is not", this.isFile) fun File.shouldNotBeFile() = assertFalse("The file '${this.absolutePath}' should not be a file, but is", this.isFile) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/FileBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/FileBacktick.kt index 7846edc1..c285f39d 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/FileBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/FileBacktick.kt @@ -11,12 +11,11 @@ fun File.`should not be dir`() = this.shouldNotBeDir() fun File.`should be file`() = this.shouldBeFile() fun File.`should not be file`() = this.shouldNotBeFile() -infix fun File.`should have extension`(other: String) = this shouldHaveExtension(other) -infix fun File.`should not have extension`(other: String) = this shouldNotHaveExtension(other) +infix fun File.`should have extension`(other: String) = this shouldHaveExtension (other) +infix fun File.`should not have extension`(other: String) = this shouldNotHaveExtension (other) infix fun File.`should have name`(other: String) = this shouldHaveName (other) infix fun File.`should not have name`(other: String) = this shouldNotHaveName (other) infix fun File.`should contain line with string`(other: String) = this shouldContainLineWithString (other) infix fun File.`should not contain line with string`(other: String) = this shouldNotContainLineWithString (other) - diff --git a/jvm/src/main/kotlin/org/amshove/kluent/JavaTimeComparators.kt b/jvm/src/main/kotlin/org/amshove/kluent/JavaTimeComparators.kt index 60558fde..06bca562 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/JavaTimeComparators.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/JavaTimeComparators.kt @@ -10,18 +10,18 @@ abstract class AbstractJavaTimeComparator where T : Comparable { internal lateinit var startValue: T internal fun assertAfter(theOther: T) = - when (comparatorType) { - ComparatorType.AtLeast -> assertAtLeastAfter(calculateComparedValue(theOther)) - ComparatorType.Exactly -> assertExactlyAfter(calculateComparedValue(theOther)) - ComparatorType.AtMost -> assertAtMostAfter(calculateComparedValue(theOther)) - } + when (comparatorType) { + ComparatorType.AtLeast -> assertAtLeastAfter(calculateComparedValue(theOther)) + ComparatorType.Exactly -> assertExactlyAfter(calculateComparedValue(theOther)) + ComparatorType.AtMost -> assertAtMostAfter(calculateComparedValue(theOther)) + } internal fun assertBefore(theOther: T) = - when (comparatorType) { - ComparatorType.AtLeast -> assertAtLeastBefore(calculateComparedValue(theOther, -1)) - ComparatorType.Exactly -> assertExactlyBefore(calculateComparedValue(theOther, -1)) - ComparatorType.AtMost -> assertAtMostBefore(calculateComparedValue(theOther, -1)) - } + when (comparatorType) { + ComparatorType.AtLeast -> assertAtLeastBefore(calculateComparedValue(theOther, -1)) + ComparatorType.Exactly -> assertExactlyBefore(calculateComparedValue(theOther, -1)) + ComparatorType.AtMost -> assertAtMostBefore(calculateComparedValue(theOther, -1)) + } internal fun withStartValue(startValue: T): AbstractJavaTimeComparator { this.startValue = startValue @@ -34,11 +34,17 @@ abstract class AbstractJavaTimeComparator where T : Comparable { } protected fun assertAtLeastAfter(theOther: T) { - assertTrue("Expected $startValue to be at least { ${getExpectedOffset()} } after $theOther", startValue >= theOther) + assertTrue( + "Expected $startValue to be at least { ${getExpectedOffset()} } after $theOther", + startValue >= theOther + ) } protected fun assertAtMostAfter(theOther: T) { - assertTrue("Expected $startValue to be at most { ${getExpectedOffset()} } after $theOther", startValue <= theOther) + assertTrue( + "Expected $startValue to be at most { ${getExpectedOffset()} } after $theOther", + startValue <= theOther + ) } protected fun assertExactlyAfter(theOther: T) { @@ -50,11 +56,17 @@ abstract class AbstractJavaTimeComparator where T : Comparable { } protected fun assertAtLeastBefore(theOther: T) { - assertTrue("Expected $startValue to be at least { ${getExpectedOffset()} } before $theOther", startValue <= theOther) + assertTrue( + "Expected $startValue to be at least { ${getExpectedOffset()} } before $theOther", + startValue <= theOther + ) } protected fun assertAtMostBefore(theOther: T) { - assertTrue("Expected $startValue to be at most { ${getExpectedOffset()} } before $theOther", startValue >= theOther) + assertTrue( + "Expected $startValue to be at most { ${getExpectedOffset()} } before $theOther", + startValue >= theOther + ) } protected abstract fun calculateComparedValue(currentValue: T, multiplier: Int = 1): T @@ -62,44 +74,67 @@ abstract class AbstractJavaTimeComparator where T : Comparable { } -class DateTimeComparator(internal var dateComparator: DateComparator? = null, internal var timeComparator: TimeComparator? = null) : AbstractJavaTimeComparator() { +class DateTimeComparator( + internal var dateComparator: DateComparator? = null, + internal var timeComparator: TimeComparator? = null +) : AbstractJavaTimeComparator() { - internal fun assertAfter(theDate: LocalDate) = dateComparator!!.withStartValue(startValue.toLocalDate()).withComparatorType(comparatorType).assertAfter(theDate) - internal fun assertBefore(theDate: LocalDate) = dateComparator!!.withStartValue(startValue.toLocalDate()).withComparatorType(comparatorType).assertBefore(theDate) - internal fun assertAfter(theTime: LocalTime) = timeComparator!!.withStartValue(startValue.toLocalTime()).withComparatorType(comparatorType).assertAfter(theTime) - internal fun assertBefore(theTime: LocalTime) = timeComparator!!.withStartValue(startValue.toLocalTime()).withComparatorType(comparatorType).assertBefore(theTime) + internal fun assertAfter(theDate: LocalDate) = + dateComparator!!.withStartValue(startValue.toLocalDate()).withComparatorType(comparatorType) + .assertAfter(theDate) - override fun getExpectedOffset() = "${dateComparator?.getExpectedOffset()} ${timeComparator?.getExpectedOffset()}".trim() + internal fun assertBefore(theDate: LocalDate) = + dateComparator!!.withStartValue(startValue.toLocalDate()).withComparatorType(comparatorType) + .assertBefore(theDate) + + internal fun assertAfter(theTime: LocalTime) = + timeComparator!!.withStartValue(startValue.toLocalTime()).withComparatorType(comparatorType) + .assertAfter(theTime) + + internal fun assertBefore(theTime: LocalTime) = + timeComparator!!.withStartValue(startValue.toLocalTime()).withComparatorType(comparatorType) + .assertBefore(theTime) + + override fun getExpectedOffset() = + "${dateComparator?.getExpectedOffset()} ${timeComparator?.getExpectedOffset()}".trim() override fun calculateComparedValue(currentValue: LocalDateTime, multiplier: Int) = - currentValue.plusYears((dateComparator?.addedYears?.toLong() ?: 0) * multiplier) - .plusMonths((dateComparator?.addedMonths?.toLong() ?: 0) * multiplier) - .plusDays((dateComparator?.addedDays?.toLong() ?: 0) * multiplier) - .plusHours((timeComparator?.addedHours?.toLong() ?: 0) * multiplier) - .plusMinutes((timeComparator?.addedMinutes?.toLong() ?: 0) * multiplier) - .plusSeconds((timeComparator?.addedSeconds?.toLong() ?: 0) * multiplier) + currentValue.plusYears((dateComparator?.addedYears?.toLong() ?: 0) * multiplier) + .plusMonths((dateComparator?.addedMonths?.toLong() ?: 0) * multiplier) + .plusDays((dateComparator?.addedDays?.toLong() ?: 0) * multiplier) + .plusHours((timeComparator?.addedHours?.toLong() ?: 0) * multiplier) + .plusMinutes((timeComparator?.addedMinutes?.toLong() ?: 0) * multiplier) + .plusSeconds((timeComparator?.addedSeconds?.toLong() ?: 0) * multiplier) } -class DateComparator(internal val addedYears: Int = 0, internal val addedMonths: Int = 0, internal val addedDays: Int = 0) : AbstractJavaTimeComparator() { +class DateComparator( + internal val addedYears: Int = 0, + internal val addedMonths: Int = 0, + internal val addedDays: Int = 0 +) : AbstractJavaTimeComparator() { override fun calculateComparedValue(currentValue: LocalDate, multiplier: Int) = - currentValue.plusYears(addedYears.toLong() * multiplier) - .plusMonths(addedMonths.toLong() * multiplier) - .plusDays(addedDays.toLong() * multiplier) + currentValue.plusYears(addedYears.toLong() * multiplier) + .plusMonths(addedMonths.toLong() * multiplier) + .plusDays(addedDays.toLong() * multiplier) override fun getExpectedOffset() = "$addedYears years, $addedMonths months, $addedDays days" } -class TimeComparator(internal val addedHours: Int = 0, internal val addedMinutes: Int = 0, internal val addedSeconds: Int = 0) : AbstractJavaTimeComparator() { +class TimeComparator( + internal val addedHours: Int = 0, + internal val addedMinutes: Int = 0, + internal val addedSeconds: Int = 0 +) : AbstractJavaTimeComparator() { override fun getExpectedOffset() = "$addedHours hours, $addedMinutes minutes, $addedSeconds seconds" override fun calculateComparedValue(currentValue: LocalTime, multiplier: Int) = - currentValue.plusHours(addedHours.toLong() * multiplier) - .plusMinutes(addedMinutes.toLong() * multiplier) - .plusSeconds(addedSeconds.toLong() * multiplier) + currentValue.plusHours(addedHours.toLong() * multiplier) + .plusMinutes(addedMinutes.toLong() * multiplier) + .plusSeconds(addedSeconds.toLong() * multiplier) } diff --git a/jvm/src/main/kotlin/org/amshove/kluent/NumericalBacktick.kt b/jvm/src/main/kotlin/org/amshove/kluent/NumericalBacktick.kt index 1e95c19a..cc743f71 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/NumericalBacktick.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/NumericalBacktick.kt @@ -79,7 +79,8 @@ infix fun > T.`should not be greater than`(expected: T) = this infix fun > T.`should be greater or equal to`(expected: T) = this.shouldBeGreaterOrEqualTo(expected) -infix fun > T.`should not be greater or equal to`(expected: T) = this.shouldNotBeGreaterOrEqualTo(expected) +infix fun > T.`should not be greater or equal to`(expected: T) = + this.shouldNotBeGreaterOrEqualTo(expected) infix fun > T.`should be less than`(expected: T) = this.shouldBeLessThan(expected) @@ -117,9 +118,11 @@ fun Float.`should be near`(expected: Float, delta: Float) = this.shouldBeNear(ex fun Double.`should be near`(expected: Double, delta: Double) = this.shouldBeNear(expected, delta) -fun > T.`should be in range`(lowerBound: T, upperBound: T) = this.shouldBeInRange(lowerBound, upperBound) +fun > T.`should be in range`(lowerBound: T, upperBound: T) = + this.shouldBeInRange(lowerBound, upperBound) -fun > T.`should not be in range`(lowerBound: T, upperBound: T) = this.shouldNotBeInRange(lowerBound, upperBound) +fun > T.`should not be in range`(lowerBound: T, upperBound: T) = + this.shouldNotBeInRange(lowerBound, upperBound) infix fun Byte.`should be in range`(range: IntRange) = this.shouldBeInRange(range) @@ -140,4 +143,5 @@ infix fun Long.`should not be in range`(range: LongRange) = this.shouldNotBeInRa infix fun > T.`should be in range`(range: ClosedRange) = this.shouldBeInRange(range) infix fun > T.`should not be in range`(range: ClosedRange) = this.shouldNotBeInRange(range) infix fun > T.`should be in range`(range: ClosedFloatingPointRange) = this.shouldBeInRange(range) -infix fun > T.`should not be in range`(range: ClosedFloatingPointRange) = this.shouldNotBeInRange(range) +infix fun > T.`should not be in range`(range: ClosedFloatingPointRange) = + this.shouldNotBeInRange(range) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/Reflection.kt b/jvm/src/main/kotlin/org/amshove/kluent/Reflection.kt index 692507d8..06338324 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/Reflection.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/Reflection.kt @@ -6,15 +6,20 @@ import org.amshove.kluent.internal.failExpectedActual import org.amshove.kluent.internal.hardFail import kotlin.reflect.KClass -infix fun Any?.shouldBeInstanceOf(className: Class<*>) = assertTrue("Expected $this to be an instance of $className", className.isInstance(this)) +infix fun Any?.shouldBeInstanceOf(className: Class<*>) = + assertTrue("Expected $this to be an instance of $className", className.isInstance(this)) -infix fun Any?.shouldBeInstanceOf(className: KClass<*>) = assertTrue("Expected $this to be an instance of $className", className.isInstance(this)) +infix fun Any?.shouldBeInstanceOf(className: KClass<*>) = + assertTrue("Expected $this to be an instance of $className", className.isInstance(this)) -inline fun Any?.shouldBeInstanceOf(): T = if (this is T) this else hardFail("Expected $this to be an instance or subclass of ${T::class.qualifiedName}") +inline fun Any?.shouldBeInstanceOf(): T = + if (this is T) this else hardFail("Expected $this to be an instance or subclass of ${T::class.qualifiedName}") -infix fun Any?.shouldNotBeInstanceOf(className: Class<*>) = assertFalse("Expected $this to not be an instance of $className", className.isInstance(this)) +infix fun Any?.shouldNotBeInstanceOf(className: Class<*>) = + assertFalse("Expected $this to not be an instance of $className", className.isInstance(this)) -infix fun Any?.shouldNotBeInstanceOf(className: KClass<*>) = assertFalse("Expected $this to not be an instance of $className", className.isInstance(this)) +infix fun Any?.shouldNotBeInstanceOf(className: KClass<*>) = + assertFalse("Expected $this to not be an instance of $className", className.isInstance(this)) inline fun Any?.shouldNotBeInstanceOf() = also { if (this is T) { @@ -24,13 +29,21 @@ inline fun Any?.shouldNotBeInstanceOf() = also { infix fun T?.shouldHaveTheSameClassAs(other: Any) = apply { if (!haveSameClasses(this, other)) { - failExpectedActual("Expected objects to have the same class", this?.javaClass?.kotlin?.qualifiedName, other::class.qualifiedName!!) + failExpectedActual( + "Expected objects to have the same class", + this?.javaClass?.kotlin?.qualifiedName, + other::class.qualifiedName!! + ) } } infix fun T?.shouldNotHaveTheSameClassAs(other: Any) = apply { - if(haveSameClasses(this, other)) { - failExpectedActual("Expected objects to not have the same class", this?.javaClass?.kotlin?.qualifiedName, other::class.qualifiedName!!) + if (haveSameClasses(this, other)) { + failExpectedActual( + "Expected objects to not have the same class", + this?.javaClass?.kotlin?.qualifiedName, + other::class.qualifiedName!! + ) } } diff --git a/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt index d2321084..da230440 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -4,20 +4,24 @@ import kotlin.reflect.KClass /** Asserts that a [blockResult] is a failure with the specific exception type being thrown. */ @PublishedApi -internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { +internal actual fun checkResultIsFailure( + exceptionClass: KClass, + message: String?, + blockResult: Result +): T { blockResult.fold( - onSuccess = { - val msg = messagePrefix(message) - hardFail(msg + "Expected an exception of ${exceptionClass.java} to be thrown, but was completed successfully.") - }, - onFailure = { e -> - if (exceptionClass.java.isInstance(e)) { - @Suppress("UNCHECKED_CAST") - return e as T - } - - hardFail(messagePrefix(message) + "Expected an exception of ${exceptionClass.java} to be thrown, but was $e") + onSuccess = { + val msg = messagePrefix(message) + hardFail(msg + "Expected an exception of ${exceptionClass.java} to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.java.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T } + + hardFail(messagePrefix(message) + "Expected an exception of ${exceptionClass.java} to be thrown, but was $e") + } ) } diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt index a634551e..f4e42545 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt @@ -2,8 +2,8 @@ package org.amshove.kluent.tests.assertions.bigdecimal import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeGreaterOrEqualTo -import kotlin.test.Test import java.math.BigDecimal +import kotlin.test.Test class BigDecimalShouldBeGreaterOrEqualToShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt index 2bfdfc97..02073ed0 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt @@ -8,20 +8,22 @@ import kotlin.test.Test class BigDecimalShouldBeInRangeShould { @Test fun passWhenAValueIsWithinTheRange() { - BigDecimal("0.15").shouldBeInRange(BigDecimal.valueOf(10, 2), BigDecimal.valueOf(10, 1) ) - BigDecimal("0.15").shouldBeInRange(BigDecimal.valueOf(10, 2) .. BigDecimal.valueOf(10, 1) ) + BigDecimal("0.15").shouldBeInRange(BigDecimal.valueOf(10, 2), BigDecimal.valueOf(10, 1)) + BigDecimal("0.15").shouldBeInRange(BigDecimal.valueOf(10, 2)..BigDecimal.valueOf(10, 1)) } @Test fun passWhenAValueIsExactlyTheLowerBound() { - BigDecimal.valueOf(1000, -1000).shouldBeInRange(BigDecimal.valueOf(1000, -1000), BigDecimal.valueOf(1005, -1000)) - BigDecimal.valueOf(1000, -1000).shouldBeInRange(BigDecimal.valueOf(1000, -1000) .. BigDecimal.valueOf(1005, -1000)) + BigDecimal.valueOf(1000, -1000) + .shouldBeInRange(BigDecimal.valueOf(1000, -1000), BigDecimal.valueOf(1005, -1000)) + BigDecimal.valueOf(1000, -1000) + .shouldBeInRange(BigDecimal.valueOf(1000, -1000)..BigDecimal.valueOf(1005, -1000)) } @Test fun passWhenAValueIsExactlyTheUpperBound() { BigDecimal.valueOf(1000, -1).shouldBeInRange(BigDecimal("1000"), BigDecimal("10000")) - BigDecimal.valueOf(1000, -1).shouldBeInRange(BigDecimal("1000") .. BigDecimal("10000")) + BigDecimal.valueOf(1000, -1).shouldBeInRange(BigDecimal("1000")..BigDecimal("10000")) } @Test @@ -30,7 +32,7 @@ class BigDecimalShouldBeInRangeShould { BigDecimal("500").shouldBeInRange(BigDecimal("600"), BigDecimal("700")) } assertFails { - BigDecimal("500").shouldBeInRange(BigDecimal("600") .. BigDecimal("700")) + BigDecimal("500").shouldBeInRange(BigDecimal("600")..BigDecimal("700")) } } @@ -40,7 +42,7 @@ class BigDecimalShouldBeInRangeShould { BigDecimal("800").shouldBeInRange(BigDecimal("600"), BigDecimal("700")) } assertFails { - BigDecimal("800").shouldBeInRange(BigDecimal("600") .. BigDecimal("700")) + BigDecimal("800").shouldBeInRange(BigDecimal("600")..BigDecimal("700")) } } } \ No newline at end of file diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt index aeeed404..44793281 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt @@ -2,8 +2,8 @@ package org.amshove.kluent.tests.assertions.bigdecimal import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNegative -import kotlin.test.Test import java.math.BigDecimal +import kotlin.test.Test class BigDecimalShouldBeNegativeShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt index 351d4e7d..f39d132a 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt @@ -2,8 +2,8 @@ package org.amshove.kluent.tests.assertions.bigdecimal import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBePositive -import kotlin.test.Test import java.math.BigDecimal +import kotlin.test.Test class BigDecimalShouldBePositiveShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt index f272293f..bdcf5f86 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt @@ -9,13 +9,13 @@ class BigDecimalShouldNotBeInRangeShould { @Test fun passWhenAValueIsBelowTheLowerBound() { BigDecimal("500").shouldNotBeInRange(BigDecimal("600"), BigDecimal("700")) - BigDecimal("500").shouldNotBeInRange(BigDecimal("600") .. BigDecimal("700")) + BigDecimal("500").shouldNotBeInRange(BigDecimal("600")..BigDecimal("700")) } @Test fun passWhenAValueIsAboveTheUpperBound() { BigDecimal("800").shouldNotBeInRange(BigDecimal("600"), BigDecimal("700")) - BigDecimal("800").shouldNotBeInRange(BigDecimal("600") .. BigDecimal("700")) + BigDecimal("800").shouldNotBeInRange(BigDecimal("600")..BigDecimal("700")) } @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowShould.kt index 3966c059..e304dcba 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldNotThrowShould.kt @@ -72,7 +72,7 @@ class ShouldNotThrowShould { @Test fun passWhenTestingAFunctionThatThrowsAnExceptionWithADifferentMessage() { invoking { throw IllegalArgumentException("Actual Message") } shouldNotThrow - IllegalAccessException::class withMessage "Expected Message" + IllegalAccessException::class withMessage "Expected Message" } @Test @@ -82,14 +82,14 @@ class ShouldNotThrowShould { suspendCancellableCoroutine { throw IllegalArgumentException("Actual Message") } } coInvoking { func() } shouldNotThrow - IllegalAccessException::class withMessage "Expected Message" + IllegalAccessException::class withMessage "Expected Message" } @Test fun failWhenTestingAFunctionThatThrowsAnExceptionWithTheSameMessage() { assertFails { invoking { throw IllegalArgumentException("Actual Message") } shouldNotThrow - IllegalAccessException::class withMessage "Actual Message" + IllegalAccessException::class withMessage "Actual Message" } } @@ -101,7 +101,7 @@ class ShouldNotThrowShould { } assertFails { coInvoking { func() } shouldNotThrow - IllegalAccessException::class withMessage "Actual Message" + IllegalAccessException::class withMessage "Actual Message" } } @@ -109,7 +109,7 @@ class ShouldNotThrowShould { fun failWhenTestingAFunctionThatDoesThrowAnExceptionWithTheExpectedCause() { assertFails { invoking { throw Exception(RuntimeException()) } shouldNotThrow - Exception::class withCause RuntimeException::class + Exception::class withCause RuntimeException::class } } @@ -121,7 +121,7 @@ class ShouldNotThrowShould { } assertFails { coInvoking { func() } shouldNotThrow - Exception::class withCause RuntimeException::class + Exception::class withCause RuntimeException::class } } @@ -142,4 +142,4 @@ class ShouldNotThrowShould { coInvoking { func() } shouldNotThrow Exception::class } } -} \ No newline at end of file +} diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowShould.kt index 5c02ea19..d9129707 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/exceptions/ShouldThrowShould.kt @@ -165,7 +165,7 @@ class ShouldThrowShould { @Test fun passWhenTestingAFunctionWhichThrowsAnExceptionWithMessageAndCause() { invoking { throw IllegalArgumentException("hello", IOException()) } shouldThrow - IllegalArgumentException::class withCause IOException::class withMessage "hello" + IllegalArgumentException::class withCause IOException::class withMessage "hello" } @Test @@ -175,32 +175,33 @@ class ShouldThrowShould { suspendCancellableCoroutine { throw IllegalArgumentException("hello", IOException()) } } coInvoking { func() } shouldThrow - IllegalArgumentException::class withCause IOException::class withMessage "hello" + IllegalArgumentException::class withCause IOException::class withMessage "hello" } @Test fun failWhenTestingAFunctionWhichThrowsAnExceptionWithMessageAndCauseExceptingADifferentMessage() { assertFails { invoking { throw IllegalArgumentException("not hello", IOException()) } shouldThrow - IllegalArgumentException::class withCause IOException::class withMessage "hello" + IllegalArgumentException::class withCause IOException::class withMessage "hello" } } @Test @ExperimentalCoroutinesApi - fun failWhenTestingASuspendFunctionWhichThrowsAnExceptionWithMessageAndCauseExceptingADifferentMessage() = runBlockingTest { - suspend fun func() { - suspendCancellableCoroutine { throw IllegalArgumentException("not hello", IOException()) } - } - assertFails { - coInvoking { func() } shouldThrow + fun failWhenTestingASuspendFunctionWhichThrowsAnExceptionWithMessageAndCauseExceptingADifferentMessage() = + runBlockingTest { + suspend fun func() { + suspendCancellableCoroutine { throw IllegalArgumentException("not hello", IOException()) } + } + assertFails { + coInvoking { func() } shouldThrow IllegalArgumentException::class withCause IOException::class withMessage "hello" + } } - } @Test fun validatedCustomValuesOfThrownException() { - class CustomException(val value: String, val num: Int): Exception(value) + class CustomException(val value: String, val num: Int) : Exception(value) invoking { throw CustomException("Hello World", 25) } shouldThrow CustomException::class with { value shouldBeEqualTo "Hello World" num shouldBeEqualTo 25 diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt index bb9d14e2..13dae9ba 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt @@ -5,8 +5,7 @@ import org.amshove.kluent.shouldHaveName import java.io.File import kotlin.test.Test -class ShouldHaveNameShould -{ +class ShouldHaveNameShould { private val name = "thisfilenameisweird.csv" private val file = File(name) @@ -17,7 +16,7 @@ class ShouldHaveNameShould @Test fun failWhenTestingAFileWithAnUnexpectedFileName() { - file.useFile { assertFails { it shouldHaveName "anothername" }} + file.useFile { assertFails { it shouldHaveName "anothername" } } } } diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/reflection/ShouldNotBeInstanceOfShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/reflection/ShouldNotBeInstanceOfShould.kt index b9795fdf..c4bb3a47 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/reflection/ShouldNotBeInstanceOfShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/reflection/ShouldNotBeInstanceOfShould.kt @@ -1,6 +1,5 @@ package org.amshove.kluent.tests.assertions.reflection -import org.amshove.kluent.shouldBeInstanceOf import org.amshove.kluent.shouldNotBeInstanceOf import org.amshove.kluent.tests.helpclasses.Base import org.amshove.kluent.tests.helpclasses.Circle @@ -50,7 +49,7 @@ class ShouldNotBeInstanceOfShould { @Test fun failWhenTestingNonNullInstanceAgainstCompatibleNullableType() { - val base: Base = Base() + val base = Base() assertFails { base.shouldNotBeInstanceOf() } } } diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt index 8fc666c6..0d7e805a 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt @@ -2,7 +2,6 @@ package org.amshove.kluent.tests.assertions.softly import org.amshove.kluent.* import org.amshove.kluent.tests.equivalency.ShouldBeEquivalentTo -import java.lang.RuntimeException import kotlin.test.Test import kotlin.test.assertEquals @@ -20,13 +19,15 @@ class AssertSoftly { length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following 2 assertions failed: |1) Expected the CharSequence ab1 to contain 2 - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:19) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:18) |2) Expected 3 to be greater or equal to 4 - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:20)""" - .trimMargin(), e.message!!.trimMargin()) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:19)""" + .trimMargin(), e.message!!.trimMargin() + ) } } @@ -56,11 +57,13 @@ class AssertSoftly { length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following assertion failed: |Expected the CharSequence ab1 to contain 2 - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.verifyAssertErrorForNonSoftlyAssertions(AssertSoftly.kt:55)""" - .trimMargin(), e.message!!.trimMargin()) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.verifyAssertErrorForNonSoftlyAssertions(AssertSoftly.kt:56)""" + .trimMargin(), e.message!!.trimMargin() + ) } } @@ -78,11 +81,13 @@ class AssertSoftly { a.length.shouldBeGreaterOrEqualTo(4) } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following assertion failed: |Expected 3 to be greater or equal to 4 - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftlyForSeveralObjects(AssertSoftly.kt:78)""" - .trimMargin(), e.message!!) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftlyForSeveralObjects(AssertSoftly.kt:81)""" + .trimMargin(), e.message!! + ) } } @@ -106,6 +111,7 @@ class AssertSoftly { return true } } + class House(val maxGuests: Int = 5) { private var _rooms: MutableList = mutableListOf() private var _guests: MutableList = mutableListOf() @@ -137,12 +143,12 @@ class AssertSoftly { // act val guests = listOf( - Guest("a"), - Guest("b"), - Guest("c"), - Guest("d"), - Guest("e"), - Guest("f") + Guest("a"), + Guest("b"), + Guest("c"), + Guest("d"), + Guest("e"), + Guest("f") ) val house = House() house.host(guests) @@ -154,13 +160,15 @@ class AssertSoftly { house.guests.size.shouldBeEqualTo(5) } } catch (e: Throwable) { - e.message!!.trimMargin().shouldBeEqualTo(""" + e.message!!.trimMargin().shouldBeEqualTo( + """ The following 2 assertions failed: 1) Expected <2>, actual <3>. at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:150) 2) Expected <6>, actual <5>. at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:151) - """.trimMargin()) + """.trimMargin() + ) } } @@ -197,15 +205,17 @@ class AssertSoftly { list shouldContainSame listOf('x', 'z') } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following 2 assertions failed: |1) Expected collection size to be 2 but was 3 - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.assertSoftlyCollections(AssertSoftly.kt:196) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.assertSoftlyCollections(AssertSoftly.kt:204) |2) The collection doesn't have the same items | |Items included on the actual collection but not in the expected: y - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.assertSoftlyCollections(AssertSoftly.kt:197) - """.trimMargin(), e.message!!.trimMargin()) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.assertSoftlyCollections(AssertSoftly.kt:205) + """.trimMargin(), e.message!!.trimMargin() + ) } } @@ -215,13 +225,13 @@ class AssertSoftly { // arrange val a1 = ShouldBeEquivalentTo.E().apply { Flist = listOf( - ShouldBeEquivalentTo.F(1).apply { name = "name1" }, - ShouldBeEquivalentTo.F(2).apply { name = "name2" } + ShouldBeEquivalentTo.F(1).apply { name = "name1" }, + ShouldBeEquivalentTo.F(2).apply { name = "name2" } ) } val a2 = ShouldBeEquivalentTo.E().apply { Flist = listOf( - ShouldBeEquivalentTo.F(1).apply { name = "name1" } + ShouldBeEquivalentTo.F(1).apply { name = "name1" } ) } @@ -232,7 +242,8 @@ class AssertSoftly { Flist[0].name.shouldBeEqualTo("name2") } } catch (e: Throwable) { - assertEquals(""" + assertEquals( + """ |The following 2 assertions failed: |1) Are not equivalent: |Expected: - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.softEquavalencyTest(AssertSoftly.kt:231) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.softEquavalencyTest(AssertSoftly.kt:241) |2) Expected: but was: - |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.softEquavalencyTest(AssertSoftly.kt:232) + |at org.amshove.kluent.tests.assertions.softly.AssertSoftly.softEquavalencyTest(AssertSoftly.kt:242) |""".trimMargin() - .trimMargin(), e.message!!.trimMargin()) + .trimMargin(), e.message!!.trimMargin() + ) } } -} \ No newline at end of file +} diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtMostXDaysBeforeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtMostXDaysBeforeShould.kt index dafc7742..85ba198d 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtMostXDaysBeforeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtMostXDaysBeforeShould.kt @@ -1,6 +1,8 @@ package org.amshove.kluent.tests.assertions.time.localdate -import org.amshove.kluent.* +import org.amshove.kluent.before +import org.amshove.kluent.days +import org.amshove.kluent.shouldBeAtMost import java.time.LocalDate import kotlin.test.Test import kotlin.test.assertFails diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdatetime/ShouldBeInSecondShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdatetime/ShouldBeInSecondShould.kt index 75b4025b..ac4fe129 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdatetime/ShouldBeInSecondShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdatetime/ShouldBeInSecondShould.kt @@ -1,7 +1,7 @@ package org.amshove.kluent.tests.assertions.time.localdatetime -import org.amshove.kluent.* -import java.time.* +import org.amshove.kluent.shouldBeInSecond +import java.time.LocalDateTime import kotlin.test.Test import kotlin.test.assertFails diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldNotBeInSecondShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldNotBeInSecondShould.kt index 7dfbe41c..b8ae1f8e 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldNotBeInSecondShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldNotBeInSecondShould.kt @@ -1,6 +1,6 @@ package org.amshove.kluent.tests.assertions.time.localtime -import org.amshove.kluent.* +import org.amshove.kluent.shouldNotBeInSecond import java.time.LocalTime import kotlin.test.Test import kotlin.test.assertFails diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksEquivalency.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksEquivalency.kt index 771322c8..5e75bec3 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksEquivalency.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksEquivalency.kt @@ -11,52 +11,64 @@ class BackticksEquivalency { fun `pass should be equivalent to withStrictOrdering as properties are equal for iterables`() { // arrange val teams1 = listOf( - ShouldBeEquivalentTo.Team("team1").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson").apply { - address = ShouldBeEquivalentTo.Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - ShouldBeEquivalentTo.Team("team2").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "") - ) - }, - ShouldBeEquivalentTo.Team("team3").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "Marcson") - ) - } + ShouldBeEquivalentTo.Team("team1").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson").apply { + address = ShouldBeEquivalentTo.Address( + "Mainzerlandstrasse", + "200", + "Frankfurt am Main", + "60327", + "Germany" + ) + }, + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + ShouldBeEquivalentTo.Team("team2").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "") + ) + }, + ShouldBeEquivalentTo.Team("team3").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "Marcson") + ) + } ) val teams2 = listOf( - ShouldBeEquivalentTo.Team("team1").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson").apply { - address = ShouldBeEquivalentTo.Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - ShouldBeEquivalentTo.Team("team2").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "") - ) - }, - ShouldBeEquivalentTo.Team("team3").apply { - persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "Marcson") - ) - } + ShouldBeEquivalentTo.Team("team1").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson").apply { + address = ShouldBeEquivalentTo.Address( + "Mainzerlandstrasse", + "200", + "Frankfurt am Main", + "60327", + "Germany" + ) + }, + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + ShouldBeEquivalentTo.Team("team2").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "") + ) + }, + ShouldBeEquivalentTo.Team("team3").apply { + persons = listOf( + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "Marcson") + ) + } ) // assert - teams1.`should be equivalent to` (teams2) { + teams1.`should be equivalent to`(teams2) { it.withStrictOrdering() } } diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt index 2b79c875..ca2d8b11 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt @@ -1,7 +1,7 @@ package org.amshove.kluent.tests.collections -import org.amshove.kluent.tests.Person import org.amshove.kluent.`should match at least one of` +import org.amshove.kluent.tests.Person import kotlin.test.Test class BackticksShould { diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentBacktickTest.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentBacktickTest.kt index cb1c2f43..d9931126 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentBacktickTest.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentBacktickTest.kt @@ -13,30 +13,30 @@ class ShouldBeEquivalentBacktickTest { // arrange val team1 = ShouldBeEquivalentTo.Team("team1").apply { persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = ShouldBeEquivalentTo.Team("team2").apply { persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson"), - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + ShouldBeEquivalentTo.Person("John", "Johnson"), + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } // assert - team1 `should be equivalent to` (team2 to { - options: EquivalencyAssertionOptions -> options.including(ShouldBeEquivalentTo.Team::persons) + team1 `should be equivalent to` (team2 to { options: EquivalencyAssertionOptions -> + options.including(ShouldBeEquivalentTo.Team::persons) }) } @@ -46,32 +46,46 @@ class ShouldBeEquivalentBacktickTest { // arrange val team1 = ShouldBeEquivalentTo.Team("team1").apply { persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson").apply { - address = ShouldBeEquivalentTo.Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + ShouldBeEquivalentTo.Person("John", "Johnson").apply { + address = ShouldBeEquivalentTo.Address( + "Mainzerlandstrasse", + "200", + "Frankfurt am Main", + "60327", + "Germany" + ) + }, + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = ShouldBeEquivalentTo.Team("team1").apply { persons = listOf( - ShouldBeEquivalentTo.Person("John", "Johnson").apply { - address = ShouldBeEquivalentTo.Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + ShouldBeEquivalentTo.Person("John", "Johnson").apply { + address = ShouldBeEquivalentTo.Address( + "Mainzerlandstrasse", + "200", + "Frankfurt am Main", + "60327", + "Germany" + ) + }, + ShouldBeEquivalentTo.Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = ShouldBeEquivalentTo.Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } // assert - team1 `should not be equivalent to` Pair EquivalencyAssertionOptions)?> (team2, { - options: EquivalencyAssertionOptions -> options.including(ShouldBeEquivalentTo.Team::persons) - }) + team1 `should not be equivalent to` Pair EquivalencyAssertionOptions)?>( + team2, + { options: EquivalencyAssertionOptions -> + options.including(ShouldBeEquivalentTo.Team::persons) + }) } } \ No newline at end of file diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt index 83dcf85d..8e4ee46f 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt @@ -1,9 +1,11 @@ package org.amshove.kluent.tests.equivalency -import org.amshove.kluent.* import org.amshove.kluent.internal.ComparisonFailedException import org.amshove.kluent.internal.assertFailsWith -import org.junit.ComparisonFailure +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldBeEquivalentTo +import org.amshove.kluent.shouldNotBeEquivalentTo +import org.amshove.kluent.shouldStartWith import org.junit.Test import java.time.LocalDate @@ -14,10 +16,10 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team1").apply { @@ -36,16 +38,16 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") + Person("John", "Johnson"), + Person("Marc", "Marcson") ) } @@ -57,52 +59,52 @@ class ShouldBeEquivalentTo { fun failShouldBeEquivalentToAsPropertiesAreDifferentForIterables() { // arrange val teams1 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + } ) val teams2 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + } ) // assert @@ -117,48 +119,48 @@ class ShouldBeEquivalentTo { fun passShouldNotBeEquivalentToAsPropertiesAreDifferentForIterables() { // arrange val teams1 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + } ) val teams2 = listOf( - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - }, - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - } + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + }, + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + } ) // assert @@ -169,48 +171,48 @@ class ShouldBeEquivalentTo { fun passShouldBeEquivalentToWithStrictOrderingAsPropertiesAreEqualForIterables() { // arrange val teams1 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + } ) val teams2 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + } ) // assert @@ -223,48 +225,48 @@ class ShouldBeEquivalentTo { fun passShouldNotBeEquivalentToWithStrictOrderingEvenIfPropertiesAreEqualForIterables() { // arrange val teams1 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + } ) val teams2 = listOf( - Team("team1").apply { - persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } - ) - }, - Team("team3").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") - ) - }, - Team("team2").apply { - persons = listOf( - Person("John", "Johnson"), - Person("Marc", "") - ) - } + Team("team1").apply { + persons = listOf( + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + ) + }, + Team("team3").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "Marcson") + ) + }, + Team("team2").apply { + persons = listOf( + Person("John", "Johnson"), + Person("Marc", "") + ) + } ) // assert @@ -278,28 +280,28 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } @@ -312,28 +314,28 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } @@ -348,26 +350,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -384,26 +386,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -418,26 +420,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -452,26 +454,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -488,26 +490,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -524,26 +526,26 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK") + } ) } @@ -558,21 +560,21 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Watson"), - Person("Marco", "Polo") + Person("John", "Watson"), + Person("Marco", "Polo") ) } @@ -589,21 +591,21 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Watson"), - Person("Marco", "Polo") + Person("John", "Watson"), + Person("Marco", "Polo") ) } @@ -618,24 +620,24 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson"), + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson"), + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } @@ -650,24 +652,24 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson"), + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson").apply { - birthDate = LocalDate.of(2020, 2, 1) - address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { - address2 = "Islington" - } + Person("John", "Johnson"), + Person("Marc", "Marcson").apply { + birthDate = LocalDate.of(2020, 2, 1) + address = Address("Graham Street", "36", "London", "N1 8GJ", "UK").apply { + address2 = "Islington" } + } ) } @@ -684,16 +686,16 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") + Person("John", "Johnson"), + Person("Marc", "Marcson") ) } @@ -709,16 +711,16 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team1").apply { persons = listOf( - Person("John", "Johnson"), - Person("Marc", "Marcson") + Person("John", "Johnson"), + Person("Marc", "Marcson") ) } @@ -735,18 +737,18 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } @@ -763,18 +765,18 @@ class ShouldBeEquivalentTo { // arrange val team1 = Team("team1").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } val team2 = Team("team2").apply { persons = listOf( - Person("John", "Johnson").apply { - address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") - }, - Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } + Person("John", "Johnson").apply { + address = Address("Mainzerlandstrasse", "200", "Frankfurt am Main", "60327", "Germany") + }, + Person("Marc", "Marcson").apply { birthDate = LocalDate.of(2020, 2, 1) } ) } @@ -832,52 +834,52 @@ class ShouldBeEquivalentTo { fun passShouldNotBeEquivalentToAsPropertiesAreDifferentAndAllowingInfiniteRecursion() { // arrange val a1 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { - Elist = mutableListOf( - E().apply { - Flist = listOf( - F(1), - F(2) - ) - }, - E().apply { - Flist = listOf( - F(3), - F(4) - ) - } - ) - name2 = "name1111" - } - } - e = "abc" - }, - A("name2").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { + Elist = mutableListOf( + E().apply { + Flist = listOf( + F(1), + F(2) + ) + }, + E().apply { + Flist = listOf( + F(3), + F(4) + ) + } + ) + name2 = "name1111" } - e = "abc" } + e = "abc" + }, + A("name2").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } + } + e = "abc" + } ) val a2 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } - } - e = "abc" - }, - A("name2").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name3111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } - } - e = "abc" + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } + } + e = "abc" + }, + A("name2").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name3111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } } + e = "abc" + } ) // assert @@ -893,98 +895,98 @@ class ShouldBeEquivalentTo { fun failShouldBeEquivalentToAsPropertiesAreDifferentAndAllowingInfiniteRecursion() { // arrange val a1 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { - Elist = mutableListOf( - E().apply { - Flist = listOf( - F(1), - F(2) - ) - }, - E().apply { - Flist = listOf( - F(3), - F(4) - ) - } - ) - name2 = "name1111" - } + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { + Elist = mutableListOf( + E().apply { + Flist = listOf( + F(1), + F(2) + ) + }, + E().apply { + Flist = listOf( + F(3), + F(4) + ) + } + ) + name2 = "name1111" } - e = "abc" - }, - A("name2").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } - d = D("name111").apply { - Elist = mutableListOf( - E().apply { - Flist = listOf( - F(5), - F(6) - ) - }, - E().apply { - Flist = listOf( - F(7) - ) - } - ) - name2 = "name1111" - } + } + e = "abc" + }, + A("name2").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } + d = D("name111").apply { + Elist = mutableListOf( + E().apply { + Flist = listOf( + F(5), + F(6) + ) + }, + E().apply { + Flist = listOf( + F(7) + ) + } + ) + name2 = "name1111" } - e = "abc" } + e = "abc" + } ) val a2 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { - Elist = mutableListOf( - E().apply { - Flist = listOf( - F(1), - F(2) - ) - }, - E().apply { - Flist = listOf( - F(3), - F(4) - ) - } - ) - name2 = "name1111" - } + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { + Elist = mutableListOf( + E().apply { + Flist = listOf( + F(1), + F(2) + ) + }, + E().apply { + Flist = listOf( + F(3), + F(4) + ) + } + ) + name2 = "name1111" } - e = "abc" - }, - A("name2").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name3111" }).apply { name = "name1111" } - d = D("name111").apply { - name2 = "name1111" - Elist = mutableListOf( - E().apply { - Flist = listOf( - F(5), - F(6) - ) - }, - E().apply { - Flist = listOf( - F(7) - ) - } - ) - } + } + e = "abc" + }, + A("name2").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name3111" }).apply { name = "name1111" } + d = D("name111").apply { + name2 = "name1111" + Elist = mutableListOf( + E().apply { + Flist = listOf( + F(5), + F(6) + ) + }, + E().apply { + Flist = listOf( + F(7) + ) + } + ) } - e = "abc" } + e = "abc" + } ) // assert @@ -998,7 +1000,8 @@ class ShouldBeEquivalentTo { } } catch (e: ComparisonFailedException) { e.message!!.shouldStartWith("Are not equivalent:") - e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ A (e = abc, name = name1) ˪-B (name = name11) ˪--C (name = name1111) @@ -1028,8 +1031,10 @@ class ShouldBeEquivalentTo { ˪----E[1] ˪-----Flist ˪------F[0] (id = 7, name = ) - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) - e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) + e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ A (e = abc, name = name1) ˪-B (name = name11) ˪--C (name = name1111) @@ -1059,7 +1064,8 @@ class ShouldBeEquivalentTo { ˪----E[1] ˪-----Flist ˪------F[0] (id = 7, name = ) - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) } } @@ -1067,29 +1073,29 @@ class ShouldBeEquivalentTo { fun failShouldBeEquivalentToAsAmountOfEntitiesIsDifferent() { // arrange val a1 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } - } - e = "abc" - }, - A("name2").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } - } - e = "abc" + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } } + e = "abc" + }, + A("name2").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name2111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } + } + e = "abc" + } ) val a2 = listOf( - A("name1").apply { - b = B("name11").apply { - c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } - d = D("name111").apply { name2 = "name1111" } - } - e = "abc" + A("name1").apply { + b = B("name11").apply { + c = C(D("name111").apply { name2 = "name1111" }).apply { name = "name1111" } + d = D("name111").apply { name2 = "name1111" } } + e = "abc" + } ) // assert @@ -1102,7 +1108,8 @@ class ShouldBeEquivalentTo { } } catch (e: ComparisonFailedException) { e.message!!.shouldStartWith("Are not equivalent:") - e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ A (e = abc, name = name1) ˪-B (name = name11) ˪--C (name = name1111) @@ -1117,8 +1124,10 @@ class ShouldBeEquivalentTo { ˪----Elist ˪--D (name = name111, name2 = name1111) ˪---Elist - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) - e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) + e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ A (e = abc, name = name1) ˪-B (name = name11) ˪--C (name = name1111) @@ -1126,7 +1135,8 @@ class ShouldBeEquivalentTo { ˪----Elist ˪--D (name = name111, name2 = name1111) ˪---Elist - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) } } @@ -1135,13 +1145,13 @@ class ShouldBeEquivalentTo { // arrange val a1 = E().apply { Flist = listOf( - F(1).apply { name = "name1" }, - F(2).apply { name = "name2" } + F(1).apply { name = "name1" }, + F(2).apply { name = "name2" } ) } val a2 = E().apply { Flist = listOf( - F(1).apply { name = "name1" } + F(1).apply { name = "name1" } ) } @@ -1150,17 +1160,21 @@ class ShouldBeEquivalentTo { a1.shouldBeEquivalentTo(a2) } catch (e: ComparisonFailedException) { e.message!!.shouldStartWith("Are not equivalent:") - e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + e.actual!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ E ˪-Flist ˪--F[0] (id = 1, name = name1) ˪--F[1] (id = 2, name = name2) - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) - e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) + e.expected!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo( + """ E ˪-Flist ˪--F[0] (id = 1, name = name1) - """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim() + ) } } @@ -1175,7 +1189,13 @@ class ShouldBeEquivalentTo { } @Suppress("unused") - internal class Address(val street: String, val house: String, val city: String, val zipCode: String, val country: String) { + internal class Address( + val street: String, + val house: String, + val city: String, + val zipCode: String, + val country: String + ) { var address2: String? = null } diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/helpclasses/Interfaces.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/helpclasses/Interfaces.kt index 297dfef3..715fe1fc 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/helpclasses/Interfaces.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/helpclasses/Interfaces.kt @@ -5,6 +5,7 @@ import java.io.IOException interface Database { fun getPerson(): Person + @Throws(IOException::class) fun getPersonChecked(): Person fun getPerson(id: Int): Person diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/mocking/Mocking.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/mocking/Mocking.kt index bc230c95..c796d11c 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/mocking/Mocking.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/mocking/Mocking.kt @@ -10,7 +10,6 @@ import org.mockito.stubbing.OngoingStubbing import kotlin.reflect.KClass - @Suppress("UNUSED_PARAMETER") // Backward compatibility inline fun mock(targetClass: KClass): T = mock() @@ -64,7 +63,8 @@ fun withLastArg(): Answer = returnsLastArg() private fun ensureMock(obj: T) { if (!MockUtil.isMock(obj)) { - throw Exception(""" + throw Exception( + """ $obj is no mock. Ensure to always determine the mock with the `on` method. @@ -72,7 +72,8 @@ private fun ensureMock(obj: T) { Verify on myMock that myMock.getPerson() was called /\ -------- - """) + """ + ) } } diff --git a/native/build.gradle b/native/build.gradle index f3db0786..bf9164d0 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -1,5 +1,5 @@ plugins { - id "org.jetbrains.kotlin.platform.native" + id "org.jetbrains.kotlin.platform.native" } dependencies { @@ -36,11 +36,11 @@ bintray { } publishing { - repositories { - maven { - url = 'https://dl.bintray.com/markusamshove/maven' + repositories { + maven { + url = 'https://dl.bintray.com/markusamshove/maven' + } } - } } bintrayUpload.doFirst { diff --git a/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt index d3fea3d0..41c2b364 100644 --- a/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt +++ b/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -8,17 +8,21 @@ internal actual fun hardFail(message: String?): Nothing { } @PublishedApi -internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { +internal actual fun checkResultIsFailure( + exceptionClass: KClass, + message: String?, + blockResult: Result +): T { blockResult.fold( - onSuccess = { - hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") - }, - onFailure = { e -> - if (exceptionClass.isInstance(e)) { - @Suppress("UNCHECKED_CAST") - return e as T - } - hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + onSuccess = { + hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T } + hardFail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + } ) } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c8772e76..2064662c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,40 +5,40 @@ def buildNative = hasProperty("NATIVE") def buildJs = hasProperty("JS") def skipJVM = hasProperty("SKIPJVM") -if(!buildAndroid) { +if (!buildAndroid) { logger.warn("Kluent Android build not included. Pass -PANDROID to build Android instead of JVM") } -if(!buildNative) { +if (!buildNative) { logger.warn("Kluent Native build not included. Pass -PNATIVE to also build native") } -if(!buildJs) { +if (!buildJs) { logger.warn("Kluent JS build not included. Pass -PJS to also build JS") } -if(skipJVM) { +if (skipJVM) { logger.warn("Skipping JVM build") } include 'common' project(':common').name = 'kluent-common' -if(!skipJVM) { +if (!skipJVM) { include 'jvm' // TODO(2.0) Rename to kluent-jvm def jvmProjectName = buildAndroid ? 'kluent-android' : 'kluent' - project(':jvm').name = jvmProjectName + project(':jvm').name = jvmProjectName } -if(buildJs) { +if (buildJs) { include 'js' - project(':js').name = 'kluent-js' + project(':js').name = 'kluent-js' } if (buildNative) { enableFeaturePreview('GRADLE_METADATA') include 'native' - project(':native').name = 'kluent-native' + project(':native').name = 'kluent-native' }