Skip to content

Update assert messages format to be compliant with JUnitTestRunner and GradleTestRunner #7345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ private U assertError(@NonNull Predicate<Throwable> errorPredicate, boolean exac
public final U assertValue(@NonNull T value) {
int s = values.size();
if (s != 1) {
throw fail("expected: " + valueAndClass(value) + " but was: " + values);
throw fail("\nexpected: " + valueAndClass(value) + "\ngot: " + values);
}
T v = values.get(0);
if (!Objects.equals(value, v)) {
throw fail("expected: " + valueAndClass(value) + " but was: " + valueAndClass(v));
throw fail("\nexpected: " + valueAndClass(value) + "\ngot: " + valueAndClass(v));
}
return (U)this;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public final U assertValueAt(int index, @NonNull T value) {

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

if (!Objects.equals(u, v)) {
throw fail("Values at position " + i + " differ; expected: " + valueAndClass(u) + " but was: " + valueAndClass(v));
throw fail("Values at position " + i + " differ;\nexpected: " + valueAndClass(u) + "\ngot: " + valueAndClass(v));
}
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ public void assertValueAtIndexMatch() {

@Test
public void assertValueAtIndexNoMatch() {
assertThrowsWithMessage("expected: b (class: String) but was: c (class: String) at position 2 (latch = 0, values = 3, errors = 0, completions = 1)", AssertionError.class, () -> {
assertThrowsWithMessage("Values at position 2 differ;\nexpected: b (class: String)\ngot: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserver<String> to = new TestObserver<>();

Observable.just("a", "b", "c").subscribe(to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public final U assertErrorMessage(String message) {
Throwable e = errors.get(0);
String errorMessage = e.getMessage();
if (!Objects.equals(message, errorMessage)) {
throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage);
throw fail("Error message differs;\nexpected: " + message + "\ngot: " + errorMessage);
}
} else {
throw fail("Multiple errors");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public final TestObserverEx<T> assertFusionMode(int mode) {
int m = establishedFusionMode;
if (m != mode) {
if (qd != null) {
throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode)
+ ", actual: " + fusionModeToString(m));
throw new AssertionError("Fusion mode different.\nexpected: " + fusionModeToString(mode)
+ "\ngot: " + fusionModeToString(m));
} else {
throw fail("Upstream is not fuseable");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ public void assertValueAtIndexMatch() {

@Test
public void assertValueAtIndexNoMatch() {
assertThrows("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)", AssertionError.class, () -> {
assertThrows("\nexpected: b (class: String)\ngot: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)", AssertionError.class, () -> {
TestObserverEx<String> to = new TestObserverEx<>();

Observable.just("a", "b", "c").subscribe(to);
Expand Down