Java Code Examples for org.assertj.core.api.Assertions#failBecauseExceptionWasNotThrown()

The following examples show how to use org.assertj.core.api.Assertions#failBecauseExceptionWasNotThrown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwitterServiceTest.java    From WTFDYUM with Apache License 2.0 6 votes vote down vote up
@Test
public void getFollowersTestWithoutPrincipalRateLimit() throws Exception {
    final IDs idsMock = mock(IDs.class);
    when(twitter.getFollowersIDs(444L, -1)).thenReturn(idsMock);

    final RateLimitStatus rateLimitStatusMock = mock(RateLimitStatus.class);
    when(idsMock.hasNext()).thenReturn(true);
    when(idsMock.getRateLimitStatus()).thenReturn(rateLimitStatusMock);

    when(rateLimitStatusMock.getRemaining()).thenReturn(0);

    try {
        sut.getFollowers(444L, Optional.<Principal> empty());
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (final WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED);
    }
}
 
Example 2
Source File: JmxReporterTest.java    From metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void cleansUpAfterItselfWhenStopped() throws Exception {
    reporter.stop();

    try {
        getAttributes("gauge", "Value");
        Assertions.failBecauseExceptionWasNotThrown(InstanceNotFoundException.class);
    } catch (InstanceNotFoundException e) {

    }
}
 
Example 3
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportObjectRequest() throws IOException, InterruptedException {
    de.mannodermaus.retrofit2.model.ForeignModel requestBody = new de.mannodermaus.retrofit2.model.ForeignModel();

    try {
        // Call the API and execute it
        service.callObjectRequestNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 4
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportObjectResponse() throws IOException, InterruptedException {
    BasicModel requestBody = new BasicModel();

    try {
        // Call the API and execute it
        service.callObjectResponseNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 5
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportListRequest() throws IOException, InterruptedException {
    List<de.mannodermaus.retrofit2.model.ForeignModel> requestBody = new ArrayList<>();
    requestBody.add(new de.mannodermaus.retrofit2.model.ForeignModel());

    try {
        // Call the API and execute it
        service.callListRequestNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 6
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportListResponse() throws IOException, InterruptedException {
    BasicModel requestBody = new BasicModel();

    try {
        // Call the API and execute it
        service.callListResponseNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 7
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportMapRequest() throws IOException, InterruptedException {
    Map<String, de.mannodermaus.retrofit2.model.ForeignModel> requestBody = new HashMap<>();
    requestBody.put("obj", new de.mannodermaus.retrofit2.model.ForeignModel());

    try {
        // Call the API and execute it
        service.callMapRequestNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 8
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoesntSupportMapResponse() throws IOException, InterruptedException {
    BasicModel requestBody = new BasicModel();

    try {
        // Call the API and execute it
        service.callMapResponseNotSupported(requestBody).execute();
        Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException ignored) {
    }
}
 
Example 9
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapWrongKeyType() throws IOException {
    mockWebServer.enqueue(new MockResponse().setBody("{}"));

    // Setup the mock object with an incompatible type argument
    Map<Integer, BasicModel> body = new HashMap<>();
    body.put(1, new BasicModel("name", "not", CustomEnum.VAL_1, null));

    // Setup the API call and fire it
    try {
        service.callMapWrongKey(body).execute();
        Assertions.failBecauseExceptionWasNotThrown(RuntimeException.class);
    } catch (RuntimeException ignored) {
    }
}
 
Example 10
Source File: LoganSquareConverterTest.java    From retrofit-logansquare with Apache License 2.0 5 votes vote down vote up
@Test
public void testArray() throws IOException {
    mockWebServer.enqueue(new MockResponse().setBody("{}"));

    // Setup the mock object with an incompatible type argument
    BasicModel[] body = new BasicModel[] { new BasicModel("name", "not", CustomEnum.VAL_2, null)};

    // Setup the API call and fire it
    try {
        service.callArray(body).execute();
        Assertions.failBecauseExceptionWasNotThrown(RuntimeException.class);
    } catch (RuntimeException ignored) {
    }
}
 
Example 11
Source File: SecurityAspectTest.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Test(expected = SecurityException.class)
public void aroundSecuredMethodTestUnauthorized() throws Throwable {
    when(authenticationService.isAuthenticated()).thenReturn(false);

    sut.aroundSecuredMethod(pjp, new Secured() {
        @Override
        public Class<? extends Annotation> annotationType() {
            // TODO Auto-generated method stub
            return null;
        }
    });

    Assertions.failBecauseExceptionWasNotThrown(SecurityException.class);
}
 
Example 12
Source File: TwitterServiceTest.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Test
public void getUsersTwitterExceptionTest() throws Exception {
    final User userMock = mock(User.class);
    when(userMock.getName()).thenReturn("name");
    when(userMock.getScreenName()).thenReturn("screenName");
    when(userMock.getProfileImageURL()).thenReturn("profile img url");
    when(userMock.getURL()).thenReturn("user url");

    final ResponseList<User> users = new ResponseListMockForTest<User>();
    final long[] ids = new long[100];

    final Random rand = new Random();
    for(int i = 0; i < 100; i++) {
        users.add(userMock);
        final long id = rand.nextLong();

        when(userMock.getId()).thenReturn(id);
        ids[i] = id;
    }

    when(twitter.users()).thenReturn(usersResources);
    when(usersResources.lookupUsers(ids)).thenThrow(TwitterException.class);

    try {
        sut.getUsers(new Principal(1L, "", ""), ids);
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
    }
}
 
Example 13
Source File: TwitterServiceTest.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Test
public void getFollowersTestWithoutPrincipalTwitterException() throws Exception {
    when(twitter.getFollowersIDs(444L, -1)).thenThrow(new TwitterException("msg"));

    try {
        sut.getFollowers(444L, Optional.<Principal> empty());
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (final WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
    }

}
 
Example 14
Source File: TwitterServiceTest.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Test
public void sendDirectMessageTestException() throws Exception {
    when(twitter.sendDirectMessage(444L, "text")).thenThrow(new TwitterException("msg"));

    try {
        sut.sendDirectMessage(new Principal(412L, "", ""), 444L, "text");
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (final WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
    }
}
 
Example 15
Source File: GraphiteNamePatternTest.java    From client_java with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void createNew_WHEN_InvalidPattern_THEN_ShouldThrowException() {
    final List<String> invalidPatterns = Arrays.asList(
            "",
            "a",
            "1org",
            "1org.",
            "org.",
            "org.**",
            "org.**",
            "org.company-",
            "org.company-.",
            "org.company-*",
            "org.company.**",
            "org.company.**-",
            "org.com*pany.*",
            "org.test.contr.oller.gather.status..400",
            "org.test.controller.gather.status..400"
    );
    final GraphiteNamePattern graphiteNamePattern = new GraphiteNamePattern("");
    for (String pattern : invalidPatterns) {
        try {
            new GraphiteNamePattern(pattern);

            Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
        } catch (IllegalArgumentException e) {
            Assertions.assertThat(e).hasMessageContaining(pattern);
        }
    }
}