All Projects → llorllale → cactoos-matchers

llorllale / cactoos-matchers

Licence: other
Elegant object-oriented hamcrest matchers

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to cactoos-matchers

cactoos-crypto
Crypto extensions for Cactoos library
Stars: ✭ 15 (-50%)
Mutual labels:  oop, cactoos
Androidut
Android开发中必要的一环---单元测试(Unit Test)
Stars: ✭ 419 (+1296.67%)
Mutual labels:  junit, unit-test
mutant-swarm
Mutation testing framework and code coverage for Hive SQL
Stars: ✭ 20 (-33.33%)
Mutual labels:  junit, unit-test
Bliss
Blissful JavaScript
Stars: ✭ 2,352 (+7740%)
Mutual labels:  oop
Aquila
🎨 An Advanced WordPress theme
Stars: ✭ 204 (+580%)
Mutual labels:  oop
FineCodeCoverage
Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)
Stars: ✭ 391 (+1203.33%)
Mutual labels:  unit-test
Pencil.js
✏️ Nice modular interactive 2D drawing library
Stars: ✭ 204 (+580%)
Mutual labels:  oop
junit.testlogger
JUnit test logger for vstest platform
Stars: ✭ 61 (+103.33%)
Mutual labels:  junit
doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-26.67%)
Mutual labels:  junit
awesome-software-architecture
A curated list of awesome articles, videos, and other resources to learn and practice software architecture, patterns, and principles.
Stars: ✭ 1,594 (+5213.33%)
Mutual labels:  oop
Design-Patterns
Project for learning and discuss about design patterns
Stars: ✭ 16 (-46.67%)
Mutual labels:  oop
Jcabi Github
Object Oriented Wrapper of Github API
Stars: ✭ 252 (+740%)
Mutual labels:  oop
Logtalk3
Logtalk - declarative object-oriented logic programming language
Stars: ✭ 221 (+636.67%)
Mutual labels:  oop
xrm-mock-generator
📖  Generates a mock Xrm.Page object. Commonly used by xrm-mock to test Dynamics 365 client-side customisations.
Stars: ✭ 15 (-50%)
Mutual labels:  unit-test
Learning Oop In Php
A collection of resources to learn object-oriented programming and related concepts for PHP developers.
Stars: ✭ 2,359 (+7763.33%)
Mutual labels:  oop
wordpress-eloquent
A library that converts converts wordpress tables into Laravel Eloquent Models.
Stars: ✭ 129 (+330%)
Mutual labels:  oop
Testdeck
Object oriented testing
Stars: ✭ 206 (+586.67%)
Mutual labels:  oop
Oop
OOP in Elixir!
Stars: ✭ 233 (+676.67%)
Mutual labels:  oop
kentan
A modular test data generator for TypeScript
Stars: ✭ 38 (+26.67%)
Mutual labels:  unit-test
SMmuiscPlay
🎼极简模式JavaScript音乐播放器组件,极简、小巧、无依赖、可定制,适用于手机页面,H5活动页,微信页面等的音乐播放支持
Stars: ✭ 40 (+33.33%)
Mutual labels:  oop

Managed by Zerocracy Donate via Zerocracy

EO principles respected here DevOps By Rultor.com

Build Status Javadoc PDD status Maven Central License

Test Coverage SonarQube

All Contributors

What it is

cactoos-matchers is an object-oriented wrapper around hamcrest's matchers.

Principles

Design principles behind cactoos-matchers.

How to use

This library depends on cactoos and hamcrest. Get the latest version here:

<dependency>
  <groupId>org.llorllale</groupId>
  <artifactId>cactoos-matchers</artifactId>
  <version>${version}</version>
</dependency>

Java version required: 1.8+.

cactoos-matchers versus Hamcrest + JUnit

