Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java APIs for TestServer.runningHttpPort and TestServer.runningHttpsPort #8294

Closed
marcospereira opened this issue Mar 14, 2018 · 2 comments

Comments

@marcospereira
Copy link
Member

marcospereira commented Mar 14, 2018

Play Version

2.6.4 and above.

API

Java.

Expected Behavior

We need to have Java APIs for TestServer.runningHttpPort and TestServer.runningHttpsPort. Ideally, these APIs will return an Optional<Integer>.

Actual Behavior

We currently have TestServer.port which is deprecated:

/**
* The port that the server is running on.
*/
@deprecated("Using runningHttpPort or runningHttpsPort instead", "2.6.4")
def port: Int = config.port.getOrElse(throw new IllegalStateException("No HTTP port defined"))

And it is recommending to use either TestServer.runningHttpPort:

/**
* The HTTP port that the server is running on.
*/
def runningHttpPort: Option[Int] = getTestServerIfRunning.httpPort

Or TestServer.runningHttpsPort:

/**
* The HTTPS port that the server is running on.
*/
def runningHttpsPort: Option[Int] = getTestServerIfRunning.httpsPort

But both are returning Option[Int]. That is a Scala API, and we need to add the Java correspondents.

@Shenker93
Copy link
Contributor

Shenker93 commented Mar 17, 2018

Java 8 also provides OptionalInt container class, it wraps primitive int value instead of Integer, so container object is little bit more lightweight and more precisely conveys the essence. It also lets to avoid unnecessary boxing-unboxing operations in client code. I think it is better to use such approach here. @marcospereira , what do you think of it? I can open a PR and override such methods for java API

@marcospereira
Copy link
Member Author

@Shenker93 makes sense to me.

I can to open a PR and override such methods for java API

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants