RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

1.x 2.x Use IDE friendly assertion failed statements

Open mtiidla opened this issue 9 years ago • 4 comments

Currently the assertItem prints by the following statements, focus on "expected to be"

private void assertItem(T expected, int i) {
        T actual = values.get(i);
        if (expected == null) {
            // check for null equality
            if (actual != null) {
                assertionError("Value at index: " + i + " expected to be [null] but was: [" + actual + "]\n");
            }
        } else if (!expected.equals(actual)) {
            assertionError("Value at index: " + i
                    + " expected to be [" + expected + "] (" + expected.getClass().getSimpleName()
                    + ") but was: [" + actual + "] (" + (actual != null ? actual.getClass().getSimpleName() : "null") + ")\n");

        }
    }

However, it does not match any of the IntelliJ assertion regex patterns, thus making it very difficult to visually compare expected and actual values. We forked assertItem() using one of the following patterns from this and could immediately see the <Click to see difference> link in the IDE.

mtiidla avatar Mar 31 '17 13:03 mtiidla

PR welcome.

akarnokd avatar Mar 31 '17 15:03 akarnokd

@mtiidla is 2.x also affected?

vanniktech avatar Mar 31 '17 16:03 vanniktech

@akarnokd Could you please choose the most pleasing pattern from the IntelliJ class I linked to? If you don't have any preference, then I would go with EXPECTED_BUT_WAS_PATTERN as JUnit4 is using it "expected:<" + expected + "> but was:<" + actual + ">"

@vanniktech The output is different, but also not recognized, for example the following code: Observable.just("Test").test().assertValue("test"); produces: Expected: test (class: String), Actual: Test (class: String) and there is no link presented by IntelliJ to compare the output. (I have also edited the Issue title with 2.x)

mtiidla avatar Mar 31 '17 18:03 mtiidla

The JUnit pattern is fine with me.

akarnokd avatar Mar 31 '17 18:03 akarnokd