Skip to content

Commit

Permalink
Use JUnit's assert format for assert messages to enable better suppor… (
Browse files Browse the repository at this point in the history
#6262)

* Use JUnit's assert format for assert messages to enable better support in IDEs

* remove unnecessary < and > since it's not matched by IntelliJ's regex
  • Loading branch information
bjoernQ authored and akarnokd committed Oct 26, 2018
1 parent 9181cbc commit 1406637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/main/java/io/reactivex/observers/BaseTestConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ public final U assertError(Predicate<Throwable> errorPredicate) {
public final U assertValue(T value) {
int s = values.size();
if (s != 1) {
throw fail("Expected: " + valueAndClass(value) + ", Actual: " + values);
throw fail("expected: " + valueAndClass(value) + " but was: " + values);
}
T v = values.get(0);
if (!ObjectHelper.equals(value, v)) {
throw fail("Expected: " + valueAndClass(value) + ", Actual: " + valueAndClass(v));
throw fail("expected: " + valueAndClass(value) + " but was: " + valueAndClass(v));
}
return (U)this;
}
Expand Down Expand Up @@ -450,7 +450,7 @@ public final U assertValueAt(int index, T value) {

T v = values.get(index);
if (!ObjectHelper.equals(value, v)) {
throw fail("Expected: " + valueAndClass(value) + ", Actual: " + valueAndClass(v));
throw fail("expected: " + valueAndClass(value) + " but was: " + valueAndClass(v));
}
return (U)this;
}
Expand Down Expand Up @@ -512,7 +512,7 @@ public static String valueAndClass(Object o) {
public final U assertValueCount(int count) {
int s = values.size();
if (s != count) {
throw fail("Value counts differ; Expected: " + count + ", Actual: " + s);
throw fail("Value counts differ; expected: " + count + " but was: " + s);
}
return (U)this;
}
Expand All @@ -535,14 +535,14 @@ public final U assertNoValues() {
public final U assertValues(T... values) {
int s = this.values.size();
if (s != values.length) {
throw fail("Value count differs; Expected: " + values.length + " " + Arrays.toString(values)
+ ", Actual: " + s + " " + this.values);
throw fail("Value count differs; expected: " + values.length + " " + Arrays.toString(values)
+ " but was: " + s + " " + this.values);
}
for (int i = 0; i < s; i++) {
T v = this.values.get(i);
T u = values[i];
if (!ObjectHelper.equals(u, v)) {
throw fail("Values at position " + i + " differ; Expected: " + valueAndClass(u) + ", Actual: " + valueAndClass(v));
throw fail("Values at position " + i + " differ; expected: " + valueAndClass(u) + " but was: " + valueAndClass(v));
}
}
return (U)this;
Expand Down Expand Up @@ -628,7 +628,7 @@ public final U assertValueSequence(Iterable<? extends T> sequence) {
T v = actualIterator.next();

if (!ObjectHelper.equals(u, v)) {
throw fail("Values at position " + i + " differ; Expected: " + valueAndClass(u) + ", Actual: " + valueAndClass(v));
throw fail("Values at position " + i + " differ; expected: " + valueAndClass(u) + " but was: " + valueAndClass(v));
}
i++;
}
Expand Down Expand Up @@ -738,7 +738,7 @@ public final U assertErrorMessage(String message) {
Throwable e = errors.get(0);
String errorMessage = e.getMessage();
if (!ObjectHelper.equals(message, errorMessage)) {
throw fail("Error message differs; Expected: " + message + ", Actual: " + errorMessage);
throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage);
}
} else {
throw fail("Multiple errors");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/reactivex/observers/TestObserverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ public void assertValueAtIndexNoMatch() {
Observable.just("a", "b", "c").subscribe(to);

thrown.expect(AssertionError.class);
thrown.expectMessage("Expected: b (class: String), Actual: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)");
thrown.expectMessage("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)");
to.assertValueAt(2, "b");
}

Expand Down

1 comment on commit 1406637

@ragunathjawahar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, was working on this RN. Hopefully this will go into the next release. Kudos @bjoernQ.

Please sign in to comment.