Created
November 9, 2015 12:04
-
-
Save relax-more/d440a6672a45585d8db1 to your computer and use it in GitHub Desktop.
how to assert Exception with TypeSafeMatcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AreTest { | |
@Test | |
public void test_WithTypeSafeMatcher() throws Exception { | |
when(service.getAre()).thenThrow(ApiException.class); | |
thrown.expect(new TypeSafeMatcher<ApiException>() { | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("expects EXPECTED_ERROR_CODE"); | |
} | |
@Override | |
protected boolean matchesSafely(ApiException item) { | |
return item.getResultCode() == ResultCode.EXPECTED_ERROR_CODE; | |
} | |
}); | |
target.get(); | |
} | |
public class Are { | |
@Inject | |
AreService service; | |
public void get () { | |
service.getAre(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment