From ea23f3074066f8c413fac10db43b6fb8a9722ca5 Mon Sep 17 00:00:00 2001 From: emeroad Date: Mon, 30 Jan 2023 16:20:56 +0900 Subject: [PATCH] [#noissue] Cleanup Assertions.assertThrows --- .../classloader/ParallelClassLoaderTest.java | 7 +-- .../classloader/PinpointClassLoaderTest.java | 6 +-- .../bootstrap/config/DumpTypeTest.java | 8 +--- ...DefaultInterceptorRegistryAdaptorTest.java | 25 ++++------ .../classloader/Java9ClassLoaderTest.java | 7 ++- .../classloader/PlatformClassLoaderTest.java | 7 +-- .../receiver/thrift/udp/UDPReceiverTest.java | 4 +- .../common/buffer/AutomaticBufferTest.java | 30 ++++-------- .../common/buffer/FixedBufferTest.java | 48 +++++++------------ .../common/buffer/OffsetFixedBufferTest.java | 19 +++----- .../hbase/util/HbaseTableNameCacheTest.java | 7 +-- .../trace/TraceMetadataLoaderTest.java | 12 ++--- .../trace/TraceMetadataRegistrarTest.java | 22 ++++----- .../zookeeper/CuratorZookeeperClientTest.java | 10 ++-- .../filter/SequenceSpanEventFilterTest.java | 7 +-- .../ApplicationNameRowKeyEncoderTest.java | 24 ++-------- .../common/server/util/time/RangeTest.java | 6 +-- .../pinpoint/common/util/ArrayUtilsTest.java | 6 +-- .../common/util/ByteSizeUnitTest.java | 6 +-- .../common/util/IdValidateUtilsTest.java | 6 +-- .../pinpoint/common/util/StringUtilsTest.java | 18 +++---- .../SystemMetricHostInfoServiceImplTest.java | 10 ++-- ...acleNetConnectionDescriptorParserTest.java | 29 ++++------- .../classloading/Java9DefineClassTest.java | 6 +-- .../PlainClassLoaderHandlerTest.java | 9 +--- .../metric/rpc/test/MetricRegistryTest.java | 20 +++----- .../profiler/sender/UdpSocketTest.java | 6 +-- .../DynamicTransformServiceTest.java | 8 ++-- .../profiler/util/JavaAssistUtilsTest.java | 20 ++++---- .../rpc/client/PinpointClientFactoryTest.java | 21 ++++---- .../rpc/server/PipelineFactoryTest.java | 8 +--- .../pinpoint/web/util/DateLimiterTest.java | 25 ++++------ .../pinpoint/web/util/LimitUtilsTest.java | 7 +-- .../pinpoint/web/util/TimeWindowTest.java | 14 +++--- 34 files changed, 162 insertions(+), 306 deletions(-) diff --git a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/ParallelClassLoaderTest.java b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/ParallelClassLoaderTest.java index 07ca93d052ab..756499ea2be6 100644 --- a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/ParallelClassLoaderTest.java +++ b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/ParallelClassLoaderTest.java @@ -47,11 +47,9 @@ private ClassLoader onLoadTest(Class classLoaderType, Class testClass) thr ClassLoader cl = PinpointClassLoaderFactory.createClassLoader(this.getClass().getName(), urls, null, ProfilerLibs.PINPOINT_PROFILER_CLASS); Assertions.assertSame(cl.getClass(), classLoaderType); - try { + Assertions.assertThrowsExactly(ClassNotFoundException.class, () -> { cl.loadClass("test"); - Assertions.fail(); - } catch (ClassNotFoundException ignored) { - } + }); Class selfLoadClass = cl.loadClass(testClass.getName()); Assertions.assertNotSame(testClass, selfLoadClass); @@ -61,7 +59,6 @@ private ClassLoader onLoadTest(Class classLoaderType, Class testClass) thr } - @Test public void testBootstrapClassLoader() throws Exception { ClassLoader classLoader = new ParallelClassLoader(this.getClass().getName(), new URL[0], null, ProfilerLibs.PINPOINT_PROFILER_CLASS); diff --git a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderTest.java b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderTest.java index e9a88c1cfe99..08da51992e97 100644 --- a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderTest.java +++ b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/classloader/PinpointClassLoaderTest.java @@ -45,11 +45,9 @@ private ClassLoader onLoadTest(Class classLoaderType, Class testClass) thr ClassLoader cl = PinpointClassLoaderFactory.createClassLoader(this.getClass().getName(), urls, null, ProfilerLibs.PINPOINT_PROFILER_CLASS); Assertions.assertSame(cl.getClass(), classLoaderType); - try { + Assertions.assertThrowsExactly(ClassNotFoundException.class, () -> { cl.loadClass("test"); - Assertions.fail(); - } catch (ClassNotFoundException ignored) { - } + }); Class selfLoadClass = cl.loadClass(testClass.getName()); Assertions.assertNotSame(testClass, selfLoadClass); diff --git a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/DumpTypeTest.java b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/DumpTypeTest.java index e36cd6fb03eb..15d06e610212 100644 --- a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/DumpTypeTest.java +++ b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/config/DumpTypeTest.java @@ -31,12 +31,8 @@ public class DumpTypeTest { public void find() { DumpType none = DumpType.valueOf("ALWAYS"); logger.debug("type:{}", none); - - try { + Assertions.assertThrows(Exception.class, () -> { DumpType.valueOf("error"); - Assertions.fail("not found"); - } catch (IllegalArgumentException ignored) { - - } + }); } } diff --git a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/DefaultInterceptorRegistryAdaptorTest.java b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/DefaultInterceptorRegistryAdaptorTest.java index 6644b952b02a..1a8aff021b85 100644 --- a/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/DefaultInterceptorRegistryAdaptorTest.java +++ b/bootstraps/bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/interceptor/DefaultInterceptorRegistryAdaptorTest.java @@ -12,34 +12,29 @@ public class DefaultInterceptorRegistryAdaptorTest { @Test public void indexSize_0() { - try { + Assertions.assertThrows(IllegalArgumentException.class, () -> { new DefaultInterceptorRegistryAdaptor(-1); - Assertions.fail(); - } catch (IllegalArgumentException ignored) { - } - + }); } @Test public void indexSize_1() { - try { - InterceptorRegistryAdaptor interceptorRegistry = new DefaultInterceptorRegistryAdaptor(0); - StaticAroundInterceptor mock = mock(StaticAroundInterceptor.class); + InterceptorRegistryAdaptor interceptorRegistry = new DefaultInterceptorRegistryAdaptor(0); + StaticAroundInterceptor mock = mock(StaticAroundInterceptor.class); + + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { interceptorRegistry.addInterceptor(mock); - Assertions.fail(); - } catch (IndexOutOfBoundsException ignored) { - } + }); } @Test public void indexSize_2() { InterceptorRegistryAdaptor interceptorRegistry = new DefaultInterceptorRegistryAdaptor(1); interceptorRegistry.addInterceptor(mock(StaticAroundInterceptor.class)); - try { + + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { interceptorRegistry.addInterceptor(mock(StaticAroundInterceptor.class)); - Assertions.fail(); - } catch (IndexOutOfBoundsException ignored) { - } + }); } @Test diff --git a/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoaderTest.java b/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoaderTest.java index 0fcdc11bfe79..43aacf5a01e5 100644 --- a/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoaderTest.java +++ b/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/Java9ClassLoaderTest.java @@ -60,11 +60,10 @@ private ClassLoader onLoadTest(Class classLoaderType, Class testClass) thr ClassLoader cl = PinpointClassLoaderFactory.createClassLoader(this.getClass().getName(), urls, null, ProfilerLibs.PINPOINT_PROFILER_CLASS); Assertions.assertSame(cl.getClass(), classLoaderType); - try { + Assertions.assertThrowsExactly(ClassNotFoundException.class, () -> { cl.loadClass("test"); - Assertions.fail(); - } catch (ClassNotFoundException ignored) { - } + }); + Class selfLoadClass = cl.loadClass(testClass.getName()); Assertions.assertNotSame(testClass, selfLoadClass); diff --git a/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/PlatformClassLoaderTest.java b/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/PlatformClassLoaderTest.java index 7364c2e88ddd..65632eb3f8eb 100644 --- a/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/PlatformClassLoaderTest.java +++ b/bootstraps/bootstrap-java9/src/test/java/com/navercorp/pinpoint/bootstrap/java9/classloader/PlatformClassLoaderTest.java @@ -42,13 +42,10 @@ public void sqlDate() throws ClassNotFoundException { logger.debug("sqlDate classLoader:{}", java.sql.Date.class.getClassLoader()); Class.forName("java.sql.Date", false, ClassLoader.getPlatformClassLoader()); - try { + Assertions.assertThrowsExactly(ClassNotFoundException.class, () -> { ClassLoader bootStrap = Object.class.getClassLoader(); Class.forName("java.sql.Date", false, bootStrap); - Assertions.fail(); - } catch (ClassNotFoundException e) { - // skip - } + }); } @Disabled diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/thrift/udp/UDPReceiverTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/thrift/udp/UDPReceiverTest.java index 373a9a44a3f8..8bf0b9cda747 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/thrift/udp/UDPReceiverTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/receiver/thrift/udp/UDPReceiverTest.java @@ -85,7 +85,7 @@ public void startStop() { receiver = new UDPReceiver("test", packetHandlerFactory, executor, 8, bindAddress, socketOptionApplier, pool); } catch (Exception e) { logger.debug(e.getMessage(), e); - Assertions.fail(e.getMessage()); + Assertions.fail(e.getMessage(), e); } finally { if (receiver != null) { receiver.shutdown(); @@ -160,7 +160,7 @@ boolean validatePacket(DatagramPacket packet) { Mockito.verify(mockExecutor).execute(any(Runnable.class)); } catch (Exception e) { logger.debug(e.getMessage(), e); - Assertions.fail(e.getMessage()); + Assertions.fail(e.getMessage(), e); } finally { if (receiver != null) { receiver.shutdown(); diff --git a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java index 148be21ec7fd..23d389668f59 100644 --- a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java +++ b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/AutomaticBufferTest.java @@ -69,18 +69,14 @@ public void testPadBytes() { public void testPadBytes_Error() { Buffer buffer1_1 = new AutomaticBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_1.putPadBytes(new byte[11], 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer1_2 = new AutomaticBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_2.putPadBytes(new byte[20], 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer2 = new AutomaticBuffer(32); buffer2.putPadBytes(new byte[10], 10); @@ -118,18 +114,14 @@ public void testPadString() { public void testPadString_Error() { Buffer buffer1_1 = new AutomaticBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_1.putPadString(StringUtils.repeat("a", 11), 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer1_2 = new AutomaticBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_2.putPadString(StringUtils.repeat("a", 20), 10); - Assertions.fail("error"); - } catch (Exception ignored) { - } + }); Buffer buffer2 = new AutomaticBuffer(32); buffer2.putPadString(StringUtils.repeat("a", 10), 10); @@ -151,12 +143,10 @@ public void testPut2PrefixedBytes() { checkPut2PrefixedBytes(null); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { byte[] bytes4 = new byte[Short.MAX_VALUE + 1]; checkPut2PrefixedBytes(bytes4); - Assertions.fail("too large bytes"); - } catch (IndexOutOfBoundsException ignored) { - } + }); } private void checkPut2PrefixedBytes(byte[] bytes) { diff --git a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/FixedBufferTest.java b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/FixedBufferTest.java index 797502c75a97..3d31ff32ba9d 100644 --- a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/FixedBufferTest.java +++ b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/FixedBufferTest.java @@ -105,18 +105,14 @@ public void readPadBytes() { public void testPadBytes_Error() { Buffer buffer1_1 = new FixedBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_1.putPadBytes(new byte[11], 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer1_2 = new FixedBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_2.putPadBytes(new byte[20], 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer2 = new FixedBuffer(32); buffer2.putPadBytes(new byte[10], 10); @@ -124,7 +120,7 @@ public void testPadBytes_Error() { } @Test - public void testPadString() throws Exception { + public void testPadString() { int TOTAL_LENGTH = 20; int TEST_SIZE = 10; int PAD_SIZE = TOTAL_LENGTH - TEST_SIZE; @@ -178,17 +174,15 @@ public void readPadStringAndRightTrim() { public void testPadString_Error() { Buffer buffer1_1 = new FixedBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_1.putPadString(StringUtils.repeat("a", 11), 10); - } catch (IndexOutOfBoundsException ignored) { - } + }); + Buffer buffer1_2 = new FixedBuffer(32); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { buffer1_2.putPadString(StringUtils.repeat("a", 20), 10); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); Buffer buffer2 = new FixedBuffer(32); buffer2.putPadString(StringUtils.repeat("a", 10), 10); @@ -206,12 +200,10 @@ public void testPut2PrefixedBytes() { byte[] bytes = new byte[Short.MAX_VALUE]; checkPut2PrefixedBytes(BytesUtils.toString(bytes), endExpected, Short.MAX_VALUE * 2); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { byte[] bytes2 = new byte[Short.MAX_VALUE + 1]; checkPut2PrefixedBytes(BytesUtils.toString(bytes2), endExpected, Short.MAX_VALUE * 2); - Assertions.fail("too large bytes"); - } catch (IndexOutOfBoundsException ignored) { - } + }); } @@ -468,11 +460,9 @@ public void find_SVLong_errorCode() { public void readVInt_errorCase() { byte[] errorCode = new byte[]{-118, -41, -17, -117, -81, -115, -64, -64, -108, -88}; Buffer buffer = new FixedBuffer(errorCode); - try { + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { buffer.readVInt(); - Assertions.fail("invalid VInt"); - } catch (IllegalArgumentException ignored) { - } + }); Assertions.assertEquals(0, buffer.getOffset()); } @@ -481,11 +471,9 @@ public void readVInt_errorCase() { public void readVLong_errorCase() { byte[] errorCode = new byte[]{-25, -45, -47, -14, -16, -104, -53, -48, -72, -9}; Buffer buffer = new FixedBuffer(errorCode); - try { + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { buffer.readVLong(); - Assertions.fail("invalid VLong"); - } catch (IllegalArgumentException ignored) { - } + }); Assertions.assertEquals(0, buffer.getOffset()); } @@ -607,10 +595,10 @@ public void testBoolean() { Buffer read = new FixedBuffer(buffer.getBuffer()); boolean b = read.readBoolean(); - Assertions.assertEquals(true, b); + Assertions.assertTrue(b); boolean c = read.readBoolean(); - Assertions.assertEquals(false, c); + Assertions.assertFalse(c); } @Test diff --git a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/OffsetFixedBufferTest.java b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/OffsetFixedBufferTest.java index 8b0933185b6a..519f84a85616 100644 --- a/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/OffsetFixedBufferTest.java +++ b/commons-buffer/src/test/java/com/navercorp/pinpoint/common/buffer/OffsetFixedBufferTest.java @@ -32,25 +32,20 @@ public class OffsetFixedBufferTest { @Test public void testFixedBuffer() { new OffsetFixedBuffer(new byte[10], 10, 0); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { new OffsetFixedBuffer(new byte[10], 11, 0); - Assertions.fail(); - } catch (IndexOutOfBoundsException ignored) { - } - try { + }); + + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { new OffsetFixedBuffer(new byte[10], -1, 0); - Assertions.fail(); - } catch (IndexOutOfBoundsException ignored) { - } + }); } @Test public void testFixedBuffer_length() { - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { new OffsetFixedBuffer(new byte[10], 0, 11); - Assertions.fail(); - } catch (IndexOutOfBoundsException e) { - } + }); new OffsetFixedBuffer(new byte[10], 0, 10); diff --git a/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/util/HbaseTableNameCacheTest.java b/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/util/HbaseTableNameCacheTest.java index ad28809fbf18..ee60a3e53c6e 100644 --- a/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/util/HbaseTableNameCacheTest.java +++ b/commons-hbase/src/test/java/com/navercorp/pinpoint/common/hbase/util/HbaseTableNameCacheTest.java @@ -62,12 +62,7 @@ public void specifiedNamespace() { @Test public void nullQualifierShouldThrowException() { Assertions.assertThrows(NullPointerException.class, () -> { - // Given - final String nullQualifier = null; - // When - cache.get(nullQualifier); - // Then - Assertions.fail(); + cache.get(null); }); } } diff --git a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoaderTest.java b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoaderTest.java index 6792a8fd83f6..f7f60ec2f044 100644 --- a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoaderTest.java +++ b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoaderTest.java @@ -120,11 +120,9 @@ public void unregisteredAnnotationKeyTest() { verifyAnnotationKey(annotationKeyRegistry, registeredAnnotationKey); Assertions.assertSame(AnnotationKey.UNKNOWN, annotationKeyRegistry.findAnnotationKey(unregisteredAnnotationKey.getCode())); - try { + Assertions.assertThrowsExactly(NoSuchElementException.class, () -> { annotationKeyRegistry.findAnnotationKeyByName(unregisteredAnnotationKey.getName()); - Assertions.fail(); - } catch (NoSuchElementException expected) { - } + }); } @Test @@ -156,11 +154,9 @@ private void verifyServiceType(ServiceTypeRegistry serviceTypeRegistry, ServiceT } } Assertions.assertTrue(found); - try { + Assertions.assertThrows(Exception.class, () -> { descMatchedServiceTypes.add(serviceType); - Assertions.fail("Adding to unmodifiable list should have failed"); - } catch (Exception expected) { - } + }, "Adding to unmodifiable list should have failed"); } } diff --git a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataRegistrarTest.java b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataRegistrarTest.java index dc35185d42bb..f0e000dde782 100644 --- a/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataRegistrarTest.java +++ b/commons-profiler/src/test/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataRegistrarTest.java @@ -42,16 +42,13 @@ public void undefinedServiceTypeShouldThrowException() { when(serviceTypeRegistry.findServiceTypeByName(unknownServiceType.getName())).thenReturn(unknownServiceType); TraceMetadataRegistrar.registerServiceTypes(serviceTypeRegistry); - try { + + Assertions.assertThrowsExactly(IllegalStateException.class, () -> { ServiceTypeProvider.getByCode(unknownServiceType.getCode()); - Assertions.fail("Retrieving UNDEFINED ServiceType by code should throw IllegalStateException"); - } catch (IllegalStateException expected1) { - try { - ServiceTypeProvider.getByName(unknownServiceType.getName()); - Assertions.fail("Retrieving UNDEFINED ServiceType by name should throw IllegalStateException"); - } catch (IllegalStateException expected2) { - } - } + }, "Retrieving UNDEFINED ServiceType by code should throw IllegalStateException"); + Assertions.assertThrowsExactly(IllegalStateException.class, () -> { + ServiceTypeProvider.getByName(unknownServiceType.getName()); + }, "Retrieving UNDEFINED ServiceType by name should throw IllegalStateException"); } @Test @@ -78,11 +75,10 @@ public void unknownAnnotationKeyShouldThrowException() { when(annotationKeyRegistry.findAnnotationKey(unknownAnnotationKey.getCode())).thenReturn(unknownAnnotationKey); TraceMetadataRegistrar.registerAnnotationKeys(annotationKeyRegistry); - try { + + Assertions.assertThrowsExactly(IllegalStateException.class, () -> { AnnotationKeyProvider.getByCode(unknownAnnotationKey.getCode()); - Assertions.fail("Retrieving UNKNOWN AnnotationKey should throw IllegalStateException"); - } catch (IllegalStateException expected) { - } + }, "Retrieving UNKNOWN AnnotationKey should throw IllegalStateException"); } @Test diff --git a/commons-server-cluster/src/test/java/com/navercorp/pinpoint/common/server/cluster/zookeeper/CuratorZookeeperClientTest.java b/commons-server-cluster/src/test/java/com/navercorp/pinpoint/common/server/cluster/zookeeper/CuratorZookeeperClientTest.java index a76a7b3d9f56..a39dc7e9e276 100644 --- a/commons-server-cluster/src/test/java/com/navercorp/pinpoint/common/server/cluster/zookeeper/CuratorZookeeperClientTest.java +++ b/commons-server-cluster/src/test/java/com/navercorp/pinpoint/common/server/cluster/zookeeper/CuratorZookeeperClientTest.java @@ -99,7 +99,7 @@ public static void tearDownClass() throws Exception { if (curatorZookeeperClient != null) { curatorZookeeperClient.close(); } - } catch (Exception e) { + } catch (Exception ignore) { // skip } @@ -141,11 +141,9 @@ public void createOrSetNodeTest() throws Exception { ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(testNodePath); String path = pathAndNode.getPath(); - try { + Assertions.assertThrows(Exception.class, () -> { curatorZookeeperClient.createOrSetNode(new CreateNodeMessage(testNodePath, message.getBytes())); - Assertions.fail(); - } catch (Exception ignored) { - } + }); boolean existNode = isExistNode(zooKeeper, path); Assertions.assertFalse(existNode); @@ -165,7 +163,7 @@ public void createOrSetNodeTest() throws Exception { } @Test - public void alreadyExistNodeCreateTest() throws Exception { + public void alreadyExistNodeCreateTest() { Assertions.assertThrows(BadOperationException.class, () -> { ZooKeeper zooKeeper = createZookeeper(); try { diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/filter/SequenceSpanEventFilterTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/filter/SequenceSpanEventFilterTest.java index 1f3bc1d57ce0..dd122e135e1e 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/filter/SequenceSpanEventFilterTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/filter/SequenceSpanEventFilterTest.java @@ -52,12 +52,9 @@ public void testFilter_reject() { public void testFilter_max() { new SequenceSpanEventFilter(Short.MAX_VALUE); - try { + Assertions.assertThrows(Exception.class, () -> { new SequenceSpanEventFilter(Short.MAX_VALUE + 1); - Assertions.fail(); - } catch (Exception e) { - } - + }); } } \ No newline at end of file diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/agent/ApplicationNameRowKeyEncoderTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/agent/ApplicationNameRowKeyEncoderTest.java index efe7ad8e47c3..3fa12ff2489a 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/agent/ApplicationNameRowKeyEncoderTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/bo/serializer/agent/ApplicationNameRowKeyEncoderTest.java @@ -11,12 +11,6 @@ public class ApplicationNameRowKeyEncoderTest { - @Test - public void app() { - - } - - @Test public void testGetTraceIndexRowKeyWhiteSpace() { String applicationName = "test test"; @@ -33,10 +27,7 @@ public void testGetTraceIndexRowKey1() { @Test public void testGetTraceIndexRowKey2() { - String applicationName = ""; - for (int i = 0; i < PinpointConstants.APPLICATION_NAME_MAX_LEN; i++) { - applicationName += "1"; - } + final String applicationName = "1".repeat(PinpointConstants.APPLICATION_NAME_MAX_LEN); long time = System.currentTimeMillis(); check(applicationName, time); @@ -44,17 +35,12 @@ public void testGetTraceIndexRowKey2() { @Test public void testGetTraceIndexRowKey3() { - String applicationName = ""; - for (int i = 0; i < PinpointConstants.APPLICATION_NAME_MAX_LEN + 1; i++) { - applicationName += "1"; - } + final String applicationName = "1".repeat(PinpointConstants.APPLICATION_NAME_MAX_LEN + 1); - long time = System.currentTimeMillis(); - try { + Assertions.assertThrowsExactly(IndexOutOfBoundsException.class, () -> { + long time = System.currentTimeMillis(); check(applicationName, time); - Assertions.fail("error"); - } catch (IndexOutOfBoundsException ignored) { - } + }); } private void check(String applicationName, long l1) { diff --git a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/time/RangeTest.java b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/time/RangeTest.java index fc11f5a7c123..894c2a638c9d 100644 --- a/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/time/RangeTest.java +++ b/commons-server/src/test/java/com/navercorp/pinpoint/common/server/util/time/RangeTest.java @@ -35,11 +35,9 @@ public void testCreate() { Range range1 = Range.between(0, 0); Range range2 = Range.between(0, 1); - try { + Assertions.assertThrows(Exception.class, () -> { Range range3 = Range.between(0, -1); - Assertions.fail(); - } catch (Exception ignored) { - } + }); } @Test diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/util/ArrayUtilsTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/util/ArrayUtilsTest.java index 68fd40a68189..1d285ae3f604 100644 --- a/commons/src/test/java/com/navercorp/pinpoint/common/util/ArrayUtilsTest.java +++ b/commons/src/test/java/com/navercorp/pinpoint/common/util/ArrayUtilsTest.java @@ -83,11 +83,9 @@ public void abbreviateSingle() { public void abbreviateNegative() { byte[] bytes = new byte[]{1}; - try { + Assertions.assertThrows(Exception.class, () -> { ArrayUtils.abbreviate(bytes, -1); - Assertions.fail(); - } catch (Exception ignored) { - } + }); } @Test diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/util/ByteSizeUnitTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/util/ByteSizeUnitTest.java index d3687b2a3b56..23c053e21dfd 100644 --- a/commons/src/test/java/com/navercorp/pinpoint/common/util/ByteSizeUnitTest.java +++ b/commons/src/test/java/com/navercorp/pinpoint/common/util/ByteSizeUnitTest.java @@ -136,11 +136,9 @@ public void expectedThrowExceptionTest() { } private void expectedThrowExceptionTest(String value) { - try { + Assertions.assertThrows(Exception.class, () -> { ByteSizeUnit.getByteSize(value); - Assertions.fail(value); - } catch (Exception ignore) { - } + }); } diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/util/IdValidateUtilsTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/util/IdValidateUtilsTest.java index 97cbd0b537a8..8b771a9b51c6 100644 --- a/commons/src/test/java/com/navercorp/pinpoint/common/util/IdValidateUtilsTest.java +++ b/commons/src/test/java/com/navercorp/pinpoint/common/util/IdValidateUtilsTest.java @@ -57,11 +57,9 @@ public void testValidateId_custom_max_length() { Assertions.assertFalse(IdValidateUtils.validateId("0123", 2), "check max length"); - try { + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { IdValidateUtils.validateId("0123", -1); - Assertions.fail(); - } catch (IllegalArgumentException ignored) { - } + }); } @Test diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/util/StringUtilsTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/util/StringUtilsTest.java index 08d4d7da1a17..35fc8ea54513 100644 --- a/commons/src/test/java/com/navercorp/pinpoint/common/util/StringUtilsTest.java +++ b/commons/src/test/java/com/navercorp/pinpoint/common/util/StringUtilsTest.java @@ -71,24 +71,18 @@ public void abbreviate() { Assertions.assertEquals(StringUtils.abbreviate(longString), "This is a very long string for testing drop function. Length of ...(100)"); Assertions.assertEquals(StringUtils.abbreviate(longString, 4), "This...(100)"); Assertions.assertEquals(StringUtils.abbreviate(longString, 0), "...(100)"); - try { + + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { StringUtils.abbreviate(longString, -4); - Assertions.fail(); - } catch (IllegalArgumentException ignored) { - } catch (Exception e) { - Assertions.fail(); - } + }); Assertions.assertEquals(StringUtils.abbreviate(shortString), shortString); Assertions.assertEquals(StringUtils.abbreviate(shortString, 4), "This...(22)"); Assertions.assertEquals(StringUtils.abbreviate(shortString, 0), "...(22)"); - try { + + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { StringUtils.abbreviate(shortString, -4); - Assertions.fail(); - } catch (IllegalArgumentException ignored) { - } catch (Exception e) { - Assertions.fail(); - } + }); } @Test diff --git a/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImplTest.java b/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImplTest.java index 16bbb0c34fd9..dfe65c5c0bc1 100644 --- a/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImplTest.java +++ b/metric-module/metric/src/test/java/com/navercorp/pinpoint/metric/web/service/SystemMetricHostInfoServiceImplTest.java @@ -3,12 +3,13 @@ import com.navercorp.pinpoint.metric.common.model.Tag; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author minwoo.jung */ @@ -22,11 +23,6 @@ public void test() { List comparedTagList = new ArrayList<>(); - if (tagList.containsAll(comparedTagList)) { - logger.debug("success"); - } else { - Assertions.fail(); - } - + assertThat(tagList).containsAll(comparedTagList); } } \ No newline at end of file diff --git a/plugins/oracle-jdbc/src/test/java/com/navercorp/pinpoint/plugin/jdbc/oracle/parser/OracleNetConnectionDescriptorParserTest.java b/plugins/oracle-jdbc/src/test/java/com/navercorp/pinpoint/plugin/jdbc/oracle/parser/OracleNetConnectionDescriptorParserTest.java index d99caea5b938..ef1586dbc662 100644 --- a/plugins/oracle-jdbc/src/test/java/com/navercorp/pinpoint/plugin/jdbc/oracle/parser/OracleNetConnectionDescriptorParserTest.java +++ b/plugins/oracle-jdbc/src/test/java/com/navercorp/pinpoint/plugin/jdbc/oracle/parser/OracleNetConnectionDescriptorParserTest.java @@ -173,14 +173,9 @@ public void parseEofError() { " ( CONNECT_DATA = ( SID = sid ) ) "; OracleNetConnectionDescriptorParser parser = new OracleNetConnectionDescriptorParser(rac); - try { - KeyValue keyValue = parser.parse(); - Assertions.fail(); - } catch (OracleConnectionStringException e) { - logger.info("Expected error", e); - } - - + Assertions.assertThrowsExactly(OracleConnectionStringException.class, () -> { + parser.parse(); + }); } @@ -191,12 +186,9 @@ public void parseSyntaxError() { " ( CONNECT_DATA = ( SID = sid ) ) )"; OracleNetConnectionDescriptorParser parser = new OracleNetConnectionDescriptorParser(rac); - try { - KeyValue keyValue = parser.parse(); - Assertions.fail(); - } catch (OracleConnectionStringException e) { - logger.info("Expected error", e); - } + Assertions.assertThrowsExactly(OracleConnectionStringException.class, () -> { + parser.parse(); + }); } @Test @@ -207,12 +199,9 @@ public void parseSyntaxError2() { // removed port OracleNetConnectionDescriptorParser parser = new OracleNetConnectionDescriptorParser(rac); - try { - KeyValue keyValue = parser.parse(); - Assertions.fail(); - } catch (OracleConnectionStringException e) { - logger.info("Expected error", e); - } + Assertions.assertThrowsExactly(OracleConnectionStringException.class, () -> { + parser.parse(); + }); } } diff --git a/profiler-optional/profiler-optional-jdk9/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/Java9DefineClassTest.java b/profiler-optional/profiler-optional-jdk9/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/Java9DefineClassTest.java index 292ff022982d..bbe05185c744 100644 --- a/profiler-optional/profiler-optional-jdk9/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/Java9DefineClassTest.java +++ b/profiler-optional/profiler-optional-jdk9/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/Java9DefineClassTest.java @@ -45,11 +45,9 @@ public void defineClass() throws ClassNotFoundException, IOException { URL[] empty = {}; URLClassLoader classLoader = new URLClassLoader(empty, null); - try { + Assertions.assertThrowsExactly(ClassNotFoundException.class, () -> { classLoader.loadClass(Logger.class.getName()); - Assertions.fail(); - } catch (ClassNotFoundException ignored) { - } + }); String className = JavaAssistUtils.javaClassNameToJvmResourceName(Logger.class.getName()); InputStream classStream = Logger.class.getClassLoader().getResourceAsStream(className); diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/PlainClassLoaderHandlerTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/PlainClassLoaderHandlerTest.java index c68ff9e090b8..e7df6f3eae43 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/PlainClassLoaderHandlerTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/instrument/classloading/PlainClassLoaderHandlerTest.java @@ -37,14 +37,9 @@ public void injectClass_bootstrapClass() { PluginConfig pluginConfig = newPluginConfig(); ClassInjector plainClassLoaderHandler = new PlainClassLoaderHandler(pluginConfig); - try { + Assertions.assertThrows(Exception.class, () -> { plainClassLoaderHandler.injectClass(this.getClass().getClassLoader(), "com.navercorp.pinpoint.bootstrap.Test"); - Assertions.fail(); - } catch (NullPointerException e) { - Assertions.fail(); - } catch (Exception e) { - - } + }); } // @Test diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/metric/rpc/test/MetricRegistryTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/metric/rpc/test/MetricRegistryTest.java index 8437ea45d994..d158691233cb 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/metric/rpc/test/MetricRegistryTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/monitor/metric/rpc/test/MetricRegistryTest.java @@ -38,20 +38,14 @@ public void testSuccess() { @Test public void testFalse() { - MetricRegistry metricRegistry = null; - try { - metricRegistry = new MetricRegistry(ServiceType.UNKNOWN_DB); - Assertions.fail(); - } catch (Exception ignored) { - } - - metricRegistry = new MetricRegistry(ServiceType.STAND_ALONE); - try { - metricRegistry.getRpcMetric(ServiceType.ASYNC); - Assertions.fail(); - } catch (Exception ignored) { - } + Assertions.assertThrows(Exception.class, () -> { + new MetricRegistry(ServiceType.UNKNOWN_DB); + }); + Assertions.assertThrows(Exception.class, () -> { + MetricRegistry metricRegistry = new MetricRegistry(ServiceType.STAND_ALONE); + metricRegistry.getRpcMetric(ServiceType.ASYNC); + }); } } \ No newline at end of file diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java index e38c5d2b82c2..ed567ab4db00 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/sender/UdpSocketTest.java @@ -92,11 +92,9 @@ public void testChunkSize() throws IOException { public void testDatagramSendFail() { int size = 70000; DatagramPacket packet1 = newDatagramPacket(size); - try { + Assertions.assertThrowsExactly(IOException.class, () -> { sender.send(packet1); - Assertions.fail("expected fail, but succeed"); - } catch (IOException ignored) { - } + }); } @Test diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/transformer/DynamicTransformServiceTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/transformer/DynamicTransformServiceTest.java index ee06dede95bf..76f7b150a03b 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/transformer/DynamicTransformServiceTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/transformer/DynamicTransformServiceTest.java @@ -24,6 +24,7 @@ import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; import java.lang.instrument.UnmodifiableClassException; +import java.time.Instant; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doAnswer; @@ -53,11 +54,10 @@ public Void answer(InvocationOnMock invocation) throws Throwable { DynamicTransformService dynamicTransformService = new DynamicTransformService(instrumentation, listener); - try { + Assertions.assertThrows(Exception.class, () -> { dynamicTransformService.retransform(String.class, classFileTransformer); - Assertions.fail("expected retransform fail"); - } catch (Exception e) { - } + }); + Assertions.assertEquals(listener.size(), 0); } diff --git a/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/JavaAssistUtilsTest.java b/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/JavaAssistUtilsTest.java index 0d6222992a39..08b94b161308 100644 --- a/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/JavaAssistUtilsTest.java +++ b/profiler/src/test/java/com/navercorp/pinpoint/profiler/util/JavaAssistUtilsTest.java @@ -71,7 +71,7 @@ public void javaClassNameToObjectName() { // classes Assertions.assertEquals("java.util.List", JavaAssistUtils.javaClassNameToObjectName(List.class.getName())); - Assertions.assertEquals("java.util.ArrayList", JavaAssistUtils.javaClassNameToObjectName(new ArrayList().getClass().getName())); + Assertions.assertEquals("java.util.ArrayList", JavaAssistUtils.javaClassNameToObjectName(ArrayList.class.getName())); // arrays Assertions.assertEquals("boolean[]", JavaAssistUtils.javaClassNameToObjectName(boolean[].class.getName())); @@ -99,7 +99,7 @@ public int compareTo(Long o) { JavaAssistUtils.javaClassNameToObjectName(inner.getClass().getName())); // assume nothing else is defined in this class Assertions.assertEquals( this.getClass().getName() + "$1SomeComparable[]", - JavaAssistUtils.javaClassNameToObjectName(new SomeComparable[]{inner}.getClass().getName())); + JavaAssistUtils.javaClassNameToObjectName(SomeComparable[].class.getName())); Assertions.assertEquals("java.util.Map$Entry", JavaAssistUtils.javaClassNameToObjectName(Map.Entry.class.getName())); Assertions.assertEquals("java.util.Map$Entry[]", JavaAssistUtils.javaClassNameToObjectName(Map.Entry[].class.getName())); } @@ -116,17 +116,13 @@ public void toJvmSignature() { Assertions.assertEquals(JavaAssistUtils.toJvmSignature("java.lang.String"), "Ljava/lang/String;"); Assertions.assertEquals(JavaAssistUtils.toJvmSignature("java.lang.String[][]"), "[[Ljava/lang/String;"); - try { - Assertions.assertEquals(JavaAssistUtils.toJvmSignature(""), ""); - Assertions.fail("empty string"); - } catch (Exception ignored) { - } + Assertions.assertThrows(Exception.class, () -> { + JavaAssistUtils.toJvmSignature(""); + }); - try { - Assertions.assertEquals(JavaAssistUtils.toJvmSignature(null), null); - Assertions.fail("null"); - } catch (Exception ignored) { - } + Assertions.assertThrows(Exception.class, () -> { + JavaAssistUtils.toJvmSignature(null); + }); } @Test diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java index 1a8046aa137d..9baf19e110e1 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/client/PinpointClientFactoryTest.java @@ -66,13 +66,10 @@ public static void tearDown() { @Test public void connectFail() { - try { + Assertions.assertThrowsExactly(PinpointSocketException.class, () -> { int availableTcpPort = SocketUtils.findAvailableTcpPort(47000); clientFactory.connect("127.0.0.1", availableTcpPort); - Assertions.fail(); - } catch (PinpointSocketException e) { - Assertions.assertTrue(ConnectException.class.isInstance(e.getCause())); - } + }); } @Test @@ -83,7 +80,7 @@ public void reconnectFail() throws InterruptedException { ChannelFuture reconnect = clientFactory.reconnect(remoteAddress); reconnect.await(); Assertions.assertFalse(reconnect.isSuccess()); - Assertions.assertTrue(ConnectException.class.isInstance(reconnect.getCause())); + Assertions.assertTrue(reconnect.getCause() instanceof ConnectException); Thread.sleep(1000); } @@ -102,7 +99,7 @@ public void connect() throws IOException, InterruptedException { } @Test - public void pingInternal() throws IOException, InterruptedException { + public void pingInternal() { TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true); final TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create(); @@ -142,7 +139,7 @@ public void ping() throws IOException, InterruptedException { } @Test - public void pingAndRequestResponse() throws IOException, InterruptedException { + public void pingAndRequestResponse() { TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX)); int bindPort = testPinpointServerAcceptor.bind(); @@ -160,7 +157,7 @@ public void pingAndRequestResponse() throws IOException, InterruptedException { } @Test - public void sendSync() throws IOException, InterruptedException { + public void sendSync() { TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(); int bindPort = testPinpointServerAcceptor.bind(); @@ -178,7 +175,7 @@ public void sendSync() throws IOException, InterruptedException { } @Test - public void requestAndResponse() throws IOException, InterruptedException { + public void requestAndResponse() { TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX)); int bindPort = testPinpointServerAcceptor.bind(); @@ -226,13 +223,13 @@ public void throwWriteBufferFullExceptionTest() { PinpointClient client = clientFactory.connect("127.0.0.1", bindPort); - List futureList = new ArrayList(); + List> futureList = new ArrayList<>(); for (int i = 0; i < 30; i++) { Future requestFuture = client.request(new byte[20]); futureList.add(requestFuture); } - for (Future future : futureList) { + for (Future future : futureList) { future.getResult(); } diff --git a/rpc/src/test/java/com/navercorp/pinpoint/rpc/server/PipelineFactoryTest.java b/rpc/src/test/java/com/navercorp/pinpoint/rpc/server/PipelineFactoryTest.java index d02ec2f0583c..10eb7461e819 100644 --- a/rpc/src/test/java/com/navercorp/pinpoint/rpc/server/PipelineFactoryTest.java +++ b/rpc/src/test/java/com/navercorp/pinpoint/rpc/server/PipelineFactoryTest.java @@ -72,13 +72,9 @@ public void testBind() throws Exception { socket.getOutputStream().write(('@' + "Test").getBytes()); socket.getOutputStream().flush(); - try { + Assertions.assertThrowsExactly(ConditionTimeoutException.class, () -> { assertMessageReceivedCount(2, discardServerHandler); - Assertions.fail(); - } catch (ConditionTimeoutException e) { - // ignore - } - + }); } finally { IOUtils.closeQuietly(socket); diff --git a/web/src/test/java/com/navercorp/pinpoint/web/util/DateLimiterTest.java b/web/src/test/java/com/navercorp/pinpoint/web/util/DateLimiterTest.java index 0648a1f3dd91..ff9d0f75dcf1 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/util/DateLimiterTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/util/DateLimiterTest.java @@ -55,33 +55,26 @@ public void checkRange() { @Test public void checkFail() { Limiter limiter = new DateLimiter(Duration.ofDays(2)); - try { + Assertions.assertThrows(Exception.class, () -> { limiter.limit(Instant.EPOCH, ofDays(2).plusMillis(1)); - Assertions.fail(); - } catch (Exception ignored) { - } + }); - try { + Assertions.assertThrows(Exception.class, () -> { limiter.limit(ofDays(2), Instant.EPOCH); - Assertions.fail(); - } catch (Exception ignored) { - } + }); } @Test public void checkRangeFail() { Limiter limiter = new DateLimiter(Duration.ofDays(2)); - try { + + Assertions.assertThrows(Exception.class, () -> { limiter.limit(Range.between(Instant.EPOCH, ofDays(2).plusMillis(1))); - Assertions.fail(); - } catch (Exception ignored) { - } + }); - try { + Assertions.assertThrows(Exception.class, () -> { limiter.limit(Range.between(ofDays(2), Instant.EPOCH)); - Assertions.fail(); - } catch (Exception ignored) { - } + }); } private Instant ofDays(long days) { diff --git a/web/src/test/java/com/navercorp/pinpoint/web/util/LimitUtilsTest.java b/web/src/test/java/com/navercorp/pinpoint/web/util/LimitUtilsTest.java index 8a3f06b8b9ba..6ddb3e8f743e 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/util/LimitUtilsTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/util/LimitUtilsTest.java @@ -34,11 +34,8 @@ public void testCheckLimit() { int low = LimitUtils.checkRange(0); Assertions.assertEquals(low, 0); - try { + Assertions.assertThrows(Exception.class, () -> { LimitUtils.checkRange(-1); - Assertions.fail(); - } catch (Exception ignored) { - } - + }); } } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/util/TimeWindowTest.java b/web/src/test/java/com/navercorp/pinpoint/web/util/TimeWindowTest.java index 50e1615fd59c..cee759cfc3d0 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/util/TimeWindowTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/util/TimeWindowTest.java @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.time.Instant; import java.util.Iterator; import java.util.concurrent.TimeUnit; @@ -38,22 +39,19 @@ public void testGetNextWindowFirst() { logger.debug("{}", window.getWindowRange()); Iterator iterator = window.iterator(); Assertions.assertEquals(iterator.next(), (Long)0L); - try { + + Assertions.assertThrows(Exception.class, () -> { iterator.next(); - Assertions.fail("no more element"); - } catch (Exception ignored) { - } + }); TimeWindow window2 = new TimeWindow(Range.between(0L, TimeUnit.MINUTES.toMillis(1))); logger.debug("{}", window2.getWindowRange()); Iterator iterator2 = window2.iterator(); Assertions.assertEquals(iterator2.next(), (Long)0L); Assertions.assertEquals(iterator2.next(), (Long)(1000*60L)); - try { + Assertions.assertThrows(Exception.class, () -> { iterator2.next(); - Assertions.fail("no more element"); - } catch (Exception ignored) { - } + }); } @Test