You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/05/23 21:44:13 UTC
[httpcomponents-core] 02/02: Adjusted test cases incompatible with
Java 16 strong encapsulation of JDK internals
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch devel
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit 97b3bfbb7e34936fb650ae7e138bac219fd00409
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun May 23 23:37:55 2021 +0200
Adjusted test cases incompatible with Java 16 strong encapsulation of JDK internals
---
.travis.yml | 5 +----
.../org/apache/hc/core5/testing/nio/H2AlpnTest.java | 10 +++++++++-
.../core5/testing/nio/H2ProtocolNegotiationTest.java | 10 +++++-----
.../hc/core5/http/impl/io/TestBHttpConnectionBase.java | 18 +++++++-----------
.../hc/core5/http/impl/io/TestSessionInOutBuffers.java | 5 +++--
5 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index c6cff08..2116214 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,6 +24,7 @@ jdk:
- oraclejdk8
- openjdk11
- oraclejdk11
+ - oraclejdk16
- openjdk-ea
addons:
@@ -41,7 +42,3 @@ jobs:
script: mvn verify -B
allow_failures:
- jdk: openjdk-ea
-
-
-after_success:
- - mvn clean cobertura:cobertura coveralls:report
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
index 20d27a0..1775200 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
@@ -65,6 +65,7 @@ import org.apache.hc.core5.util.Timeout;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.junit.Assume;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -164,9 +165,16 @@ public class H2AlpnTest {
};
+ private static int JAVA_VER;
+
@BeforeClass
public static void determineJavaVersion() {
- Assume.assumeTrue("Java version must be 9 or greater", ReflectionUtils.determineJRELevel() >= 9);
+ JAVA_VER = ReflectionUtils.determineJRELevel();
+ }
+
+ @Before
+ public void checkVersion() {
+ Assume.assumeTrue("Java version must be 9 or greater and less than 16", JAVA_VER >= 9 && JAVA_VER < 16);
}
@Test
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ProtocolNegotiationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ProtocolNegotiationTest.java
index dc959b0..974ff98 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ProtocolNegotiationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ProtocolNegotiationTest.java
@@ -145,16 +145,16 @@ public class H2ProtocolNegotiationTest {
};
- private static int javaVersion;
+ private static int JAVA_VER;
@BeforeClass
public static void determineJavaVersion() {
- javaVersion = ReflectionUtils.determineJRELevel();
+ JAVA_VER = ReflectionUtils.determineJRELevel();
}
@Before
public void checkVersion() {
- Assume.assumeTrue("Java version must be 1.8 or greater", javaVersion > 7);
+ Assume.assumeTrue("Java version must be 1.8 or greater", JAVA_VER >= 8);
}
@Test
@@ -232,7 +232,7 @@ public class H2ProtocolNegotiationTest {
}
private boolean isAlpnSupported() {
- if (javaVersion == 8) {
+ if (JAVA_VER == 8) {
// The 'java.version' property values are structured "1.8.0_[BUILD NUMBER]" in java 8 releases.
final Matcher matcher = Pattern.compile("^1\\.8\\.0_(\\d+)$")
.matcher(System.getProperty("java.version"));
@@ -243,7 +243,7 @@ public class H2ProtocolNegotiationTest {
return java8Build >= 251;
}
}
- return javaVersion > 8;
+ return JAVA_VER > 8 && JAVA_VER < 16;
}
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
index 8559dca..73e2494 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
@@ -231,8 +231,8 @@ public class TestBHttpConnectionBase {
@Test
public void testAwaitInputInBuffer() throws Exception {
- final ByteArrayInputStream inStream = Mockito.spy(new ByteArrayInputStream(
- new byte[] {1, 2, 3, 4, 5}));
+ final ByteArrayInputStream inStream = new ByteArrayInputStream(
+ new byte[] {1, 2, 3, 4, 5});
conn.bind(socket);
conn.ensureOpen();
conn.inBuffer.read(inStream);
@@ -240,14 +240,12 @@ public class TestBHttpConnectionBase {
Assert.assertTrue(conn.awaitInput(Timeout.ofMilliseconds(432)));
Mockito.verify(socket, Mockito.never()).setSoTimeout(ArgumentMatchers.anyInt());
- Mockito.verify(inStream, Mockito.times(1)).read(
- ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt());
}
@Test
public void testAwaitInputInSocket() throws Exception {
- final ByteArrayInputStream inStream = Mockito.spy(new ByteArrayInputStream(
- new byte[] {1, 2, 3, 4, 5}));
+ final ByteArrayInputStream inStream = new ByteArrayInputStream(
+ new byte[] {1, 2, 3, 4, 5});
Mockito.when(socket.getInputStream()).thenReturn(inStream);
Mockito.when(socket.getSoTimeout()).thenReturn(345);
@@ -258,9 +256,7 @@ public class TestBHttpConnectionBase {
Mockito.verify(socket, Mockito.times(1)).setSoTimeout(432);
Mockito.verify(socket, Mockito.times(1)).setSoTimeout(345);
- Mockito.verify(inStream, Mockito.times(1)).read(
- ArgumentMatchers.any(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt());
- }
+ }
@Test
public void testAwaitInputNoData() throws Exception {
@@ -289,8 +285,8 @@ public class TestBHttpConnectionBase {
@Test
public void testNotStaleWhenHasData() throws Exception {
- final ByteArrayInputStream inStream = Mockito.spy(new ByteArrayInputStream(
- new byte[] {1, 2, 3, 4, 5}));
+ final ByteArrayInputStream inStream = new ByteArrayInputStream(
+ new byte[] {1, 2, 3, 4, 5});
Mockito.when(socket.getInputStream()).thenReturn(inStream);
conn.bind(socket);
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestSessionInOutBuffers.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestSessionInOutBuffers.java
index 82d3e4a..3323b88 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestSessionInOutBuffers.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestSessionInOutBuffers.java
@@ -30,6 +30,7 @@ package org.apache.hc.core5.http.impl.io;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
@@ -370,7 +371,7 @@ public class TestSessionInOutBuffers {
@Test
public void testWriteSmallFragmentBuffering() throws Exception {
- final ByteArrayOutputStream outputStream = Mockito.spy(new ByteArrayOutputStream());
+ final OutputStream outputStream = Mockito.mock(OutputStream.class);
final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(new BasicHttpTransportMetrics(), 16, 16, null);
outbuffer.write(1, outputStream);
outbuffer.write(2, outputStream);
@@ -383,7 +384,7 @@ public class TestSessionInOutBuffers {
@Test
public void testWriteSmallFragmentNoBuffering() throws Exception {
- final ByteArrayOutputStream outputStream = Mockito.spy(new ByteArrayOutputStream());
+ final OutputStream outputStream = Mockito.mock(OutputStream.class);
final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(new BasicHttpTransportMetrics(), 16, 0, null);
outbuffer.write(1, outputStream);
outbuffer.write(2, outputStream);