@Test public void testConstructorArguments() throws Exception { assertIllegalArgumentException(() -> Buffer.buffer(-1)); assertNullPointerException(() -> Buffer.buffer((byte[]) null)); assertNullPointerException(() -> Buffer.buffer((String) null)); assertNullPointerException(() -> Buffer.buffer((ByteBuf) null)); assertNullPointerException(() -> Buffer.buffer(null, "UTF-8")); assertNullPointerException(() -> Buffer.buffer("", null)); }
@Test public void testRequestNPE() { String uri = "/some-uri?foo=bar"; TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod)null, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, uri, resp -> {})); TestUtils.assertNullPointerException(() -> client.requestAbs((HttpMethod) null, "http://someuri", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", "/somepath", null)); TestUtils.assertNullPointerException(() -> client.request((HttpMethod) null, 8080, "localhost", "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, null, "/somepath", resp -> { })); TestUtils.assertNullPointerException(() -> client.request(HttpMethod.GET, 8080, "localhost", null, resp -> { })); }
@Test public void testWebsocketFrameFactoryArguments() throws Exception { assertNullPointerException(() -> WebSocketFrame.binaryFrame(null, true)); assertNullPointerException(() -> WebSocketFrame.textFrame(null, true)); assertNullPointerException(() -> WebSocketFrame.continuationFrame(null, true)); }
@Test public void testIllegalArguments() { assertNullPointerException(() -> RecordParser.newDelimited((Buffer) null, handler -> {})); assertNullPointerException(() -> RecordParser.newDelimited((String) null, handler -> {})); RecordParser parser = RecordParser.newDelimited("", handler -> {}); assertNullPointerException(() -> parser.setOutput(null)); assertNullPointerException(() -> parser.delimitedMode((Buffer) null)); assertNullPointerException(() -> parser.delimitedMode((String) null)); assertIllegalArgumentException(() -> parser.maxRecordSize(-1)); }
@Test public void testSetBytesBuffer() throws Exception { testSetBytesBuffer(Buffer.buffer(150), Buffer::buffer); assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null)); }
@Test public void testSetBytesBuffer2() throws Exception { testSetBytesBuffer(Buffer.buffer(150), PADDED_BUFFER_FACTORY); assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (ByteBuffer) null)); }
@Test public void testConnectInvalidConnectHandler() throws Exception { assertNullPointerException(() -> client.connect(80, "localhost", null)); }
private void testSetBytesString(Buffer buff) throws Exception { String str = TestUtils.randomUnicodeString(100); buff.setString(50, str); byte[] b1 = buff.getBytes(50, buff.length()); String str2 = new String(b1, "UTF-8"); assertEquals(str, str2); assertNullPointerException(() -> Buffer.buffer(150).setString(0, null)); assertNullPointerException(() -> Buffer.buffer(150).setString(0, null, "UTF-8")); //TODO setString with encoding }
@Test public void testAppendString1() throws Exception { String str = TestUtils.randomUnicodeString(100); byte[] sb = str.getBytes("UTF-8"); Buffer b = Buffer.buffer(); b.appendString(str); assertEquals(b.length(), sb.length); assertTrue(str.equals(b.toString("UTF-8"))); assertTrue(str.equals(b.toString(StandardCharsets.UTF_8))); assertNullPointerException(() -> b.appendString(null)); assertNullPointerException(() -> b.appendString(null, "UTF-8")); assertNullPointerException(() -> b.appendString("", null)); }
@Test public void testConnectInvalidHost() { assertNullPointerException(() -> client.connect(80, null, res -> {})); client.connect(1234, "127.0.0.2", res -> { assertTrue(res.failed()); assertFalse(res.succeeded()); assertNotNull(res.cause()); testComplete(); }); await(); }
@Test public void testDeliveryOptions() { DeliveryOptions options = new DeliveryOptions(); assertIllegalArgumentException(() -> options.setSendTimeout(0)); assertIllegalArgumentException(() -> options.setSendTimeout(-1)); assertNullPointerException(() -> options.addHeader(null, "")); assertNullPointerException(() -> options.addHeader("", null)); }
@Test public void testGetMapWithNullResultHandler() throws Exception { assertNullPointerException(() -> getVertx().sharedData().<String, String>getAsyncMap("foo", null)); }
@Test public void testGetMapWithNullName() throws Exception { assertNullPointerException(() -> getVertx().sharedData().<String, String>getAsyncMap(null, ar -> {})); }
@Test public void testDefaultCodecNullName() throws Exception { assertNullPointerException(() -> vertx.eventBus().registerDefaultCodec(String.class, new NullNameCodec())); }
@Test public void testIllegalArguments() throws Exception { assertNullPointerException(() -> getVertx().sharedData().getLock(null, ar -> {})); assertNullPointerException(() -> getVertx().sharedData().getLock("foo", null)); assertNullPointerException(() -> getVertx().sharedData().getLockWithTimeout(null, 1, ar -> {})); assertNullPointerException(() -> getVertx().sharedData().getLockWithTimeout("foo", 1, null)); assertIllegalArgumentException(() -> getVertx().sharedData().getLockWithTimeout("foo", -1, ar -> {})); }
private void testAppendBufferWithOffsetAndLen(Function<byte[], Buffer> bufferFactory) throws Exception { int bytesLen = 100; byte[] bytes = TestUtils.randomByteArray(bytesLen); Buffer src = bufferFactory.apply(bytes); int len = bytes.length - 2; Buffer b = Buffer.buffer(); b.appendBuffer(src, 1, len); assertEquals(b.length(), len); byte[] copy = new byte[len]; System.arraycopy(bytes, 1, copy, 0, len); assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes())); b.appendBuffer(src, 1, len); assertEquals(b.length(), 2 * len); assertNullPointerException(() -> b.appendBuffer(null, 1, len)); }
public void testAppendBuff(Function<byte[], Buffer> bufferFactory) throws Exception { int bytesLen = 100; byte[] bytes = TestUtils.randomByteArray(bytesLen); Buffer toAppend = bufferFactory.apply(bytes); Buffer b = Buffer.buffer(); b.appendBuffer(toAppend); assertEquals(b.length(), bytes.length); assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes())); b.appendBuffer(toAppend); assertEquals(b.length(), 2 * bytes.length); assertNullPointerException(() -> b.appendBuffer(null)); }
@Test public void testSocketAddress() throws Exception { assertNullPointerException(() -> new SocketAddressImpl(0, null)); assertIllegalArgumentException(() -> new SocketAddressImpl(0, "")); assertIllegalArgumentException(() -> new SocketAddressImpl(-1, "someHost")); assertIllegalArgumentException(() -> new SocketAddressImpl(65536, "someHost")); }
@Test public void testAppendBytes() throws Exception { int bytesLen = 100; byte[] bytes = TestUtils.randomByteArray(bytesLen); Buffer b = Buffer.buffer(); b.appendBytes(bytes); assertEquals(b.length(), bytes.length); assertTrue(TestUtils.byteArraysEqual(bytes, b.getBytes())); b.appendBytes(bytes); assertEquals(b.length(), 2 * bytes.length); assertNullPointerException(() -> b.appendBytes(null)); }
@Test public void testMap() throws Exception { assertNullPointerException(() -> sharedData.getLocalMap(null)); LocalMap<String, String> map = sharedData.getLocalMap("foo"); LocalMap<String, String> map2 = sharedData.getLocalMap("foo"); assertTrue(map == map2); LocalMap<String, String> map3 = sharedData.getLocalMap("bar"); assertFalse(map3 == map2); map.close(); LocalMap<String, String> map4 = sharedData.getLocalMap("foo"); assertFalse(map4 == map3); }