1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-08 23:42:08 +03:00

Don't use @JvmStatic for internal calls

This commit is contained in:
Jesse Wilson
2019-05-20 16:00:40 -04:00
parent ac2618ade2
commit 2e0dfa29d0
41 changed files with 157 additions and 183 deletions

View File

@@ -35,7 +35,6 @@ object DnsRecordCodec {
private const val TYPE_PTR = 0x000c
private val ASCII = StandardCharsets.US_ASCII
@JvmStatic
fun encodeQuery(host: String, type: Int): ByteString = Buffer().apply {
writeShort(0) // query id
writeShort(256) // flags with recursion
@@ -62,7 +61,6 @@ object DnsRecordCodec {
}.readByteString()
@Throws(Exception::class)
@JvmStatic
fun decodeAnswers(hostname: String, byteString: ByteString): List<InetAddress> {
val result = ArrayList<InetAddress>()

View File

@@ -34,7 +34,7 @@ public class DnsRecordCodecTest {
}
private String encodeQuery(String host, int type) {
return DnsRecordCodec.encodeQuery(host, type).base64Url().replace("=", "");
return DnsRecordCodec.INSTANCE.encodeQuery(host, type).base64Url().replace("=", "");
}
@Test public void testGoogleDotComEncodingWithIPv6() {
@@ -44,30 +44,37 @@ public class DnsRecordCodecTest {
}
@Test public void testGoogleDotComDecodingFromCloudflare() throws Exception {
List<InetAddress> encoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"00008180000100010000000006676f6f676c6503636f6d0000010001c00c00010001000000430004d83ad54e"));
List<InetAddress> encoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
ByteString.decodeHex("00008180000100010000000006676f6f676c6503636f6d0000010001c00c000100010"
+ "00000430004d83ad54e"));
assertThat(encoded).containsExactly(InetAddress.getByName("216.58.213.78"));
}
@Test public void testGoogleDotComDecodingFromGoogle() throws Exception {
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c012c042000100010000003b00049df00112"));
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d0000010"
+ "001c00c0005000100000a6d000603617069c012c0300005000100000cde000c04737461720463313072c"
+ "012c042000100010000003b00049df00112"));
assertThat(decoded).containsExactly(InetAddress.getByName("157.240.1.18"));
}
@Test public void testGoogleDotComDecodingFromGoogleIPv6() throws Exception {
List<InetAddress> decoded = DnsRecordCodec.decodeAnswers("test.com", ByteString.decodeHex(
"0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
List<InetAddress> decoded = DnsRecordCodec.INSTANCE.decodeAnswers("test.com",
ByteString.decodeHex("0000818000010003000000000567726170680866616365626f6f6b03636f6d00001c0"
+ "001c00c0005000100000a1b000603617069c012c0300005000100000b1f000c04737461720463313072c"
+ "012c042001c00010000003b00102a032880f0290011faceb00c00000002"));
assertThat(decoded).containsExactly(InetAddress.getByName("2a03:2880:f029:11:face:b00c:0:2"));
}
@Test public void testGoogleDotComDecodingNxdomainFailure() throws Exception {
try {
DnsRecordCodec.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex(
"0000818300010000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e10000003840012750000000e10"));
DnsRecordCodec.INSTANCE.decodeAnswers("sdflkhfsdlkjdf.ee", ByteString.decodeHex("000081830001"
+ "0000000100000e7364666c6b686673646c6b6a64660265650000010001c01b00060001000007070038026e"
+ "7303746c64c01b0a686f73746d61737465720d6565737469696e7465726e6574c01b5adb12c100000e1000"
+ "0003840012750000000e10"));
fail();
} catch (UnknownHostException uhe) {
assertThat(uhe.getMessage()).isEqualTo("sdflkhfsdlkjdf.ee: NXDOMAIN");

View File

@@ -724,7 +724,6 @@ class Cache internal constructor(
fun key(url: HttpUrl): String = url.toString().encodeUtf8().md5().hex()
@Throws(IOException::class)
@JvmStatic
internal fun readInt(source: BufferedSource): Int {
try {
val result = source.readDecimalLong()

View File

@@ -1421,7 +1421,6 @@ class HttpUrl internal constructor(
* Returns the index of the ':' in `input` that is after scheme characters. Returns -1 if
* `input` does not have a scheme that starts at `pos`.
*/
@JvmStatic
private fun schemeDelimiterOffset(input: String, pos: Int, limit: Int): Int {
if (limit - pos < 2) return -1
@@ -1493,7 +1492,6 @@ class HttpUrl internal constructor(
}
companion object {
@JvmStatic
private val HEX_DIGITS =
charArrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F')
internal const val USERNAME_ENCODE_SET = " \"':;<=>@[]^`{}|/\\?#"

View File

@@ -25,9 +25,7 @@ import okhttp3.internal.connection.RealConnectionPool
* packages.
*/
object Internal {
@JvmStatic
fun realConnectionPool(connectionPool: ConnectionPool): RealConnectionPool = connectionPool.delegate
@JvmStatic
fun exchange(response: Response): Exchange? = response.exchange
}

View File

@@ -83,7 +83,7 @@ object Util {
}
}
@JvmStatic fun threadFactory(
fun threadFactory(
name: String,
daemon: Boolean
): ThreadFactory = ThreadFactory { runnable ->
@@ -232,13 +232,11 @@ object Util {
}
/** Returns true if [host] is not a host name and might be an IP address. */
@JvmStatic
fun verifyAsIpAddress(host: String): Boolean {
return VERIFY_AS_IP_ADDRESS.matches(host)
}
/** Returns a [Locale.US] formatted [String]. */
@JvmStatic
fun format(format: String, vararg args: Any): String {
return String.format(Locale.US, format, *args)
}

View File

@@ -981,7 +981,6 @@ class DiskLruCache internal constructor(
* @param valueCount the number of values per cache entry. Must be positive.
* @param maxSize the maximum number of bytes this cache should use to store
*/
@JvmStatic
fun create(
fileSystem: FileSystem,
directory: File,

View File

@@ -309,7 +309,6 @@ class Relay private constructor(
* close that when they're done. Otherwise a handle to [file] will be leaked.
*/
@Throws(IOException::class)
@JvmStatic
fun edit(
file: File,
upstream: Source,
@@ -333,7 +332,6 @@ class Relay private constructor(
* close that when they're done. Otherwise a handle to [file] will be leaked.
*/
@Throws(IOException::class)
@JvmStatic
fun read(file: File): Relay {
val randomAccessFile = RandomAccessFile(file, "rw")
val fileOperator = FileOperator(randomAccessFile.channel)

View File

@@ -700,7 +700,6 @@ class RealConnection(
private const val NPE_THROW_WITH_NULL = "throw with null exception"
private const val MAX_TUNNEL_ATTEMPTS = 21
@JvmStatic
fun newTestConnection(
connectionPool: RealConnectionPool,
route: Route,

View File

@@ -182,7 +182,6 @@ class RouteSelector(
companion object {
/** Obtain a host string containing either an actual host name or a numeric IP address. */
@JvmStatic
val InetSocketAddress.socketHost: String get() {
// The InetSocketAddress was specified with a string (either a numeric IP or a host name). If
// it is a name, all IPs for that name should be tried. If it is an IP address, only that IP

View File

@@ -19,8 +19,8 @@ import okhttp3.internal.Util.UTC
import java.text.DateFormat
import java.text.ParsePosition
import java.text.SimpleDateFormat
import java.util.Locale
import java.util.Date
import java.util.Locale
/**
* Best-effort parser for HTTP dates.
@@ -69,7 +69,6 @@ object HttpDate {
private val BROWSER_COMPATIBLE_DATE_FORMATS = arrayOfNulls<DateFormat>(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.size)
/** Returns the date for [value]. Returns null if the value couldn't be parsed. */
@JvmStatic
fun parse(value: String): Date? {
if (value.isEmpty()) {
return null
@@ -109,7 +108,6 @@ object HttpDate {
}
/** Returns the string for [value]. */
@JvmStatic
fun format(value: Date): String {
return STANDARD_DATE_FORMAT.get().format(value)
}

View File

@@ -16,29 +16,24 @@
package okhttp3.internal.http
object HttpMethod {
@JvmStatic
fun invalidatesCache(method: String): Boolean = (method == "POST" ||
method == "PATCH" ||
method == "PUT" ||
method == "DELETE" ||
method == "MOVE") // WebDAV
@JvmStatic
fun requiresRequestBody(method: String): Boolean = (method == "POST" ||
method == "PUT" ||
method == "PATCH" ||
method == "PROPPATCH" || // WebDAV
method == "REPORT") // CalDAV/CardDAV (defined in WebDAV Versioning)
@JvmStatic
fun permitsRequestBody(method: String): Boolean = !(method == "GET" || method == "HEAD")
@JvmStatic
fun redirectsWithBody(method: String): Boolean =
// (WebDAV) redirects should also maintain the request body
method == "PROPFIND"
@JvmStatic
fun redirectsToGet(method: String): Boolean =
// All requests but PROPFIND should redirect to a GET request.
method != "PROPFIND"

View File

@@ -15,10 +15,10 @@
*/
package okhttp3.internal.http
import java.net.HttpURLConnection
import java.net.Proxy
import okhttp3.HttpUrl
import okhttp3.Request
import java.net.HttpURLConnection
import java.net.Proxy
object RequestLine {
@@ -27,7 +27,6 @@ object RequestLine {
* [HttpURLConnection.getHeaderFields], so it needs to be set even if the transport is
* HTTP/2.
*/
@JvmStatic
fun get(request: Request, proxyType: Proxy.Type): String {
val result = StringBuilder()
result.append(request.method())
@@ -47,7 +46,6 @@ object RequestLine {
* Returns true if the request line should contain the full URL with host and port (like "GET
* http://android.com/foo HTTP/1.1") or only the path (like "GET /foo HTTP/1.1").
*/
@JvmStatic
private fun includeAuthorityInRequestLine(request: Request, proxyType: Proxy.Type): Boolean {
return !request.isHttps && proxyType == Proxy.Type.HTTP
}
@@ -56,7 +54,6 @@ object RequestLine {
* Returns the path to request, like the '/' in 'GET / HTTP/1.1'. Never empty, even if the request
* URL is. Includes the query component if it exists.
*/
@JvmStatic
fun requestPath(url: HttpUrl): String {
val path = url.encodedPath()
val query = url.encodedQuery()

View File

@@ -45,12 +45,10 @@ class StatusLine(
const val HTTP_PERM_REDIRECT = 308
const val HTTP_CONTINUE = 100
@JvmStatic
fun get(response: Response): StatusLine {
return StatusLine(response.protocol(), response.code(), response.message())
}
@JvmStatic
@Throws(IOException::class)
fun parse(statusLine: String): StatusLine {
// H T T P / 1 . 1 2 0 0 T e m p o r a r y R e d i r e c t

View File

@@ -105,7 +105,6 @@ object Http2 {
* `<< 0x0000000f 12 HEADERS END_HEADERS|END_STREAM
* ```
*/
@JvmStatic
fun frameLog(
inbound: Boolean,
streamId: Int,
@@ -125,7 +124,6 @@ object Http2 {
* in binary.
*/
// Visible for testing.
@JvmStatic
fun formatFlags(type: Int, flags: Int): String {
if (flags == 0) return ""
when (type) {

View File

@@ -106,7 +106,6 @@ class ConscryptPlatform private constructor() : Platform() {
}
companion object {
@JvmStatic
fun buildIfSupported(): ConscryptPlatform? = try {
// Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
Class.forName("org.conscrypt.Conscrypt\$Version")
@@ -119,7 +118,6 @@ class ConscryptPlatform private constructor() : Platform() {
null
}
@JvmStatic @JvmOverloads
fun atLeastVersion(major: Int, minor: Int = 0, patch: Int = 0): Boolean {
val conscryptVersion = Conscrypt.version()

View File

@@ -123,7 +123,6 @@ class Jdk8WithJettyBootPlatform(
}
companion object {
@JvmStatic
fun buildIfSupported(): Platform? {
val jvmVersion = System.getProperty("java.specification.version", "unknown")
try {

View File

@@ -71,7 +71,6 @@ class Jdk9Platform(
}
companion object {
@JvmStatic
fun buildIfSupported(): Jdk9Platform? =
try {
// Find JDK 9 methods

View File

@@ -193,7 +193,6 @@ open class Platform {
fun alpnProtocolNames(protocols: List<Protocol>) =
protocols.filter { it != Protocol.HTTP_1_0 }.map { it.toString() }
@JvmStatic
val isConscryptPreferred: Boolean
get() {
val preferredProvider = Security.getProviders()[0].name
@@ -201,7 +200,6 @@ open class Platform {
}
/** Attempt to match the host runtime to a capable Platform implementation. */
@JvmStatic
private fun findPlatform(): Platform {
val android = AndroidPlatform.buildIfSupported()
@@ -233,7 +231,6 @@ open class Platform {
* Returns the concatenation of 8-bit, length prefixed protocol names.
* http://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-4
*/
@JvmStatic
fun concatLengthPrefixed(protocols: List<Protocol>): ByteArray {
val result = Buffer()
for (protocol in alpnProtocolNames(protocols)) {
@@ -243,7 +240,6 @@ open class Platform {
return result.readByteArray()
}
@JvmStatic
fun <T> readFieldOrNull(instance: Any, fieldType: Class<T>, fieldName: String): T? {
var c: Class<*> = instance.javaClass
while (c != Any::class.java) {

View File

@@ -38,12 +38,10 @@ abstract class CertificateChainCleaner {
abstract fun clean(chain: List<Certificate>, hostname: String): List<Certificate>
companion object {
@JvmStatic
fun get(trustManager: X509TrustManager): CertificateChainCleaner {
return Platform.get().buildCertificateChainCleaner(trustManager)
}
@JvmStatic
fun get(vararg caCerts: X509Certificate): CertificateChainCleaner {
return BasicCertificateChainCleaner(BasicTrustRootIndex(*caCerts))
}

View File

@@ -95,7 +95,6 @@ object WebSocketProtocol {
/** Used when an empty close frame was received (i.e., without a status code). */
internal const val CLOSE_NO_STATUS_CODE = 1005
@JvmStatic
fun toggleMask(cursor: Buffer.UnsafeCursor, key: ByteArray) {
var keyIndex = 0
val keyLength = key.size
@@ -120,7 +119,6 @@ object WebSocketProtocol {
} while (cursor.next() != -1)
}
@JvmStatic
fun closeCodeExceptionMessage(code: Int): String? {
return if (code < 1000 || code >= 5000) {
"Code must be in range [1000,5000): $code"
@@ -131,7 +129,6 @@ object WebSocketProtocol {
}
}
@JvmStatic
fun validateCloseCode(code: Int) {
val message = closeCodeExceptionMessage(code)
if (message != null) {
@@ -139,7 +136,6 @@ object WebSocketProtocol {
}
}
@JvmStatic
fun acceptHeader(key: String): String {
return (key + ACCEPT_MAGIC).encodeUtf8().sha1().base64()
}

View File

@@ -37,22 +37,22 @@ public final class CertificateChainCleanerTest {
HeldCertificate rootB = new HeldCertificate.Builder()
.serialNumber(2L)
.build();
assertThat(CertificateChainCleaner.get(rootB.certificate(), rootA.certificate())).isEqualTo(
CertificateChainCleaner.get(rootA.certificate(), rootB.certificate()));
assertThat(CertificateChainCleaner.Companion.get(rootB.certificate(), rootA.certificate()))
.isEqualTo(CertificateChainCleaner.Companion.get(rootA.certificate(), rootB.certificate()));
}
@Test public void equalsFromTrustManager() {
HandshakeCertificates handshakeCertificates = new HandshakeCertificates.Builder().build();
X509TrustManager x509TrustManager = handshakeCertificates.trustManager();
assertThat(CertificateChainCleaner.get(x509TrustManager)).isEqualTo(
CertificateChainCleaner.get(x509TrustManager));
assertThat(CertificateChainCleaner.Companion.get(x509TrustManager)).isEqualTo(
CertificateChainCleaner.Companion.get(x509TrustManager));
}
@Test public void normalizeSingleSelfSignedCertificate() throws Exception {
HeldCertificate root = new HeldCertificate.Builder()
.serialNumber(1L)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(root), "hostname")).isEqualTo(list(root));
}
@@ -60,7 +60,7 @@ public final class CertificateChainCleanerTest {
HeldCertificate root = new HeldCertificate.Builder()
.serialNumber(1L)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get();
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get();
try {
cleaner.clean(list(root), "hostname");
@@ -82,7 +82,7 @@ public final class CertificateChainCleanerTest {
.signedBy(certA)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certB, certA, root), "hostname")).isEqualTo(
list(certB, certA, root));
}
@@ -100,7 +100,7 @@ public final class CertificateChainCleanerTest {
.signedBy(certA)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
// Root is added!
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
list(certB, certA, root));
@@ -123,7 +123,7 @@ public final class CertificateChainCleanerTest {
.signedBy(certB)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certC, certA, root, certB), "hostname")).isEqualTo(
list(certC, certB, certA, root));
}
@@ -145,7 +145,7 @@ public final class CertificateChainCleanerTest {
.signedBy(certB)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certC, certA, certB), "hostname")).isEqualTo(
list(certC, certB, certA, root));
}
@@ -166,7 +166,7 @@ public final class CertificateChainCleanerTest {
.serialNumber(4L)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root.certificate());
assertThat(cleaner.clean(list(certB, certUnnecessary, certA, root), "hostname")).isEqualTo(
list(certB, certA, root));
}
@@ -188,7 +188,7 @@ public final class CertificateChainCleanerTest {
.signedBy(certA)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(
selfSigned.certificate(), trusted.certificate());
assertThat(cleaner.clean(list(certB, certA), "hostname")).isEqualTo(
list(certB, certA, trusted, selfSigned));
@@ -215,7 +215,7 @@ public final class CertificateChainCleanerTest {
.serialNumber(4L)
.build();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(trusted.certificate());
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(trusted.certificate());
assertThat(cleaner.clean(list(certificate, intermediateCa), "hostname")).isEqualTo(
list(certificate, intermediateCa, trusted));
assertThat(cleaner.clean(list(certificate, intermediateCa, trusted), "hostname")).isEqualTo(
@@ -230,7 +230,7 @@ public final class CertificateChainCleanerTest {
}
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
assertThat(cleaner.clean(certificates, "hostname")).isEqualTo(certificates);
assertThat(cleaner.clean(certificates.subList(0, 9), "hostname")).isEqualTo(
certificates);
@@ -244,7 +244,7 @@ public final class CertificateChainCleanerTest {
}
X509Certificate root = heldCertificates.get(heldCertificates.size() - 1).certificate();
CertificateChainCleaner cleaner = CertificateChainCleaner.get(root);
CertificateChainCleaner cleaner = CertificateChainCleaner.Companion.get(root);
try {
cleaner.clean(certificates, "hostname");
fail();

View File

@@ -89,7 +89,7 @@ public final class EventListenerTest {
.eventListener(listener)
.build();
listener.forbidLock(Internal.realConnectionPool(client.connectionPool()));
listener.forbidLock(Internal.INSTANCE.realConnectionPool(client.connectionPool()));
listener.forbidLock(client.dispatcher());
}

View File

@@ -58,7 +58,7 @@ public final class SocksProxy {
private static final Logger logger = Logger.getLogger(SocksProxy.class.getName());
private final ExecutorService executor = Executors.newCachedThreadPool(
Util.threadFactory("SocksProxy", false));
Util.INSTANCE.threadFactory("SocksProxy", false));
private ServerSocket serverSocket;
private AtomicInteger connectionCount = new AtomicInteger();

View File

@@ -232,7 +232,7 @@ class UrlComponentEncodingTester {
String urlString = component.urlString(encoded);
HttpUrl url = HttpUrl.get(urlString);
if (!component.encodedValue(url).equals(encoded)) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
}
@@ -243,7 +243,7 @@ class UrlComponentEncodingTester {
HttpUrl url = builder.build();
String actual = component.get(url);
if (!expected.equals(actual)) {
fail(Util.format("Roundtrip %s %#x %s", component, codePoint, url));
fail(Util.INSTANCE.format("Roundtrip %s %#x %s", component, codePoint, url));
}
}
@@ -256,7 +256,7 @@ class UrlComponentEncodingTester {
String s = component.encodedValue(url);
if (!s.equals(encoded)) {
fail(Util.format("Encoding %s %#02x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#02x using %s", component, codePoint, encoding));
}
}
@@ -265,7 +265,7 @@ class UrlComponentEncodingTester {
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
URL javaNetUrl = httpUrl.url();
if (!javaNetUrl.toString().equals(javaNetUrl.toString())) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
}
@@ -274,7 +274,7 @@ class UrlComponentEncodingTester {
HttpUrl httpUrl = HttpUrl.get(component.urlString(encoded));
HttpUrl toAndFromJavaNetUrl = HttpUrl.get(httpUrl.url());
if (!toAndFromJavaNetUrl.equals(httpUrl)) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
}
@@ -288,18 +288,18 @@ class UrlComponentEncodingTester {
if (uriEscaped) {
// The URI has more escaping than the HttpURL. Check that the decoded values still match.
if (uri.toString().equals(httpUrl.toString())) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
if (!component.get(toAndFromUri).equals(string)) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
} else {
// Check that the URI and HttpURL have the exact same escaping.
if (!toAndFromUri.equals(httpUrl)) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
if (!uri.toString().equals(httpUrl.toString())) {
fail(Util.format("Encoding %s %#x using %s", component, codePoint, encoding));
fail(Util.INSTANCE.format("Encoding %s %#x using %s", component, codePoint, encoding));
}
}
}
@@ -316,7 +316,7 @@ class UrlComponentEncodingTester {
ByteString utf8 = ByteString.encodeUtf8(IDENTITY.encode(codePoint));
Buffer percentEncoded = new Buffer();
for (int i = 0; i < utf8.size(); i++) {
percentEncoded.writeUtf8(Util.format("%%%02X", utf8.getByte(i) & 0xff));
percentEncoded.writeUtf8(Util.INSTANCE.format("%%%02X", utf8.getByte(i) & 0xff));
}
return percentEncoded.readUtf8();
}

View File

@@ -82,7 +82,7 @@ public final class WebPlatformUrlTestData {
}
@Override public String toString() {
return Util.format("Parsing: <%s> against <%s>", input, base);
return Util.INSTANCE.format("Parsing: <%s> against <%s>", input, base);
}
public static List<WebPlatformUrlTestData> load(BufferedSource source) throws IOException {

View File

@@ -662,7 +662,7 @@ public final class DiskLruCacheTest {
@Test public void constructorDoesNotAllowZeroCacheSize() throws Exception {
try {
DiskLruCache.create(fileSystem, cacheDir, appVersion, 2, 0);
DiskLruCache.Companion.create(fileSystem, cacheDir, appVersion, 2, 0);
fail();
} catch (IllegalArgumentException expected) {
}
@@ -670,7 +670,7 @@ public final class DiskLruCacheTest {
@Test public void constructorDoesNotAllowZeroValuesPerEntry() throws Exception {
try {
DiskLruCache.create(fileSystem, cacheDir, appVersion, 0, 10);
DiskLruCache.Companion.create(fileSystem, cacheDir, appVersion, 0, 10);
fail();
} catch (IllegalArgumentException expected) {
}
@@ -978,7 +978,7 @@ public final class DiskLruCacheTest {
@Test public void openCreatesDirectoryIfNecessary() throws Exception {
cache.close();
File dir = tempDir.newFolder("testOpenCreatesDirectoryIfNecessary");
cache = DiskLruCache.create(fileSystem, dir, appVersion, 2, Integer.MAX_VALUE);
cache = DiskLruCache.Companion.create(fileSystem, dir, appVersion, 2, Integer.MAX_VALUE);
set("a", "a", "a");
assertThat(fileSystem.exists(new File(dir, "a.0"))).isTrue();
assertThat(fileSystem.exists(new File(dir, "a.1"))).isTrue();

View File

@@ -56,7 +56,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghijklm");
Relay relay = Relay.edit(file, upstream, metadata, 1024);
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
Source source = relay.newSource();
Buffer sourceBuffer = new Buffer();
@@ -78,7 +78,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghijklm");
Relay relay = Relay.edit(file, upstream, metadata, 1024);
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
BufferedSource source1 = Okio.buffer(relay.newSource());
BufferedSource source2 = Okio.buffer(relay.newSource());
@@ -95,7 +95,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghij");
Relay relay = Relay.edit(file, upstream, metadata, 5);
Relay relay = Relay.Companion.edit(file, upstream, metadata, 5);
BufferedSource source1 = Okio.buffer(relay.newSource());
BufferedSource source2 = Okio.buffer(relay.newSource());
@@ -116,7 +116,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghijklmnopqrst");
Relay relay = Relay.edit(file, upstream, metadata, 5);
Relay relay = Relay.Companion.edit(file, upstream, metadata, 5);
BufferedSource source1 = Okio.buffer(relay.newSource());
BufferedSource source2 = Okio.buffer(relay.newSource());
@@ -137,7 +137,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghij");
Relay relay1 = Relay.edit(file, upstream, metadata, 5);
Relay relay1 = Relay.Companion.edit(file, upstream, metadata, 5);
BufferedSource source1 = Okio.buffer(relay1.newSource());
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
assertThat(source1.exhausted()).isTrue();
@@ -147,7 +147,7 @@ public final class RelayTest {
// Since relay1 is closed, new sources cannot be created.
assertThat(relay1.newSource()).isNull();
Relay relay2 = Relay.read(file);
Relay relay2 = Relay.Companion.read(file);
assertThat(relay2.metadata()).isEqualTo(metadata);
BufferedSource source2 = Okio.buffer(relay2.newSource());
assertThat(source2.readUtf8(10)).isEqualTo("abcdefghij");
@@ -165,14 +165,14 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcdefghij");
Relay relay1 = Relay.edit(file, upstream, metadata, 5);
Relay relay1 = Relay.Companion.edit(file, upstream, metadata, 5);
BufferedSource source1 = Okio.buffer(relay1.newSource());
assertThat(source1.readUtf8(10)).isEqualTo("abcdefghij");
source1.close(); // Not exhausted!
assertThat(relay1.isClosed()).isTrue();
try {
Relay.read(file);
Relay.Companion.read(file);
fail();
} catch (IOException expected) {
assertThat(expected.getMessage()).isEqualTo("unreadable cache file");
@@ -185,7 +185,7 @@ public final class RelayTest {
Buffer upstream = new Buffer();
upstream.writeUtf8("abcde");
Relay relay = Relay.edit(file, upstream, metadata, 1024);
Relay relay = Relay.Companion.edit(file, upstream, metadata, 1024);
Source source1 = relay.newSource();
Source source2 = relay.newSource();
@@ -202,7 +202,7 @@ public final class RelayTest {
Pipe pipe = new Pipe(1024);
BufferedSink sink = Okio.buffer(pipe.sink());
Relay relay = Relay.edit(file, pipe.source(), metadata, 5);
Relay relay = Relay.Companion.edit(file, pipe.source(), metadata, 5);
Future<ByteString> future1 = executor.submit(sourceReader(relay.newSource()));
Future<ByteString> future2 = executor.submit(sourceReader(relay.newSource()));

View File

@@ -34,7 +34,6 @@ import okhttp3.internal.RecordingOkAuthenticator;
import org.junit.Test;
import static okhttp3.TestUtil.awaitGarbageCollection;
import static okhttp3.internal.connection.RealConnection.newTestConnection;
import static org.assertj.core.api.Assertions.assertThat;
public final class ConnectionPoolTest {
@@ -79,7 +78,7 @@ public final class ConnectionPoolTest {
@Test public void inUseConnectionsNotEvicted() throws Exception {
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
RealConnectionPool pool = Internal.realConnectionPool(poolApi);
RealConnectionPool pool = Internal.INSTANCE.realConnectionPool(poolApi);
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
RealConnection c1 = newConnection(pool, routeA1, 50L);
@@ -167,7 +166,7 @@ public final class ConnectionPoolTest {
@Test public void leakedAllocation() throws Exception {
ConnectionPool poolApi = new ConnectionPool(Integer.MAX_VALUE, 100L, TimeUnit.NANOSECONDS);
RealConnectionPool pool = Internal.realConnectionPool(poolApi);
RealConnectionPool pool = Internal.INSTANCE.realConnectionPool(poolApi);
pool.setCleanupRunning(true); // Prevent the cleanup runnable from being started.
RealConnection c1 = newConnection(pool, routeA1, 0L);
@@ -183,7 +182,7 @@ public final class ConnectionPoolTest {
/** Use a helper method so there's no hidden reference remaining on the stack. */
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
synchronized (Internal.realConnectionPool(pool)) {
synchronized (Internal.INSTANCE.realConnectionPool(pool)) {
OkHttpClient client = new OkHttpClient.Builder()
.connectionPool(pool)
.build();
@@ -195,7 +194,8 @@ public final class ConnectionPoolTest {
}
private RealConnection newConnection(RealConnectionPool pool, Route route, long idleAtNanos) {
RealConnection result = newTestConnection(pool, route, new Socket(), idleAtNanos);
RealConnection result = RealConnection.Companion.newTestConnection(
pool, route, new Socket(), idleAtNanos);
synchronized (pool) {
pool.put(result);
}

View File

@@ -422,19 +422,19 @@ public final class RouteSelectorTest {
@Test public void getHostString() throws Exception {
// Name proxy specification.
InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("host", 1234);
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("host");
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("host");
socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 1234);
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
// InetAddress proxy specification.
socketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 1234);
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
socketAddress = new InetSocketAddress(
InetAddress.getByAddress(new byte[] {127, 0, 0, 1}), 1234);
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
socketAddress = new InetSocketAddress(
InetAddress.getByAddress("foobar", new byte[] {127, 0, 0, 1}), 1234);
assertThat(RouteSelector.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
assertThat(RouteSelector.Companion.getSocketHost(socketAddress)).isEqualTo("127.0.0.1");
}
@Test public void routeToString() throws Exception {

View File

@@ -13,80 +13,84 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.internal.http;
package okhttp3.internal.http
import java.util.Date;
import java.util.TimeZone;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.Date
import java.util.TimeZone
import static org.assertj.core.api.Assertions.assertThat;
class HttpDateTest {
public class HttpDateTest {
private TimeZone originalDefault;
private lateinit var originalDefault: TimeZone
@Before
public void setUp() throws Exception {
originalDefault = TimeZone.getDefault();
@Throws(Exception::class)
fun setUp() {
originalDefault = TimeZone.getDefault()
// The default timezone should affect none of these tests: HTTP specified GMT, so we set it to
// something else.
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
}
@After
public void tearDown() throws Exception {
TimeZone.setDefault(originalDefault);
@Throws(Exception::class)
fun tearDown() {
TimeZone.setDefault(originalDefault)
}
@Test public void parseStandardFormats() throws Exception {
@Test @Throws(Exception::class)
fun parseStandardFormats() {
// RFC 822, updated by RFC 1123 with GMT.
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT").getTime()).isEqualTo(0L);
assertThat(HttpDate.parse("Fri, 06 Jun 2014 12:30:30 GMT").getTime()).isEqualTo(1402057830000L);
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT")!!.time).isEqualTo(0L)
assertThat(HttpDate.parse("Fri, 06 Jun 2014 12:30:30 GMT")!!.time).isEqualTo(1402057830000L)
// RFC 850, obsoleted by RFC 1036 with GMT.
assertThat(HttpDate.parse("Thursday, 01-Jan-70 00:00:00 GMT").getTime()).isEqualTo(0L);
assertThat(HttpDate.parse("Friday, 06-Jun-14 12:30:30 GMT").getTime()).isEqualTo(1402057830000L);
assertThat(HttpDate.parse("Thursday, 01-Jan-70 00:00:00 GMT")!!.time).isEqualTo(0L)
assertThat(HttpDate.parse("Friday, 06-Jun-14 12:30:30 GMT")!!.time).isEqualTo(1402057830000L)
// ANSI C's asctime(): should use GMT, not platform default.
assertThat(HttpDate.parse("Thu Jan 1 00:00:00 1970").getTime()).isEqualTo(0L);
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014").getTime()).isEqualTo(1402057830000L);
assertThat(HttpDate.parse("Thu Jan 1 00:00:00 1970")!!.time).isEqualTo(0L)
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014")!!.time).isEqualTo(1402057830000L)
}
@Test public void format() throws Exception {
assertThat(HttpDate.format(new Date(0))).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT");
assertThat(HttpDate.format(new Date(1402057830000L))).isEqualTo(
"Fri, 06 Jun 2014 12:30:30 GMT");
@Test @Throws(Exception::class)
fun format() {
assertThat(HttpDate.format(Date(0L))).isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT")
assertThat(HttpDate.format(Date(1402057830000L))).isEqualTo("Fri, 06 Jun 2014 12:30:30 GMT")
}
@Test public void parseNonStandardStrings() throws Exception {
@Test @Throws(Exception::class)
fun parseNonStandardStrings() {
// RFC 822, updated by RFC 1123 with any TZ
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT-01:00").getTime()).isEqualTo(3600000L);
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 PST").getTime()).isEqualTo(28800000L);
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT-01:00")!!.time).isEqualTo(3600000L)
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 PST")!!.time).isEqualTo(28800000L)
// Ignore trailing junk
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT JUNK").getTime()).isEqualTo(0L);
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00 GMT JUNK")!!.time).isEqualTo(0L)
// Missing timezones treated as bad.
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00")).isNull();
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00:00")).isNull()
// Missing seconds treated as bad.
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull();
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull()
// Extra spaces treated as bad.
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull();
assertThat(HttpDate.parse("Thu, 01 Jan 1970 00:00 GMT")).isNull()
// Missing leading zero treated as bad.
assertThat(HttpDate.parse("Thu, 1 Jan 1970 00:00 GMT")).isNull();
assertThat(HttpDate.parse("Thu, 1 Jan 1970 00:00 GMT")).isNull()
// RFC 850, obsoleted by RFC 1036 with any TZ.
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 GMT-01:00").getTime()).isEqualTo(
3600000L);
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST").getTime()).isEqualTo(28800000L);
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 GMT-01:00")!!.time)
.isEqualTo(3600000L)
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST")!!.time)
.isEqualTo(28800000L)
// Ignore trailing junk
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST JUNK").getTime()).isEqualTo(
28800000L);
assertThat(HttpDate.parse("Thursday, 01-Jan-1970 00:00:00 PST JUNK")!!.time)
.isEqualTo(28800000L)
// ANSI C's asctime() format
// This format ignores the timezone entirely even if it is present and uses GMT.
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 PST").getTime()).isEqualTo(1402057830000L);
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 PST")!!.time).isEqualTo(1402057830000L)
// Ignore trailing junk.
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 JUNK").getTime()).isEqualTo(1402057830000L);
assertThat(HttpDate.parse("Fri Jun 6 12:30:30 2014 JUNK")!!.time).isEqualTo(1402057830000L)
}
}

View File

@@ -44,7 +44,7 @@ public final class RecordingProxySelector extends ProxySelector {
@Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
InetSocketAddress socketAddress = (InetSocketAddress) sa;
failures.add(Util.format("%s %s:%d %s",
failures.add(Util.INSTANCE.format("%s %s:%d %s",
uri, socketAddress, socketAddress.getPort(), ioe.getMessage()));
}

View File

@@ -28,7 +28,8 @@ public final class StatusLineTest {
String message = "Temporary Redirect";
int version = 1;
int code = 200;
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code + " " + message);
StatusLine statusLine = StatusLine.Companion.parse(
"HTTP/1." + version + " " + code + " " + message);
assertThat(statusLine.message).isEqualTo(message);
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
assertThat(statusLine.code).isEqualTo(code);
@@ -37,7 +38,7 @@ public final class StatusLineTest {
@Test public void emptyMessage() throws IOException {
int version = 1;
int code = 503;
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code + " ");
StatusLine statusLine = StatusLine.Companion.parse("HTTP/1." + version + " " + code + " ");
assertThat(statusLine.message).isEqualTo("");
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
assertThat(statusLine.code).isEqualTo(code);
@@ -50,7 +51,7 @@ public final class StatusLineTest {
@Test public void emptyMessageAndNoLeadingSpace() throws IOException {
int version = 1;
int code = 503;
StatusLine statusLine = StatusLine.parse("HTTP/1." + version + " " + code);
StatusLine statusLine = StatusLine.Companion.parse("HTTP/1." + version + " " + code);
assertThat(statusLine.message).isEqualTo("");
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_1);
assertThat(statusLine.code).isEqualTo(code);
@@ -58,7 +59,7 @@ public final class StatusLineTest {
// https://github.com/square/okhttp/issues/386
@Test public void shoutcast() throws IOException {
StatusLine statusLine = StatusLine.parse("ICY 200 OK");
StatusLine statusLine = StatusLine.Companion.parse("ICY 200 OK");
assertThat(statusLine.message).isEqualTo("OK");
assertThat(statusLine.protocol).isEqualTo(Protocol.HTTP_1_0);
assertThat(statusLine.code).isEqualTo(200);
@@ -109,7 +110,7 @@ public final class StatusLineTest {
private void assertInvalid(String statusLine) throws IOException {
try {
StatusLine.parse(statusLine);
StatusLine.Companion.parse(statusLine);
fail();
} catch (ProtocolException expected) {
}

View File

@@ -30,7 +30,6 @@ import static okhttp3.internal.http2.Http2.TYPE_HEADERS;
import static okhttp3.internal.http2.Http2.TYPE_PING;
import static okhttp3.internal.http2.Http2.TYPE_PUSH_PROMISE;
import static okhttp3.internal.http2.Http2.TYPE_SETTINGS;
import static okhttp3.internal.http2.Http2.frameLog;
import static org.assertj.core.api.Assertions.assertThat;
public final class FrameLogTest {
@@ -89,7 +88,7 @@ public final class FrameLogTest {
*/
@Test public void allFormattedFlagsWithValidBits() {
List<String> formattedFlags = new ArrayList<>(0x40); // Highest valid flag is 0x20.
for (byte i = 0; i < 0x40; i++) formattedFlags.add(Http2.formatFlags(TYPE_HEADERS, i));
for (byte i = 0; i < 0x40; i++) formattedFlags.add(Http2.INSTANCE.formatFlags(TYPE_HEADERS, i));
assertThat(formattedFlags).containsExactly(
"",
@@ -158,4 +157,8 @@ public final class FrameLogTest {
"00111111"
);
}
private String frameLog(boolean inbound, int streamId, int length, int type, int flags) {
return Http2.INSTANCE.frameLog(inbound, streamId, length, type, flags);
}
}

View File

@@ -51,7 +51,7 @@ public final class MockHttp2Peer implements Closeable {
private final BlockingQueue<InFrame> inFrames = new LinkedBlockingQueue<>();
private int port;
private final ExecutorService executor = Executors.newSingleThreadExecutor(
Util.threadFactory("MockHttp2Peer", false));
Util.INSTANCE.threadFactory("MockHttp2Peer", false));
private ServerSocket serverSocket;
private Socket socket;

View File

@@ -31,13 +31,13 @@ public class Jdk8WithJettyBootPlatformTest {
assumeTrue(System.getProperty("java.specification.version").equals("1.8"));
platform.assumeJettyBootEnabled();
assertThat(Jdk8WithJettyBootPlatform.buildIfSupported()).isNotNull();
assertThat(Jdk8WithJettyBootPlatform.Companion.buildIfSupported()).isNotNull();
}
@Test
public void testNotBuildWithOther() {
assumeFalse(System.getProperty("java.specification.version").equals("1.8"));
assertThat(Jdk8WithJettyBootPlatform.buildIfSupported()).isNull();
assertThat(Jdk8WithJettyBootPlatform.Companion.buildIfSupported()).isNull();
}
}

View File

@@ -27,12 +27,12 @@ public class Jdk9PlatformTest {
@Test
public void buildsWhenJdk9() {
assertThat(Jdk9Platform.buildIfSupported()).isNotNull();
assertThat(Jdk9Platform.Companion.buildIfSupported()).isNotNull();
}
@Test
public void findsAlpnMethods() {
Jdk9Platform platform = Jdk9Platform.buildIfSupported();
Jdk9Platform platform = Jdk9Platform.Companion.buildIfSupported();
assertThat(platform.getProtocolMethod.getName()).isEqualTo("getApplicationProtocol");
assertThat(platform.setProtocolMethod.getName()).isEqualTo("setApplicationProtocols");

View File

@@ -518,28 +518,28 @@ public final class HostnameVerifierTest {
@Test public void verifyAsIpAddress() {
// IPv4
assertThat(Util.verifyAsIpAddress("127.0.0.1")).isTrue();
assertThat(Util.verifyAsIpAddress("1.2.3.4")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("127.0.0.1")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("1.2.3.4")).isTrue();
// IPv6
assertThat(Util.verifyAsIpAddress("::1")).isTrue();
assertThat(Util.verifyAsIpAddress("2001:db8::1")).isTrue();
assertThat(Util.verifyAsIpAddress("::192.168.0.1")).isTrue();
assertThat(Util.verifyAsIpAddress("::ffff:192.168.0.1")).isTrue();
assertThat(Util.verifyAsIpAddress("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210")).isTrue();
assertThat(Util.verifyAsIpAddress("1080:0:0:0:8:800:200C:417A")).isTrue();
assertThat(Util.verifyAsIpAddress("1080::8:800:200C:417A")).isTrue();
assertThat(Util.verifyAsIpAddress("FF01::101")).isTrue();
assertThat(Util.verifyAsIpAddress("0:0:0:0:0:0:13.1.68.3")).isTrue();
assertThat(Util.verifyAsIpAddress("0:0:0:0:0:FFFF:129.144.52.38")).isTrue();
assertThat(Util.verifyAsIpAddress("::13.1.68.3")).isTrue();
assertThat(Util.verifyAsIpAddress("::FFFF:129.144.52.38")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("::1")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("2001:db8::1")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("::192.168.0.1")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("::ffff:192.168.0.1")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("1080:0:0:0:8:800:200C:417A")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("1080::8:800:200C:417A")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("FF01::101")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("0:0:0:0:0:0:13.1.68.3")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("0:0:0:0:0:FFFF:129.144.52.38")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("::13.1.68.3")).isTrue();
assertThat(Util.INSTANCE.verifyAsIpAddress("::FFFF:129.144.52.38")).isTrue();
// Hostnames
assertThat(Util.verifyAsIpAddress("go")).isFalse();
assertThat(Util.verifyAsIpAddress("localhost")).isFalse();
assertThat(Util.verifyAsIpAddress("squareup.com")).isFalse();
assertThat(Util.verifyAsIpAddress("www.nintendo.co.jp")).isFalse();
assertThat(Util.INSTANCE.verifyAsIpAddress("go")).isFalse();
assertThat(Util.INSTANCE.verifyAsIpAddress("localhost")).isFalse();
assertThat(Util.INSTANCE.verifyAsIpAddress("squareup.com")).isFalse();
assertThat(Util.INSTANCE.verifyAsIpAddress("www.nintendo.co.jp")).isFalse();
}
private X509Certificate certificate(String certificate) throws Exception {

View File

@@ -764,7 +764,7 @@ public final class WebSocketHttpTest {
.setStatus("HTTP/1.1 101 Switching Protocols")
.setHeader("Connection", "Upgrade")
.setHeader("Upgrade", "websocket")
.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.acceptHeader(key));
.setHeader("Sec-WebSocket-Accept", WebSocketProtocol.INSTANCE.acceptHeader(key));
}
private void websocketScheme(String scheme) {

View File

@@ -299,7 +299,8 @@ public final class WebSocketReaderTest {
data.write(ByteString.decodeHex("880203ed")); // Close with code 1005
data.write(ByteString.decodeHex("880203ee")); // Close with code 1006
for (int i = 1012; i <= 2999; i++) {
data.write(ByteString.decodeHex("8802" + Util.format("%04X", i))); // Close with code 'i'
data.write(ByteString.decodeHex(
"8802" + Util.INSTANCE.format("%04X", i))); // Close with code 'i'
}
int count = 0;

View File

@@ -95,7 +95,7 @@ public final class WebSocketWriterTest {
sink.close();
assertData("817e");
assertData(Util.format("%04x", length));
assertData(Util.INSTANCE.format("%04x", length));
assertData(bytes);
assertThat(data.exhausted()).isTrue();
}
@@ -199,7 +199,7 @@ public final class WebSocketWriterTest {
// Write directly to the unbuffered sink. This ensures it will become single frame.
sink.write(payload.clone(), byteCount);
assertData("027e"); // 'e' == 4-byte follow-up length.
assertData(Util.format("%04X", payload.completeSegmentByteCount()));
assertData(Util.INSTANCE.format("%04X", payload.completeSegmentByteCount()));
assertData(payload.readByteArray());
sink.close();
@@ -219,7 +219,7 @@ public final class WebSocketWriterTest {
// Write directly to the unbuffered sink. This ensures it will become single frame.
sink.write(payload.clone(), byteCount);
assertData("027f"); // 'f' == 16-byte follow-up length.
assertData(Util.format("%016X", byteCount));
assertData(Util.INSTANCE.format("%016X", byteCount));
assertData(payload.readByteArray(byteCount));
sink.close();