cactoos: Tests of cacctoos is not oop

Right now tests use alot of static function from matchers, Maybe they should be more oop style, like let’s take this example

    @Test
    public void iteratesEmptyList() {
        final List<String> list = new LinkedList<>();
        MatcherAssert.assertThat(
            "Can't iterate a list",
            new And(
                new Mapped<String, Scalar<Boolean>>(
                    new FuncOf<>(list::add, () -> true), Collections.emptyList()
                )
            ),
            new ScalarHasValue<>(
                Matchers.allOf(
                    Matchers.equalTo(true),
                    new MatcherOf<>(
                        value -> {
                            return list.isEmpty();
                        }
                    )
                )
            )
        );
    }

in oop style this would be

    @Test
    public void iteratesEmptyList() {
        final List<String> list = new LinkedList<>();
        MatcherAssert.assertThat(
            "Can't iterate a list",
            new And(
                new Mapped<String, Scalar<Boolean>>(
                    new FuncOf<>(list::add, () -> true), Collections.emptyList()
                )
            ),
            new ScalarHasValue<>(
                new AllOf<Boolean>(
                    new IterableOf<>(
                        new IsEqual<>(true),
                        new MatcherOf<>(
                            value -> {
                                return list.isEmpty();
                            }
                        )
                    )
                )
            )
        );
    }

or this is overkill?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 44 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@yegor256 there is plugin for maven forbidden-apis

Sample configuration: add this profile to pom.xml

<profile>
      <id>forbiddenapis</id>
      <build>
        <plugins>
          <plugin>
            <groupId>de.thetaphi</groupId>
            <artifactId>forbiddenapis</artifactId>
            <version>2.4.1</version>
            <configuration>
              <failOnUnsupportedJava>false</failOnUnsupportedJava>
              <signaturesFiles>
                <signaturesFile>./src/test/resources/org/cactoos/forbidden.txt</signaturesFile>
              </signaturesFiles>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>testCheck</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

create file ./src/test/resources/org/cactoos/forbidden.txt with content

@defaultMessage Do not use static methods
org.hamcrest.Matchers

run maven goal forbiddenapis:testCheck, and you wold have something similar to this

[ERROR] Forbidden class/interface use: org.hamcrest.Matchers [Do not use static methods]
[ERROR]   in org.cactoos.collection.BehavesAsCollection (BehavesAsCollection.java:64)
[ERROR] Forbidden class/interface use: org.hamcrest.Matchers [Do not use static methods]
[ERROR]   in org.cactoos.collection.BehavesAsCollection (BehavesAsCollection.java:64)
[ERROR] Forbidden class/interface use: org.hamcrest.Matchers [Do not use static methods]
[ERROR]   in org.cactoos.collection.BehavesAsCollection (BehavesAsCollection.java:68)
[ERROR] Forbidden class/interface use: org.hamcrest.Matchers [Do not use static methods]

plugin also includes some bundled signatures for jdk unsafe methods, but for this examaple i excluded them

also it can match specific methods, link to example