Last active
November 20, 2016 19:43
-
-
Save jlprat/5e1c27ce4b912e0a3eb0ad56237246d7 to your computer and use it in GitHub Desktop.
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
import akka.http.javadsl.marshallers.jackson.Jackson; | |
import akka.http.javadsl.model.HttpRequest; | |
import akka.http.javadsl.model.StatusCodes; | |
import akka.http.javadsl.server.Route; | |
import akka.http.javadsl.testkit.JUnitRouteTest; | |
import org.junit.Test; | |
import java.util.Optional; | |
public class RejectEmptyResponseBug extends JUnitRouteTest { | |
@Test | |
public void testRejectEmptyResponseBug() { | |
final Route route = path("foo", () -> completeOK(Optional.empty(), Jackson.marshaller())); | |
final Route route2 = rejectEmptyResponse(() -> path("foo", () -> completeOK(Optional.empty(), Jackson.marshaller()))); | |
final Route route3 = path("foo", () -> completeOK(Optional.of(42), Jackson.marshaller())); | |
//what happens | |
testRoute(route).run(HttpRequest.GET("/foo")).assertEntity("{\"present\":false}"); | |
testRoute(route2).run(HttpRequest.GET("/foo")).assertEntity("{\"present\":false}"); | |
testRoute(route3).run(HttpRequest.GET("/foo")).assertEntity("{\"present\":true}"); | |
//what is expected | |
testRoute(route).run(HttpRequest.GET("/foo")).assertEntity(""); | |
testRoute(route2).run(HttpRequest.GET("/foo")).assertStatusCode(StatusCodes.NOT_FOUND); | |
testRoute(route3).run(HttpRequest.GET("/foo")).assertEntity("42"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment