diff --git a/build.gradle b/build.gradle index d291040e..ce4b945a 100644 --- a/build.gradle +++ b/build.gradle @@ -10,9 +10,9 @@ plugins { } compileJava { - if (JavaVersion.current().ordinal() > JavaVersion.VERSION_1_8.ordinal()) { - options.compilerArgs.addAll(['--release', '8', '-Xlint']) - } + sourceCompatibility = '8' + targetCompatibility = '8' + options.compilerArgs.add('-Xlint') } repositories { diff --git a/src/test/scala/tlschannel/ApiTest.java b/src/test/scala/tlschannel/ApiTest.java new file mode 100644 index 00000000..2dc7822b --- /dev/null +++ b/src/test/scala/tlschannel/ApiTest.java @@ -0,0 +1,66 @@ +package tlschannel; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.WritableByteChannel; +import java.security.NoSuchAlgorithmException; +import java.util.Optional; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import tlschannel.impl.ByteBufferSet; +import tlschannel.impl.TlsChannelImpl; + +@TestInstance(Lifecycle.PER_CLASS) +public class ApiTest { + + private static final int arraySize = 1024; + + private final ReadableByteChannel readChannel = Channels.newChannel(new ByteArrayInputStream(new byte[arraySize])); + private final WritableByteChannel writeChannel = Channels.newChannel(new ByteArrayOutputStream(arraySize)); + + private TlsChannelImpl newSocket() { + try { + SSLEngine sslEngine = SSLContext.getDefault().createSSLEngine(); + return new TlsChannelImpl( + readChannel, + writeChannel, + sslEngine, + Optional.empty(), + session -> {}, + true, + new TrackingAllocator(new HeapBufferAllocator()), + new TrackingAllocator(new HeapBufferAllocator()), + true /* releaseBuffers */, + false /* waitForCloseConfirmation */); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testReadIntoReadOnlyBuffer() throws IOException { + try (TlsChannelImpl socket = newSocket()) { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + socket.read(new ByteBufferSet(ByteBuffer.allocate(1).asReadOnlyBuffer())); + }); + } + } + + @Test + public void testReadIntoBufferWithoutCapacity() throws IOException { + try (TlsChannelImpl socket = newSocket()) { + Assertions.assertEquals( + 0, + socket.read(new ByteBufferSet(ByteBuffer.allocate(0))), + "read must return zero when the buffer was empty"); + } + } +} diff --git a/src/test/scala/tlschannel/ApiTest.scala b/src/test/scala/tlschannel/ApiTest.scala deleted file mode 100644 index a35ad173..00000000 --- a/src/test/scala/tlschannel/ApiTest.scala +++ /dev/null @@ -1,58 +0,0 @@ -package tlschannel - -import org.junit.jupiter.api.TestInstance.Lifecycle -import org.junit.jupiter.api.{Assertions, Test, TestInstance} - -import java.nio.channels.Channels -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream -import java.nio.ByteBuffer -import javax.net.ssl.SSLContext -import tlschannel.impl.{BufferHolder, ByteBufferSet, TlsChannelImpl} - -import java.util.Optional - -@TestInstance(Lifecycle.PER_CLASS) -class ApiTest { - - val arraySize = 1024 - - val readChannel = Channels.newChannel(new ByteArrayInputStream(new Array(arraySize))) - val writeChannel = Channels.newChannel(new ByteArrayOutputStream(arraySize)) - - def newSocket() = { - val sslEngine = SSLContext.getDefault.createSSLEngine - new TlsChannelImpl( - readChannel, - writeChannel, - sslEngine, - Optional.empty[BufferHolder], - _ => (), - true, - new TrackingAllocator(new HeapBufferAllocator), - new TrackingAllocator(new HeapBufferAllocator), - true /* releaseBuffers */, - false /* waitForCloseConfirmation */ - ) - } - - @Test - def testReadIntoReadOnlyBuffer(): Unit = { - val socket = newSocket() - Assertions.assertThrows( - classOf[IllegalArgumentException], - () => socket.read(new ByteBufferSet(ByteBuffer.allocate(1).asReadOnlyBuffer())) - ) - } - - @Test - def testReadIntoBufferWithoutCapacity(): Unit = { - val socket = newSocket() - Assertions.assertEquals( - 0, - socket.read(new ByteBufferSet(ByteBuffer.allocate(0))), - "read must return zero when the buffer was empty" - ) - } - -} diff --git a/src/test/scala/tlschannel/helpers/NullSslEngine.java b/src/test/scala/tlschannel/helpers/NullSslEngine.java index 76f3519c..5964b73e 100644 --- a/src/test/scala/tlschannel/helpers/NullSslEngine.java +++ b/src/test/scala/tlschannel/helpers/NullSslEngine.java @@ -115,7 +115,7 @@ public void setWantClientAuth(boolean b) {} @Override public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length) { - var dstSet = new ByteBufferSet(dsts, offset, length); + ByteBufferSet dstSet = new ByteBufferSet(dsts, offset, length); if (!src.hasRemaining()) { return new SSLEngineResult(Status.BUFFER_UNDERFLOW, HandshakeStatus.NOT_HANDSHAKING, 0, 0); } @@ -132,7 +132,7 @@ public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int @Override public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst) { - var srcSet = new ByteBufferSet(srcs, offset, length); + ByteBufferSet srcSet = new ByteBufferSet(srcs, offset, length); if (!srcSet.hasRemaining()) { return new SSLEngineResult(Status.OK, HandshakeStatus.NOT_HANDSHAKING, 0, 0); }