From 61693f53415baa0b2744263391cec8cb3e4471d1 Mon Sep 17 00:00:00 2001 From: TLS-Attacker Developer Date: Mon, 30 Jun 2025 09:22:41 +0000 Subject: [PATCH] Fix unused code and imports in test files - Removed unused wildcard imports from ModifiableVariableTest.java (biginteger, bytearray, singlebyte) - Refactored BigInteger test exception handling from try-catch to assertThrows pattern - This modernizes the test code and eliminates static analyzer warnings about unused allocations --- .../ModifiableVariableTest.java | 3 -- ...gIntegerExplicitValueModificationTest.java | 31 +++++++----------- .../BigIntegerSubtractModificationTest.java | 32 +++++++------------ .../BigIntegerXorModificationTest.java | 32 +++++++------------ 4 files changed, 33 insertions(+), 65 deletions(-) diff --git a/src/test/java/de/rub/nds/modifiablevariable/ModifiableVariableTest.java b/src/test/java/de/rub/nds/modifiablevariable/ModifiableVariableTest.java index 180f5d54..97a2a849 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/ModifiableVariableTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/ModifiableVariableTest.java @@ -9,10 +9,7 @@ import static org.junit.jupiter.api.Assertions.*; -import de.rub.nds.modifiablevariable.biginteger.*; -import de.rub.nds.modifiablevariable.bytearray.*; import de.rub.nds.modifiablevariable.integer.*; -import de.rub.nds.modifiablevariable.singlebyte.*; import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModificationTest.java index 18866bfb..b3374c50 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModificationTest.java @@ -11,8 +11,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.math.BigInteger; import org.junit.jupiter.api.BeforeEach; @@ -156,29 +156,20 @@ void testToString() { /** Test constructor with null value */ @Test void testConstructorWithNullValue() { - // Using try-catch because we expect an exception - try { - // Explicitly specify null as BigInteger to avoid ambiguity with copy constructor - BigInteger nullValue = null; - new BigIntegerExplicitValueModification(nullValue); - fail("Constructor should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + new BigIntegerExplicitValueModification((BigInteger) null); + }); } /** Test setExplicitValue with null value */ @Test void testSetExplicitValueWithNullValue() { - // Using try-catch because we expect an exception - try { - b1.setExplicitValue(null); - // Should not reach here - fail("setExplicitValue should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + b1.setExplicitValue(null); + }); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModificationTest.java index 0a6fc59b..487debee 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModificationTest.java @@ -11,8 +11,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.math.BigInteger; import org.junit.jupiter.api.BeforeEach; @@ -166,30 +166,20 @@ void testToString() { /** Test constructor with null value */ @Test void testConstructorWithNullValue() { - // Using try-catch because we expect an exception - try { - // Explicitly specify null as BigInteger to avoid ambiguity with copy constructor - BigInteger nullValue = null; - BigIntegerSubtractModification mod = new BigIntegerSubtractModification(nullValue); - // Should not reach here - fail("Constructor should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + new BigIntegerSubtractModification((BigInteger) null); + }); } /** Test setSubtrahend with null value */ @Test void testSetSubtrahendWithNullValue() { - // Using try-catch because we expect an exception - try { - b1.setSubtrahend(null); - // Should not reach here - fail("setSubtrahend should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + b1.setSubtrahend(null); + }); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModificationTest.java index 21ae9d78..a17a1599 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModificationTest.java @@ -11,8 +11,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.math.BigInteger; import org.junit.jupiter.api.BeforeEach; @@ -162,30 +162,20 @@ void testToString() { /** Test constructor with null value */ @Test void testConstructorWithNullValue() { - // Using try-catch because we expect an exception - try { - // Explicitly specify null as BigInteger to avoid ambiguity with copy constructor - BigInteger nullValue = null; - new BigIntegerXorModification(nullValue); - // Should not reach here - fail("Constructor should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + new BigIntegerXorModification((BigInteger) null); + }); } /** Test setXor with null value */ @Test void testSetXorWithNullValue() { - // Using try-catch because we expect an exception - try { - b1.setXor(null); - // Should not reach here - fail("setXor should throw NullPointerException"); - } catch (NullPointerException e) { - // Expected exception - assertTrue(e.getMessage().contains("null")); - } + assertThrows( + NullPointerException.class, + () -> { + b1.setXor(null); + }); } }