Skip to content

Commit

Permalink
Merge pull request #1255 from smallrye/AssertSubscriber-fix-messages
Browse files Browse the repository at this point in the history
Fix the AssertSubscriber.assertItems error message
  • Loading branch information
cescoffier authored Apr 20, 2023
2 parents 8cf624f + e6008e8 commit a44539f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void shouldHaveReceivedExactly(List<?> items, Object[] expected) {
fail("%nExpected to have received exactly:%n<%s>%nbut received:%n<%s>.%nMismatches are:%n%s",
getItemList(expected), getItemList(items), getMismatches(missed));
}
fail("%nExpected to have received exactly%n<%s>%nbut received%n<%s>.%nExpected the following items to be received:%n%s",
fail("%nExpected to have received exactly%n<%s>%nbut received%n<%s>.%nThe following items were not expected:%n<%s>",
getItemList(expected), getItemList(items), getItemList(extra));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,43 @@ public void testItemsAndCompletion() {

assertThatThrownBy(() -> subscriber.assertItems("a"))
.isInstanceOf(AssertionError.class)
.hasMessageContaining("Expected the following items to be received");
.hasMessageContaining("The following items were not expected:\n<b>");
}

@Test
public void testAssertItemsMessages() {
AssertSubscriber<String> subscriber = AssertSubscriber.create();
Subscription subscription = mock(Subscription.class);

subscriber.onSubscribe(subscription);
subscriber.request(2);
verify(subscription).request(2);

subscriber.onNext("a");
subscriber.onNext("b");
subscriber.onNext("c");

subscriber.assertItems("a", "b", "c");

String m1 = "\nExpected to have received exactly:\n" +
"<a,b,c,d>\n" +
"but received:\n" +
"<a,b,c>.\n" +
"Mismatches are:\n" +
"\t- Missing expected item <d>";
assertThatThrownBy(() -> subscriber.assertItems("a", "b", "c", "d"))
.isInstanceOf(AssertionError.class)
.hasMessage(m1);

String m2 = "\nExpected to have received exactly\n" +
"<a,b>\n" +
"but received\n" +
"<a,b,c>.\n" +
"The following items were not expected:\n" +
"<c>";
assertThatThrownBy(() -> subscriber.assertItems("a", "b"))
.isInstanceOf(AssertionError.class)
.hasMessage(m2);
}

@Test
Expand Down

0 comments on commit a44539f

Please sign in to comment.