Skip to content

Commit

Permalink
NoIssue: condensed similar test methods in parameterized test
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Feb 18, 2021
1 parent 2eb0073 commit 9145bc2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/test/java/com/restfb/FacebookClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import com.restfb.WebRequestor.Response;
import com.restfb.exception.FacebookJsonMappingException;
Expand Down Expand Up @@ -321,23 +324,19 @@ void testDebugTokenException() throws IOException {
});
}

@Test
void deleteObjectReturnsJson() {
FacebookClient facebookClient = facebookClientWithResponse(new Response(200, "{\"success\":true}"));
@ParameterizedTest
@MethodSource("provideDeleteResponseBody")
void deleteObjetReturnValue(String responseString) {
FacebookClient facebookClient = facebookClientWithResponse(new Response(200, responseString));
assertThat(facebookClient.deleteObject("12345")).isTrue();
}

@Test
void deleteObjectReturnsJsonGreetingMessengerPlatform() {
FacebookClient facebookClient =
facebookClientWithResponse(new Response(200, "{\"result\":\"Successfully deleted greeting\"}"));
assertThat(facebookClient.deleteObject("12345")).isTrue();
}

@Test
void deleteObjectReturnsText() {
FacebookClient facebookClient = facebookClientWithResponse(new Response(200, "true"));
assertThat(facebookClient.deleteObject("12345")).isTrue();
private static Stream<String> provideDeleteResponseBody() {
return Stream.of( //
"{\"success\":true}", // simple json
"{\"result\":\"Successfully deleted greeting\"}", // Json Greeting from Messenger Platform
"true" // only text
);
}

@Test
Expand Down

0 comments on commit 9145bc2

Please sign in to comment.