Skip to content

Commit

Permalink
Minor cleanups to OptionalSubjectTest.
Browse files Browse the repository at this point in the history
This is just like what bbd289b1b11bd1c290500b24ec570ac4be3f8326 did to GuavaOptionalSubjectTest, plus a few more changes to bring the two files in line with one another.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=188042977
  • Loading branch information
cpovirk authored and ronshapiro committed Mar 7, 2018
1 parent e818e8e commit 70d8bd0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ public void hasValue_failingWithAbsent() {
}

@Test
public void hasValue_errorWithNullParameter() {
public void hasValue_npeWithNullParameter() {
try {
assertThat(Optional.of("foo")).hasValue(null);
fail("Expected NPE");
} catch (NullPointerException expected) {
assertThat(expected).hasMessageThat().contains("Optional");
return;
}
fail("Should have thrown");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@
*/
@RunWith(JUnit4.class)
public class OptionalSubjectTest {
@Test
public void namedOptional() {
Optional<String> optional = Optional.of("actual");
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(optional).named("name").hasValue("expected"));
assertThat(expected)
.hasMessageThat()
.isEqualTo("Not true that name (<Optional[actual]>) has value <expected>");
}

@Test
public void isPresent() {
Expand All @@ -55,7 +46,7 @@ public void isPresentFailing() {
}

@Test
public void isPresentFailingWithNamed() {
public void isPresentFailing_named() {
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(Optional.empty()).named("name").isPresent());
assertThat(expected).hasMessageThat().isEqualTo("Not true that \"name\" is present");
Expand Down Expand Up @@ -91,7 +82,7 @@ public void hasValue() {
}

@Test
public void hasValue_FailingWithEmpty() {
public void hasValue_failingWithEmpty() {
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(Optional.empty()).hasValue("foo"));
assertThat(expected)
Expand All @@ -100,7 +91,7 @@ public void hasValue_FailingWithEmpty() {
}

@Test
public void hasValue_NPEWithNullParameter() {
public void hasValue_npeWithNullParameter() {
try {
assertThat(Optional.of("foo")).hasValue(null);
fail("Expected NPE");
Expand All @@ -110,7 +101,7 @@ public void hasValue_NPEWithNullParameter() {
}

@Test
public void hasValue_FailingWithWrongValueForString() {
public void hasValue_failingWithWrongValueForString() {
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(Optional.of("foo")).hasValue("boo"));
assertThat(expected)
Expand All @@ -119,24 +110,35 @@ public void hasValue_FailingWithWrongValueForString() {
}

@Test
public void hasValue_FailingWithWrongValueForOther() {
public void hasValue_failingWithWrongValueForString_named() {
AssertionError expected =
expectFailure(
whenTesting -> whenTesting.that(Optional.of("foo")).named("bar").hasValue("boo"));
assertThat(expected)
.hasMessageThat()
.isEqualTo("Not true that bar (<Optional[foo]>) has value <boo>");
}

@Test
public void hasValue_failingWithWrongValueForOther() {
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(Optional.of(5)).hasValue(10));
assertThat(expected).hasMessageThat().isEqualTo("Not true that <Optional[5]> has value <10>");
}

@Test
public void hasValue_Named_Failing() {
public void hasValue_failingWithSameToStrings() {
AssertionError expected =
expectFailure(
whenTesting -> whenTesting.that(Optional.of("foo")).named("bar").hasValue("boo"));
expectFailure(whenTesting -> whenTesting.that(Optional.of(10)).hasValue("10"));
assertThat(expected)
.hasMessageThat()
.isEqualTo("Not true that bar (<Optional[foo]>) has value <boo>");
.isEqualTo(
"Not true that <Optional[10]> (class java.lang.Integer) "
+ "has value <10> (class java.lang.String)");
}

@Test
public void hasValue_Named_FailingWithSameToStrings() {
public void hasValue_failingWithSameToStrings_named() {
AssertionError expected =
expectFailure(whenTesting -> whenTesting.that(Optional.of(10)).named("bar").hasValue("10"));
assertThat(expected)
Expand Down

0 comments on commit 70d8bd0

Please sign in to comment.