From d1c987026fe7d10331a0b369c5837189cc89d15f Mon Sep 17 00:00:00 2001 From: uhm0311 Date: Mon, 12 Aug 2024 16:26:01 +0900 Subject: [PATCH] TEST: Fix `java.net.spy.memcached.protocol.ascii.BaseOpTest` to ensure it tests correctly. --- .../memcached/protocol/ascii/BaseOpTest.java | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/test/java/net/spy/memcached/protocol/ascii/BaseOpTest.java b/src/test/java/net/spy/memcached/protocol/ascii/BaseOpTest.java index 573eed337..b409b71ae 100644 --- a/src/test/java/net/spy/memcached/protocol/ascii/BaseOpTest.java +++ b/src/test/java/net/spy/memcached/protocol/ascii/BaseOpTest.java @@ -27,44 +27,31 @@ import net.spy.memcached.compat.BaseMockCase; +import static org.junit.Assert.assertThrows; + /** * Test the basic operation buffer handling stuff. */ public class BaseOpTest extends BaseMockCase { public void testAssertions() { - try { - assert false; - fail("Assertions are not enabled."); - } catch (AssertionError e) { - // OK - } + assertThrows(AssertionError.class, () -> { assert false; }); } - public void testDataReadType() throws Exception { + public void testDataReadType() { SimpleOp op = new SimpleOp(OperationReadType.DATA); assertSame(OperationReadType.DATA, op.getReadType()); // Make sure lines aren't handled - try { - op.handleLine("x"); - fail("Handled a line in data mode"); - } catch (AssertionError e) { - // ok - } + assertThrows(AssertionError.class, () -> op.handleLine("x")); op.setBytesToRead(2); op.handleRead(ByteBuffer.wrap("hi".getBytes())); } - public void testLineReadType() throws Exception { + public void testLineReadType() { SimpleOp op = new SimpleOp(OperationReadType.LINE); assertSame(OperationReadType.LINE, op.getReadType()); // Make sure lines aren't handled - try { - op.handleRead(ByteBuffer.allocate(3)); - fail("Handled data in line mode"); - } catch (AssertionError e) { - // ok - } + assertThrows(AssertionError.class, () -> op.handleRead(ByteBuffer.allocate(3))); op.handleLine("x"); }