cactoos-matchers Hamcrest (static method) Hamcrest (object) JUnit
Assertion MatcherAssert.assertThat - Assert.assertThat
Throws - - @expected + ExpectedException
EndsWith Matchers.endsWith StringEndsWith -
StartsWith Matcers.startsWith StringStartsWith -
TextIs Matchers.is IsEqual -
HasLines - - -
MatchesRegex - - -
TextHasString Matchers.stringContainsInOrder StringContains -
FuncApplies - - -
HasValues Matchers.containsInAnyOrder IsIterableContainingInAnyOrder -
HasValuesMatching Matchers.containsInAnyOrder IsIterableContainingInAnyOrder -
InputHasContent - - -
IsTrue - - Assert.assertTrue
Matches - - -
RunsInThreads - - -
ScalarHasValue - - -

How to use

Use our matchers inside your JUnit @Test case. We also provide Assertion<T> in which you can compose the behavior under test and the test case's matcher, and attempt to affirm it.

We provide matchers for several different domains:

Text

Examples:

@Test
public void textHasPrefix() {
  final String prefix = "Application startup";
  new Assertion<>(
    "must have the prefix",
    new TextOf(new File("some.log")),
    new StartsWith(prefix)
  ).affirm();
}  

@Test
public void csvLineHasCorrectFormat() throws Exception {
  final String fields = "^[^|]+|[^|]+|[^|]+$";
  new Assertion<>(
    "must match the expected pattern",
    new FirstOf<>(
      line -> true,
      new Split(
        new TextOf(new File("report.csv")),
        "\n"
      ),
      () -> new TextOf("")
    ).value(),
    new MatchesRegex(fields)
  ).affirm();
}

@Test
public void textIsBlank(){
  new Assertion<>(
    "must be blank",
    new TextOf(
      new File("file.txt")
    ),
    new IsBlank()
  ).affirm();
}

Concurrency

Examples:

RunsInThreads

/**
 * Want some assurance that your object is thread-safe?
 */
@Test
public void threadSafety() {
  new Assertion<>(
    "must be able to modify the map concurrently",
    map -> {
      boolean success = true;
      try {
        map.forEach(
          (key, value) -> {
            map.remove(key);
            final Random r = new Random();
            map.put(r.nextInt(), r.nextInt());
          }
        );
      } catch (ConcurrentModificationException ex) {
        success = false;
      }
      return success;
    },
    new RunsInThreads<>(new ConcurrentHashMap<>(), 100)
  ).affirm();
}

Matching errors

Examples:

@Test
public void throwIllegalArgumentExceptionIfLessThan10() throws Exception {
  final Func<Integer, Integer> test = input -> {
    if (input < 10) {
      throw new IllegalArgumentException();
    }
    return input * 10;
  };
  new Assertion<>(
    "must throw illegalargumentexception if input is less than 10",
    () -> test.apply(5),
    new Throws<>(IllegalArgumentException.class)
  ).affirm();
}

Meta-matching: a matcher to test your matchers

Examples:

Use Matches to test matchers themselves:

@Test
public void matchExactString() {
  new Assertion<>(
    "must match the exact text",
    new TextIs("abc"),                // matcher being tested
    new Matches<>(new TextOf("abc"))  // reference against which the matcher is tested
  ).affirm();
}

How to contribute?

Just fork the repo and send us a pull request.

Request to add yourself to the list of contributors below with the @all-contributors bot.

Make sure your branch builds without any warnings/issues:

mvn clean install -Pqulice

Note: Checkstyle is used as a static code analyze tool with checks list in GitHub precommits.

License (MIT)

Copyright (c) for portions of project cactoos-matchers are held by Yegor Bugayenko, 2017-2018, as part of project cactoos. All other copyright for project cactoos-matchers are held by George Aristy, 2018-2020.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contributors


George Aristy

💻

Yegor Bugayenko

💻

Roman Proshin

💻

Yurii Dubinka

💻

andreoss

💻

Victor Noël

💻

Dominik

💻

Stefano Cristalli

💻

Fevzi Anifieiev

💻

Paulo Lobo

💻

Vedran Grgo Vatavuk

💻

Alexander

💻

vzurauskas

💻

jsoroka

💻
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].