diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index ac739e83..712847bf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -38,6 +38,9 @@ public BigIntegerExplicitValueModification createCopy() { @Override protected BigInteger modifyImplementationHook(BigInteger input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java deleted file mode 100644 index ae4c835d..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.biginteger; - -import de.rub.nds.modifiablevariable.VariableModification; -import java.math.BigInteger; - -public final class BigIntegerModificationFactory { - - public static BigIntegerAddModification add(String summand) { - return add(new BigInteger(summand)); - } - - public static BigIntegerAddModification add(BigInteger summand) { - return new BigIntegerAddModification(summand); - } - - public static BigIntegerShiftLeftModification shiftLeft(String shift) { - return shiftLeft(Integer.parseInt(shift)); - } - - public static BigIntegerShiftLeftModification shiftLeft(Integer shift) { - return new BigIntegerShiftLeftModification(shift); - } - - public static BigIntegerShiftRightModification shiftRight(String shift) { - return shiftRight(Integer.parseInt(shift)); - } - - public static BigIntegerShiftRightModification shiftRight(Integer shift) { - return new BigIntegerShiftRightModification(shift); - } - - public static BigIntegerMultiplyModification multiply(BigInteger factor) { - return new BigIntegerMultiplyModification(factor); - } - - public static VariableModification sub(String subtrahend) { - return sub(new BigInteger(subtrahend)); - } - - public static VariableModification sub(BigInteger subtrahend) { - return new BigIntegerSubtractModification(subtrahend); - } - - public static VariableModification xor(String xor) { - return xor(new BigInteger(xor)); - } - - public static VariableModification xor(BigInteger xor) { - return new BigIntegerXorModification(xor); - } - - public static VariableModification explicitValue(String value) { - return explicitValue(new BigInteger(value)); - } - - public static VariableModification explicitValue(BigInteger value) { - return new BigIntegerExplicitValueModification(value); - } - - private BigIntegerModificationFactory() { - super(); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index e753535e..79416d75 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -36,6 +36,9 @@ public BooleanExplicitValueModification createCopy() { @Override protected Boolean modifyImplementationHook(Boolean input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java deleted file mode 100644 index f441e47d..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.bool; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class BooleanModificationFactory { - - private BooleanModificationFactory() { - super(); - } - - public static VariableModification toggle() { - return new BooleanToggleModification(); - } - - public static VariableModification explicitValue(boolean explicitValue) { - return new BooleanExplicitValueModification(explicitValue); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java index c6735377..cfd0c0ca 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java @@ -28,9 +28,6 @@ public BooleanToggleModification createCopy() { @Override protected Boolean modifyImplementationHook(Boolean input) { - if (input == null) { - input = Boolean.FALSE; - } return !input; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index 627d8e35..9317f237 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -41,10 +41,6 @@ public ByteArrayAppendValueModification createCopy() { @Override protected byte[] modifyImplementationHook(byte[] input) { - if (input == null) { - input = new byte[0]; - } - return ArrayConverter.concatenate(input, bytesToAppend); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 592ef978..10d70c67 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -42,9 +42,6 @@ public ByteArrayDeleteModification createCopy() { @Override protected byte[] modifyImplementationHook(byte[] input) { - if (input == null) { - input = new byte[0]; - } if (input.length == 0) { return input; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index e1a43b44..bba2ca8e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -41,6 +41,9 @@ public ByteArrayExplicitValueModification createCopy() { @Override protected byte[] modifyImplementationHook(byte[] input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue.clone(); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java deleted file mode 100644 index 4b9cc732..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.bytearray; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class ByteArrayModificationFactory { - - /** - * @param xor bytes to xor - * @param startPosition negative numbers mean that the position is taken from the end - * @return variable modification - */ - public static VariableModification xor(byte[] xor, int startPosition) { - return new ByteArrayXorModification(xor, startPosition); - } - - /** - * * - * - * @param bytesToInsert bytes to insert - * @param startPosition negative numbers mean that the position is taken from the end - * @return variable modification - */ - public static VariableModification insertValue( - byte[] bytesToInsert, int startPosition) { - return new ByteArrayInsertValueModification(bytesToInsert, startPosition); - } - - public static VariableModification appendValue(byte[] bytesToAppend) { - return new ByteArrayAppendValueModification(bytesToAppend); - } - - public static VariableModification prependValue(byte[] bytesToPrepend) { - return new ByteArrayPrependValueModification(bytesToPrepend); - } - - /** - * * Deletes $count bytes from the input array beginning at $startPosition - * - * @param startPosition negative numbers mean that the position is taken from the end - * @param count number of bytes to be deleted - * @return variable modification - */ - public static VariableModification delete(int startPosition, int count) { - return new ByteArrayDeleteModification(startPosition, count); - } - - /** - * Duplicates the byte array - * - * @return duplicate variable modification - */ - public static VariableModification duplicate() { - return new ByteArrayDuplicateModification(); - } - - public static VariableModification explicitValue(byte[] explicitValue) { - return new ByteArrayExplicitValueModification(explicitValue); - } - - /** - * Shuffles the bytes in the array, given a specified array of positions. - * - * @param shuffle positions that define shuffling - * @return shuffling variable modification - */ - public static VariableModification shuffle(byte[] shuffle) { - return new ByteArrayShuffleModification(shuffle); - } - - private ByteArrayModificationFactory() { - super(); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index b49e1269..f148a113 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -37,7 +37,7 @@ public IntegerAddModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? summand : input + summand; + return input + summand; } public Integer getSummand() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 412df62d..f98a06b8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -37,6 +37,9 @@ public IntegerExplicitValueModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java deleted file mode 100644 index 1a981b48..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.integer; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class IntegerModificationFactory { - - public static IntegerAddModification add(String summand) { - return add(Integer.parseInt(summand)); - } - - public static IntegerAddModification add(Integer summand) { - return new IntegerAddModification(summand); - } - - public static IntegerShiftLeftModification shiftLeft(String shift) { - return shiftLeft(Integer.parseInt(shift)); - } - - public static IntegerShiftLeftModification shiftLeft(Integer shift) { - return new IntegerShiftLeftModification(shift); - } - - public static IntegerShiftRightModification shiftRight(String shift) { - return shiftRight(Integer.parseInt(shift)); - } - - public static IntegerShiftRightModification shiftRight(Integer shift) { - return new IntegerShiftRightModification(shift); - } - - public static VariableModification sub(String subtrahend) { - return sub(Integer.parseInt(subtrahend)); - } - - public static VariableModification sub(Integer subtrahend) { - return new IntegerSubtractModification(subtrahend); - } - - public static VariableModification xor(String xor) { - return xor(Integer.parseInt(xor)); - } - - public static VariableModification xor(Integer xor) { - return new IntegerXorModification(xor); - } - - public static VariableModification swapEndian() { - return new IntegerSwapEndianModification(); - } - - public static VariableModification explicitValue(String value) { - return explicitValue(Integer.parseInt(value)); - } - - public static VariableModification explicitValue(Integer value) { - return new IntegerExplicitValueModification(value); - } - - public static VariableModification multiply(Integer value) { - return new IntegerMultiplyModification(value); - } - - private IntegerModificationFactory() { - super(); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index 9a853051..a3c1c72d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -37,7 +37,7 @@ public IntegerMultiplyModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? 0 : input * factor; + return input * factor; } public Integer getFactor() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index 0da27cb4..cd151156 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -38,7 +38,7 @@ public IntegerShiftLeftModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? 0 : input << shift % MAX_SHIFT_MODIFIER; + return input << shift % MAX_SHIFT_MODIFIER; } public int getShift() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index f50ccfd7..83e098f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -38,7 +38,7 @@ public IntegerShiftRightModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? 0 : input >> shift % MAX_SHIFT_MODIFIER; + return input >> shift % MAX_SHIFT_MODIFIER; } public int getShift() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index 12362f9f..67958e8c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -37,7 +37,7 @@ public IntegerSubtractModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? -subtrahend : input - subtrahend; + return input - subtrahend; } public Integer getSubtrahend() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java index 4a7fcdf7..91fde71c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java @@ -28,9 +28,6 @@ public IntegerSwapEndianModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - if (input == null) { - return null; - } return Integer.reverseBytes(input); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index ad86f199..30602bd4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -37,7 +37,7 @@ public IntegerXorModification createCopy() { @Override protected Integer modifyImplementationHook(Integer input) { - return input == null ? xor : input ^ xor; + return input ^ xor; } public Integer getXor() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index 0d5e0984..bb51c4ed 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -45,7 +45,11 @@ public void setAssertEquals(Integer assertEquals) { @Override public boolean isOriginalValueModified() { - return getOriginalValue() != null && getOriginalValue().compareTo(getValue()) != 0; + if (getOriginalValue() == null) { + throw new IllegalStateException("Original value must not be null"); + } else { + return getOriginalValue().compareTo(getValue()) != 0; + } } public byte[] getByteArray(int size) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index 9c7e6278..a09325d1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -37,7 +37,7 @@ public LongAddModification createCopy() { @Override protected Long modifyImplementationHook(Long input) { - return input == null ? summand : input + summand; + return input + summand; } public Long getSummand() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index 9914cd4c..2034142f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -37,6 +37,9 @@ public LongExplicitValueModification createCopy() { @Override protected Long modifyImplementationHook(Long input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java deleted file mode 100644 index e9cfc6e9..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.longint; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class LongModificationFactory { - - public static LongAddModification add(String summand) { - return add(Long.parseLong(summand)); - } - - public static LongAddModification add(Long summand) { - return new LongAddModification(summand); - } - - public static VariableModification sub(String subtrahend) { - return sub(Long.parseLong(subtrahend)); - } - - public static VariableModification sub(Long subtrahend) { - return new LongSubtractModification(subtrahend); - } - - public static VariableModification xor(String xor) { - return xor(Long.parseLong(xor)); - } - - public static VariableModification xor(Long xor) { - return new LongXorModification(xor); - } - - public static VariableModification swapEndian() { - return new LongSwapEndianModification(); - } - - public static VariableModification explicitValue(String value) { - return explicitValue(Long.parseLong(value)); - } - - public static VariableModification explicitValue(Long value) { - return new LongExplicitValueModification(value); - } - - public static VariableModification multiply(Long factor) { - return new LongMultiplyModification(factor); - } - - public static VariableModification shiftLeft(int shift) { - return new LongShiftLeftModification(shift); - } - - public static VariableModification shiftRight(int shift) { - return new LongShiftRightModification(shift); - } - - private LongModificationFactory() { - super(); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 64f7d5c9..c7ad1284 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -37,6 +37,9 @@ public ByteExplicitValueModification createCopy() { @Override protected Byte modifyImplementationHook(Byte input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java deleted file mode 100644 index 1bc2ba1f..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.singlebyte; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class ByteModificationFactory { - - public static ByteAddModification add(String summand) { - return add(Byte.parseByte(summand)); - } - - public static ByteAddModification add(Byte summand) { - return new ByteAddModification(summand); - } - - public static VariableModification sub(String subtrahend) { - return sub(Byte.parseByte(subtrahend)); - } - - public static VariableModification sub(Byte subtrahend) { - return new ByteSubtractModification(subtrahend); - } - - public static VariableModification xor(String xor) { - return xor(Byte.parseByte(xor)); - } - - public static VariableModification xor(Byte xor) { - return new ByteXorModification(xor); - } - - public static VariableModification explicitValue(String value) { - return explicitValue(Byte.parseByte(value)); - } - - public static VariableModification explicitValue(Byte value) { - return new ByteExplicitValueModification(value); - } - - private ByteModificationFactory() { - super(); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index 5c8d4ffb..764efc78 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -42,6 +42,9 @@ public StringExplicitValueModification createCopy() { @Override protected String modifyImplementationHook(String input) { + if (input == null) { + throw new NullPointerException("original value must not be null"); + } return explicitValue; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java deleted file mode 100644 index 8ccb345a..00000000 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ModifiableVariable - A Variable Concept for Runtime Modifications - * - * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH - * - * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 - */ -package de.rub.nds.modifiablevariable.string; - -import de.rub.nds.modifiablevariable.VariableModification; - -public final class StringModificationFactory { - - private StringModificationFactory() { - super(); - } - - public static VariableModification prependValue(String value) { - return new StringPrependValueModification(value); - } - - public static VariableModification appendValue(String value) { - return new StringAppendValueModification(value); - } - - public static VariableModification explicitValue(String value) { - return new StringExplicitValueModification(value); - } - - public static VariableModification insertValue(String value, int position) { - return new StringInsertValueModification(value, position); - } - - public static VariableModification delete(int startPosition, int count) { - return new StringDeleteModification(startPosition, count); - } -} diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index d5f1800a..4fbfb764 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -8,20 +8,54 @@ package de.rub.nds.modifiablevariable.util; import de.rub.nds.modifiablevariable.VariableModification; -import de.rub.nds.modifiablevariable.biginteger.BigIntegerModificationFactory; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerExplicitValueModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerMultiplyModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftLeftModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftRightModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification; +import de.rub.nds.modifiablevariable.biginteger.BigIntegerXorModification; import de.rub.nds.modifiablevariable.biginteger.ModifiableBigInteger; -import de.rub.nds.modifiablevariable.bool.BooleanModificationFactory; +import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification; +import de.rub.nds.modifiablevariable.bool.BooleanToggleModification; import de.rub.nds.modifiablevariable.bool.ModifiableBoolean; -import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayAppendValueModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayDeleteModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayDuplicateModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayExplicitValueModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayInsertValueModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayPrependValueModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayShuffleModification; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayXorModification; import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray; -import de.rub.nds.modifiablevariable.integer.IntegerModificationFactory; +import de.rub.nds.modifiablevariable.integer.IntegerAddModification; +import de.rub.nds.modifiablevariable.integer.IntegerExplicitValueModification; +import de.rub.nds.modifiablevariable.integer.IntegerMultiplyModification; +import de.rub.nds.modifiablevariable.integer.IntegerShiftLeftModification; +import de.rub.nds.modifiablevariable.integer.IntegerShiftRightModification; +import de.rub.nds.modifiablevariable.integer.IntegerSubtractModification; +import de.rub.nds.modifiablevariable.integer.IntegerSwapEndianModification; +import de.rub.nds.modifiablevariable.integer.IntegerXorModification; import de.rub.nds.modifiablevariable.integer.ModifiableInteger; -import de.rub.nds.modifiablevariable.longint.LongModificationFactory; +import de.rub.nds.modifiablevariable.longint.LongAddModification; +import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification; +import de.rub.nds.modifiablevariable.longint.LongMultiplyModification; +import de.rub.nds.modifiablevariable.longint.LongShiftLeftModification; +import de.rub.nds.modifiablevariable.longint.LongShiftRightModification; +import de.rub.nds.modifiablevariable.longint.LongSubtractModification; +import de.rub.nds.modifiablevariable.longint.LongSwapEndianModification; +import de.rub.nds.modifiablevariable.longint.LongXorModification; import de.rub.nds.modifiablevariable.longint.ModifiableLong; -import de.rub.nds.modifiablevariable.singlebyte.ByteModificationFactory; +import de.rub.nds.modifiablevariable.singlebyte.ByteAddModification; +import de.rub.nds.modifiablevariable.singlebyte.ByteExplicitValueModification; +import de.rub.nds.modifiablevariable.singlebyte.ByteSubtractModification; +import de.rub.nds.modifiablevariable.singlebyte.ByteXorModification; import de.rub.nds.modifiablevariable.singlebyte.ModifiableByte; import de.rub.nds.modifiablevariable.string.ModifiableString; -import de.rub.nds.modifiablevariable.string.StringModificationFactory; +import de.rub.nds.modifiablevariable.string.StringAppendValueModification; +import de.rub.nds.modifiablevariable.string.StringExplicitValueModification; +import de.rub.nds.modifiablevariable.string.StringInsertValueModification; +import de.rub.nds.modifiablevariable.string.StringPrependValueModification; import java.math.BigInteger; @SuppressWarnings("unused") @@ -82,185 +116,177 @@ private static ModifiableString getModifiableStringWithModification( public static ModifiableByteArray prepend(byte[] perpendValue) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.prependValue(perpendValue)); + new ByteArrayPrependValueModification(perpendValue)); } public static ModifiableString prepend(String perpendValue) { return getModifiableStringWithModification( - StringModificationFactory.prependValue(perpendValue)); + new StringPrependValueModification(perpendValue)); } public static ModifiableByteArray append(byte[] appendValue) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.appendValue(appendValue)); + new ByteArrayAppendValueModification(appendValue)); } public static ModifiableString append(String appendValue) { - return getModifiableStringWithModification( - StringModificationFactory.appendValue(appendValue)); + return getModifiableStringWithModification(new StringAppendValueModification(appendValue)); } public static ModifiableByteArray explicit(byte[] explicitValue) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.explicitValue(explicitValue)); + new ByteArrayExplicitValueModification(explicitValue)); } public static ModifiableByte explicit(Byte explicitValue) { - return getModifiableByteWithModification( - ByteModificationFactory.explicitValue(explicitValue)); + return getModifiableByteWithModification(new ByteExplicitValueModification(explicitValue)); } public static ModifiableInteger explicit(Integer explicitValue) { return getModifiableIntegerWithModification( - IntegerModificationFactory.explicitValue(explicitValue)); + new IntegerExplicitValueModification(explicitValue)); } public static ModifiableBigInteger explicit(BigInteger explicitValue) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.explicitValue(explicitValue)); + new BigIntegerExplicitValueModification(explicitValue)); } public static ModifiableLong explicit(Long explicitValue) { - return getModifiableLongWithModification( - LongModificationFactory.explicitValue(explicitValue)); + return getModifiableLongWithModification(new LongExplicitValueModification(explicitValue)); } public static ModifiableBoolean explicit(Boolean explicitValue) { return getModifiableBooleanWithModification( - BooleanModificationFactory.explicitValue(explicitValue)); + new BooleanExplicitValueModification(explicitValue)); } public static ModifiableString explicit(String explicitValue) { return getModifiableStringWithModification( - StringModificationFactory.explicitValue(explicitValue)); + new StringExplicitValueModification(explicitValue)); } public static ModifiableByteArray insert(byte[] insertValue, int position) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.insertValue(insertValue, position)); + new ByteArrayInsertValueModification(insertValue, position)); } public static ModifiableString insert(String insertValue, int position) { return getModifiableStringWithModification( - StringModificationFactory.insertValue(insertValue, position)); + new StringInsertValueModification(insertValue, position)); } public static ModifiableByteArray xor(byte[] xor, int position) { - return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.xor(xor, position)); + return getModifiableByteArrayWithModification(new ByteArrayXorModification(xor, position)); } public static ModifiableByte xor(Byte xor) { - return getModifiableByteWithModification(ByteModificationFactory.xor(xor)); + return getModifiableByteWithModification(new ByteXorModification(xor)); } public static ModifiableInteger xor(Integer xor) { - return getModifiableIntegerWithModification(IntegerModificationFactory.xor(xor)); + return getModifiableIntegerWithModification(new IntegerXorModification(xor)); } public static ModifiableBigInteger xor(BigInteger xor) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.xor(xor)); + return getModifiableBigIntegerWithModification(new BigIntegerXorModification(xor)); } public static ModifiableLong xor(Long xor) { - return getModifiableLongWithModification(LongModificationFactory.xor(xor)); + return getModifiableLongWithModification(new LongXorModification(xor)); } public static ModifiableInteger swapEndianIntger() { - return getModifiableIntegerWithModification(IntegerModificationFactory.swapEndian()); + return getModifiableIntegerWithModification(new IntegerSwapEndianModification()); } public static ModifiableLong swapEndianLong() { - return getModifiableLongWithModification(LongModificationFactory.swapEndian()); + return getModifiableLongWithModification(new LongSwapEndianModification()); } public static ModifiableByte add(Byte summand) { - return getModifiableByteWithModification(ByteModificationFactory.add(summand)); + return getModifiableByteWithModification(new ByteAddModification(summand)); } public static ModifiableInteger add(Integer summand) { - return getModifiableIntegerWithModification(IntegerModificationFactory.add(summand)); + return getModifiableIntegerWithModification(new IntegerAddModification(summand)); } public static ModifiableBigInteger add(BigInteger summand) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.add(summand)); + return getModifiableBigIntegerWithModification(new BigIntegerAddModification(summand)); } public static ModifiableLong add(Long summand) { - return getModifiableLongWithModification(LongModificationFactory.add(summand)); + return getModifiableLongWithModification(new LongAddModification(summand)); } public static ModifiableByte sub(Byte subtrahend) { - return getModifiableByteWithModification(ByteModificationFactory.sub(subtrahend)); + return getModifiableByteWithModification(new ByteSubtractModification(subtrahend)); } public static ModifiableInteger sub(Integer subtrahend) { - return getModifiableIntegerWithModification(IntegerModificationFactory.sub(subtrahend)); + return getModifiableIntegerWithModification(new IntegerSubtractModification(subtrahend)); } public static ModifiableBigInteger sub(BigInteger subtrahend) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.sub(subtrahend)); + new BigIntegerSubtractModification(subtrahend)); } public static ModifiableLong sub(Long subtrahend) { - return getModifiableLongWithModification(LongModificationFactory.sub(subtrahend)); + return getModifiableLongWithModification(new LongSubtractModification(subtrahend)); } public static ModifiableByteArray delete(int startPosition, int count) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.delete(startPosition, count)); + new ByteArrayDeleteModification(startPosition, count)); } public static ModifiableByteArray shuffle(byte[] shuffle) { - return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.shuffle(shuffle)); + return getModifiableByteArrayWithModification(new ByteArrayShuffleModification(shuffle)); } public static ModifiableByteArray duplicate() { - return getModifiableByteArrayWithModification(ByteArrayModificationFactory.duplicate()); + return getModifiableByteArrayWithModification(new ByteArrayDuplicateModification()); } public static ModifiableBoolean toggle() { - return getModifiableBooleanWithModification(BooleanModificationFactory.toggle()); + return getModifiableBooleanWithModification(new BooleanToggleModification()); } public static ModifiableBigInteger shiftLeftBigInteger(Integer shift) { - return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.shiftLeft(shift)); + return getModifiableBigIntegerWithModification(new BigIntegerShiftLeftModification(shift)); } public static ModifiableInteger shiftLeft(Integer shift) { - return getModifiableIntegerWithModification(IntegerModificationFactory.shiftLeft(shift)); + return getModifiableIntegerWithModification(new IntegerShiftLeftModification(shift)); } public static ModifiableLong shiftLeftLong(Integer shift) { - return getModifiableLongWithModification(LongModificationFactory.shiftLeft(shift)); + return getModifiableLongWithModification(new LongShiftLeftModification(shift)); } public static ModifiableBigInteger shiftRightBigInteger(Integer shift) { - return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.shiftRight(shift)); + return getModifiableBigIntegerWithModification(new BigIntegerShiftRightModification(shift)); } public static ModifiableInteger shiftRight(Integer shift) { - return getModifiableIntegerWithModification(IntegerModificationFactory.shiftRight(shift)); + return getModifiableIntegerWithModification(new IntegerShiftRightModification(shift)); } public static ModifiableLong shiftRightLong(Integer shift) { - return getModifiableLongWithModification(LongModificationFactory.shiftRight(shift)); + return getModifiableLongWithModification(new LongShiftRightModification(shift)); } public static ModifiableBigInteger multiplyBigInteger(BigInteger factor) { - return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.multiply(factor)); + return getModifiableBigIntegerWithModification(new BigIntegerMultiplyModification(factor)); } public static ModifiableInteger multiply(Integer factor) { - return getModifiableIntegerWithModification(IntegerModificationFactory.multiply(factor)); + return getModifiableIntegerWithModification(new IntegerMultiplyModification(factor)); } public static ModifiableLong multiply(Long factor) { - return getModifiableLongWithModification(LongModificationFactory.multiply(factor)); + return getModifiableLongWithModification(new LongMultiplyModification(factor)); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/assertion/AssertionTest.java b/src/test/java/de/rub/nds/modifiablevariable/assertion/AssertionTest.java index cffe2e75..af562e22 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/assertion/AssertionTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/assertion/AssertionTest.java @@ -12,7 +12,7 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray; -import de.rub.nds.modifiablevariable.integer.IntegerModificationFactory; +import de.rub.nds.modifiablevariable.integer.IntegerAddModification; import de.rub.nds.modifiablevariable.integer.ModifiableInteger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,7 +41,7 @@ public void testAssertionInteger() { @Test public void testAddInteger() { - VariableModification modifier = IntegerModificationFactory.add(1); + VariableModification modifier = new IntegerAddModification(1); mi.setModifications(modifier); mi.setAssertEquals(11); assertTrue(mi.validateAssertions()); diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java index 64c213b6..d041c22a 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java @@ -28,11 +28,10 @@ public void setUp() { result = null; } - /** Test of add method, of class BigIntegerModificationFactory. */ + /** Test of add method, of class BigIntegerAddModification. */ @Test public void testAdd() { - VariableModification modifier = - BigIntegerModificationFactory.add(BigInteger.ONE); + VariableModification modifier = new BigIntegerAddModification(BigInteger.ONE); start.setModifications(modifier); expectedResult = new BigInteger("11"); result = start.getValue(); @@ -41,11 +40,11 @@ public void testAdd() { assertEquals(BigInteger.TEN, start.getOriginalValue()); } - /** Test of sub method, of class BigIntegerModificationFactory. */ + /** Test of sub method, of class BigIntegerSubtractModification. */ @Test public void testSub() { VariableModification modifier = - BigIntegerModificationFactory.sub(BigInteger.ONE); + new BigIntegerSubtractModification(BigInteger.ONE); start.setModifications(modifier); expectedResult = new BigInteger("9"); result = start.getValue(); @@ -54,11 +53,11 @@ public void testSub() { assertEquals(BigInteger.TEN, start.getOriginalValue()); } - /** Test of xor method, of class BigIntegerModificationFactory. */ + /** Test of xor method, of class BigIntegerXorModification. */ @Test public void testXor() { VariableModification modifier = - BigIntegerModificationFactory.xor(new BigInteger("2")); + new BigIntegerXorModification(new BigInteger("2")); start.setModifications(modifier); expectedResult = new BigInteger("8"); result = start.getValue(); @@ -67,11 +66,11 @@ public void testXor() { assertEquals(BigInteger.TEN, start.getOriginalValue()); } - /** Test of explicitValue method, of class BigIntegerModificationFactory. */ + /** Test of explicitValue method, of class BigIntegerExplicitValueModification. */ @Test public void testExplicitValue() { VariableModification modifier = - BigIntegerModificationFactory.explicitValue(new BigInteger("7")); + new BigIntegerExplicitValueModification(new BigInteger("7")); start.setModifications(modifier); expectedResult = new BigInteger("7"); result = start.getValue(); @@ -80,22 +79,21 @@ public void testExplicitValue() { assertEquals(BigInteger.TEN, start.getOriginalValue()); } - /** Test of add method, of class BigIntegerModificationFactory. */ + /** Test of add method, of class BigIntegerAddModification. */ @Test public void testIsOriginalValueModified() { assertFalse(start.isOriginalValueModified()); - VariableModification modifier = - BigIntegerModificationFactory.add(BigInteger.ZERO); + VariableModification modifier = new BigIntegerAddModification(BigInteger.ZERO); start.setModifications(modifier); assertFalse(start.isOriginalValueModified()); - modifier = BigIntegerModificationFactory.add(BigInteger.ONE); + modifier = new BigIntegerAddModification(BigInteger.ONE); start.setModifications(modifier); assertTrue(start.isOriginalValueModified()); } @Test public void testShiftLeft() { - VariableModification modifier = BigIntegerModificationFactory.shiftLeft(2); + VariableModification modifier = new BigIntegerShiftLeftModification(2); start.setModifications(modifier); expectedResult = new BigInteger("40"); result = start.getValue(); @@ -106,7 +104,7 @@ public void testShiftLeft() { @Test public void testShiftRight() { - VariableModification modifier = BigIntegerModificationFactory.shiftRight(1); + VariableModification modifier = new BigIntegerShiftRightModification(1); start.setModifications(modifier); expectedResult = new BigInteger("5"); result = start.getValue(); diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index f93e2d3d..095b877b 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -60,7 +60,7 @@ public void testSetValue() { public void testExplicitValue() { LOGGER.info("testExplicitValue"); VariableModification modifier = - ByteArrayModificationFactory.explicitValue(modification1); + new ByteArrayExplicitValueModification(modification1); start.setModifications(modifier); assertArrayEquals(modification1, start.getValue()); } @@ -69,7 +69,7 @@ public void testExplicitValue() { @Test public void testXorFirstBytes() { LOGGER.info("testXorFirstBytes"); - VariableModification modifier = ByteArrayModificationFactory.xor(modification1, 0); + VariableModification modifier = new ByteArrayXorModification(modification1, 0); start.setModifications(modifier); byte[] expResult = originalValue.clone(); @@ -83,7 +83,7 @@ public void testXorFirstBytes() { for (int i = 0; i < originalValue.length; i++) { expResult2[i] = (byte) (originalValue[i] ^ modification2[i]); } - VariableModification modifier2 = ByteArrayModificationFactory.xor(modification2, 0); + VariableModification modifier2 = new ByteArrayXorModification(modification2, 0); start.setModifications(modifier2); assertArrayEquals(expResult2, start.getValue()); } @@ -99,8 +99,7 @@ public void testXorLastBytes() { expResult[first + i] = (byte) (originalValue[first + i] ^ modification1[i]); } - VariableModification modifier = - ByteArrayModificationFactory.xor(modification1, first); + VariableModification modifier = new ByteArrayXorModification(modification1, first); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -112,8 +111,7 @@ public void testXorLastBytes() { expResult2[first + i] = (byte) (originalValue[first + i] ^ modification2[i]); } - VariableModification modifier2 = - ByteArrayModificationFactory.xor(modification2, first); + VariableModification modifier2 = new ByteArrayXorModification(modification2, first); start.setModifications(modifier2); assertArrayEquals(expResult2, start.getValue()); } @@ -133,7 +131,7 @@ public void testPrependBytes() { } VariableModification modifier = - ByteArrayModificationFactory.insertValue(modification1, 0); + new ByteArrayInsertValueModification(modification1, 0); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -156,7 +154,7 @@ public void testAppendBytes() { } VariableModification modifier = - ByteArrayModificationFactory.insertValue(modification1, originalValue.length); + new ByteArrayInsertValueModification(modification1, originalValue.length); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -174,7 +172,7 @@ public void testDeleteLastBytes() { byte[] expResult = new byte[len]; System.arraycopy(originalValue, 0, expResult, 0, len); VariableModification modifier = - ByteArrayModificationFactory.delete(len, modification1.length); + new ByteArrayDeleteModification(len, modification1.length); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -194,7 +192,7 @@ public void testDeleteFirstBytes() { System.arraycopy( originalValue, modification1.length, expResult, 0, len - modification1.length); VariableModification modifier = - ByteArrayModificationFactory.delete(0, modification1.length); + new ByteArrayDeleteModification(0, modification1.length); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -213,39 +211,39 @@ public void testDeleteBytes() { byte[] expResult2 = {(byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5}; byte[] expResult3 = {(byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6}; - VariableModification modifier = ByteArrayModificationFactory.delete(0, len); + VariableModification modifier = new ByteArrayDeleteModification(0, len); start.setModifications(modifier); assertArrayEquals(expResult, start.getValue()); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete more Bytes than possible"); - modifier = ByteArrayModificationFactory.delete(0, len + 1); + modifier = new ByteArrayDeleteModification(0, len + 1); start.setModifications(modifier); assertArrayEquals(start.getValue(), expResult); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete negative amount"); - modifier = ByteArrayModificationFactory.delete(0, -1); + modifier = new ByteArrayDeleteModification(0, -1); start.setModifications(modifier); assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete 0 Bytes"); - modifier = ByteArrayModificationFactory.delete(0, 0); + modifier = new ByteArrayDeleteModification(0, 0); start.setModifications(modifier); assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from negative Start position"); - modifier = ByteArrayModificationFactory.delete(len * -2, 1); + modifier = new ByteArrayDeleteModification(len * -2, 1); start.setModifications(modifier); assertArrayEquals(start.getValue(), expResult2); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from to big Start Position"); - modifier = ByteArrayModificationFactory.delete(len * 2, 2); + modifier = new ByteArrayDeleteModification(len * 2, 2); start.setModifications(modifier); assertArrayEquals(start.getValue(), expResult3); } @@ -258,7 +256,7 @@ public void testInsertBytes() { assumeTrue(modification1.length < originalValue.length); LOGGER.debug("Inserting negative at position"); VariableModification modifier = - ByteArrayModificationFactory.insertValue(modification1, -2 * originalValue.length); + new ByteArrayInsertValueModification(modification1, -2 * originalValue.length); start.setModifications(modifier); byte[] expResult = ArrayConverter.concatenate( @@ -270,7 +268,7 @@ public void testInsertBytes() { start.setOriginalValue(originalValue); LOGGER.debug("Inserting empty Array"); byte[] emptyArray = new byte[0]; - modifier = ByteArrayModificationFactory.insertValue(emptyArray, 0); + modifier = new ByteArrayInsertValueModification(emptyArray, 0); start.setModifications(modifier); assertArrayEquals(originalValue, start.getValue()); @@ -278,8 +276,7 @@ public void testInsertBytes() { start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting at too large position"); - modifier = - ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); + modifier = new ByteArrayInsertValueModification(modification1, originalValue.length * 2); start.setModifications(modifier); expResult = ArrayConverter.concatenate( @@ -294,13 +291,13 @@ public void testInsertBytes() { @Test public void testIsOriginalValueModified() { assertFalse(start.isOriginalValueModified()); - VariableModification modifier = ByteArrayModificationFactory.xor(new byte[] {}, 0); + VariableModification modifier = new ByteArrayXorModification(new byte[] {}, 0); start.setModifications(modifier); assertFalse(start.isOriginalValueModified()); - modifier = ByteArrayModificationFactory.xor(new byte[] {1}, 0); + modifier = new ByteArrayXorModification(new byte[] {1}, 0); start.setModifications(modifier); assertTrue(start.isOriginalValueModified()); - modifier = ByteArrayModificationFactory.xor(new byte[] {0, 0}, originalValue.length - 2); + modifier = new ByteArrayXorModification(new byte[] {0, 0}, originalValue.length - 2); start.setModifications(modifier); assertFalse(start.isOriginalValueModified()); } @@ -310,7 +307,7 @@ public void testDuplicateModification() { LOGGER.info("testDuplicateModification"); byte[] expResult = ArrayConverter.concatenate(originalValue, originalValue); - VariableModification modifier = ByteArrayModificationFactory.duplicate(); + VariableModification modifier = new ByteArrayDuplicateModification(); start.setModifications(modifier); LOGGER.debug("Expected: {}", expResult); @@ -322,18 +319,17 @@ public void testDuplicateModification() { @Test public void testShuffle() { LOGGER.info("testShuffle"); - VariableModification modifier = - ByteArrayModificationFactory.shuffle(new byte[] {0, 1}); + VariableModification modifier = new ByteArrayShuffleModification(new byte[] {0, 1}); start.setModifications(modifier); byte[] result = {1, 0, 2, 3, 4, 5, 6}; assertArrayEquals(result, start.getValue()); - modifier = ByteArrayModificationFactory.shuffle(new byte[] {0, 1, 2, 3, 4, 5, 6}); + modifier = new ByteArrayShuffleModification(new byte[] {0, 1, 2, 3, 4, 5, 6}); start.setModifications(modifier); result = new byte[] {1, 0, 3, 2, 5, 4, 6}; assertArrayEquals(result, start.getValue()); - modifier = ByteArrayModificationFactory.shuffle(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}); + modifier = new ByteArrayShuffleModification(new byte[] {0, 1, 2, 3, 4, 5, 6, 7}); start.setModifications(modifier); result = new byte[] {6, 0, 3, 2, 5, 4, 1}; assertArrayEquals(result, start.getValue()); diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java index 8add8762..81560416 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java @@ -13,14 +13,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class IntegerModificationTest { +class IntegerModificationTest { private ModifiableInteger start; - private Integer expectedResult, result; @BeforeEach - public void setUp() { + void setUp() { start = new ModifiableInteger(); start.setOriginalValue(10); expectedResult = null; @@ -29,65 +28,239 @@ public void setUp() { /** Test of add method, of class IntegerModification. */ @Test - public void testAdd() { - VariableModification modifier = IntegerModificationFactory.add(1); + void testAdd() { + VariableModification modifier = new IntegerAddModification(1); start.setModifications(modifier); expectedResult = 11; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + assertEquals(10, start.getOriginalValue()); + } + + /** Test of add method with String, of class IntegerModification. */ + @Test + void testAddWithString() { + VariableModification modifier = new IntegerAddModification(1); + start.setModifications(modifier); + expectedResult = 11; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of add method with null input, of class IntegerModification. */ + @Test + void testAddWithNullInput() { + VariableModification modifier = new IntegerAddModification(1); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); } /** Test of sub method, of class IntegerModification. */ @Test - public void testSub() { - VariableModification modifier = IntegerModificationFactory.sub(1); + void testSub() { + VariableModification modifier = new IntegerSubtractModification(1); start.setModifications(modifier); expectedResult = 9; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + assertEquals(10, start.getOriginalValue()); + } + + /** Test of sub method with null input, of class IntegerModification. */ + @Test + void testSubWithNullInput() { + VariableModification modifier = new IntegerSubtractModification(1); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); } /** Test of xor method, of class IntegerModification. */ @Test - public void testXor() { - VariableModification modifier = IntegerModificationFactory.xor(2); + void testXor() { + VariableModification modifier = new IntegerXorModification(2); start.setModifications(modifier); expectedResult = 8; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + assertEquals(10, start.getOriginalValue()); + } + + /** Test of xor method with null input, of class IntegerModification. */ + @Test + void testXorWithNullInput() { + VariableModification modifier = new IntegerXorModification(2); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); } /** Test of explicitValue method, of class IntegerModification. */ @Test - public void testExplicitValue() { - VariableModification modifier = IntegerModificationFactory.explicitValue(7); + void testExplicitValue() { + VariableModification modifier = new IntegerExplicitValueModification(7); start.setModifications(modifier); expectedResult = 7; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + assertEquals(10, start.getOriginalValue()); } + /** Test of explicitValue method with String, of class IntegerModification. */ @Test - public void testShiftLeft() { - VariableModification modifier = IntegerModificationFactory.shiftLeft(2); + void testExplicitValueWithString() { + VariableModification modifier = new IntegerExplicitValueModification(7); + start.setModifications(modifier); + expectedResult = 7; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of explicitValue method with null input, of class IntegerModification. */ + @Test + void testExplicitValueWithNullInput() { + VariableModification modifier = new IntegerExplicitValueModification(7); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); + } + + /** Test of shiftLeft method, of class IntegerModification. */ + @Test + void testShiftLeft() { + VariableModification modifier = new IntegerShiftLeftModification(2); start.setModifications(modifier); expectedResult = 40; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + assertEquals(10, start.getOriginalValue()); + } + + /** Test of shiftLeft method with String, of class IntegerModification. */ + @Test + void testShiftLeftWithString() { + VariableModification modifier = new IntegerShiftLeftModification(2); + start.setModifications(modifier); + expectedResult = 40; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of shiftRight method, of class IntegerModification. */ + @Test + void testShiftRight() { + VariableModification modifier = new IntegerShiftRightModification(2); + start.setModifications(modifier); + expectedResult = 2; + result = start.getValue(); + assertEquals(expectedResult, result); + assertEquals(10, start.getOriginalValue()); } + /** Test of shiftRight method with String, of class IntegerModification. */ @Test - public void testShiftRight() { - VariableModification modifier = IntegerModificationFactory.shiftRight(2); + void testShiftRightWithString() { + VariableModification modifier = new IntegerShiftRightModification(2); start.setModifications(modifier); expectedResult = 2; result = start.getValue(); assertEquals(expectedResult, result); - assertEquals(Integer.valueOf(10), start.getOriginalValue()); + } + + /** Test of swapEndian method, of class IntegerModification. */ + @Test + void testSwapEndian() { + VariableModification modifier = new IntegerSwapEndianModification(); + start.setOriginalValue(0x12345678); + start.setModifications(modifier); + expectedResult = 0x78563412; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of swapEndian method with null input, of class IntegerModification. */ + @Test + void testSwapEndianWithNullInput() { + VariableModification modifier = new IntegerSwapEndianModification(); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); + } + + /** Test of multiply method, of class IntegerModification. */ + @Test + void testMultiply() { + VariableModification modifier = new IntegerMultiplyModification(2); + start.setModifications(modifier); + expectedResult = 20; + result = start.getValue(); + assertEquals(expectedResult, result); + assertEquals(10, start.getOriginalValue()); + } + + /** Test of multiply method with negative value, of class IntegerModification. */ + @Test + void testMultiplyWithNegativeValue() { + VariableModification modifier = new IntegerMultiplyModification(-1); + start.setModifications(modifier); + expectedResult = -10; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of multiply method with zero, of class IntegerModification. */ + @Test + void testMultiplyWithZero() { + VariableModification modifier = new IntegerMultiplyModification(0); + start.setModifications(modifier); + expectedResult = 0; + result = start.getValue(); + assertEquals(expectedResult, result); + } + + /** Test of multiply method with null input, of class IntegerModification. */ + @Test + void testMultiplyWithNullInput() { + VariableModification modifier = new IntegerMultiplyModification(2); + start.setOriginalValue(null); + start.setModifications(modifier); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + start.getValue(); + }); + } + + /** Test of multiple modifications, of class IntegerModification. */ + @Test + void testMultipleModifications() { + // Instead of chaining, apply modifications one after another + VariableModification addModifier = new IntegerAddModification(5); + VariableModification multiplyModifier = new IntegerMultiplyModification(2); + start.setModifications(addModifier, multiplyModifier); + expectedResult = 30; // (10 + 5) * 2 + result = start.getValue(); + assertEquals(expectedResult, result); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModificationTest.java new file mode 100644 index 00000000..315708d0 --- /dev/null +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModificationTest.java @@ -0,0 +1,218 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class IntegerMultiplyModificationTest { + + private ModifiableInteger modifiableInteger; + private int originalValue; + + @BeforeEach + public void setUp() { + modifiableInteger = new ModifiableInteger(); + originalValue = 123; + modifiableInteger.setOriginalValue(originalValue); + } + + @Test + public void testMultiplyModification() { + int factor = 2; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = originalValue * factor; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + assertEquals(246, result); + } + + @Test + public void testMultiplyByZero() { + int factor = 0; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = 0; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testMultiplyByOne() { + int factor = 1; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = originalValue; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testMultiplyByNegative() { + int factor = -1; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = -originalValue; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testMultiplyWithNullInput() { + modifiableInteger.setOriginalValue(null); + + int factor = 5; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + modifiableInteger.getValue(); + }); + } + + @Test + public void testMultiplyMaxValue() { + modifiableInteger.setOriginalValue(Integer.MAX_VALUE); + + int factor = 2; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = Integer.MAX_VALUE * 2; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testMultiplyMinValue() { + modifiableInteger.setOriginalValue(Integer.MIN_VALUE); + + int factor = 2; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + modifiableInteger.setModifications(modification); + + int expected = Integer.MIN_VALUE * 2; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testDefaultConstructor() { + IntegerMultiplyModification modification = new IntegerMultiplyModification(); + + // Set factor after construction + modification.setFactor(3); + + modifiableInteger.setModifications(modification); + int expected = originalValue * 3; + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + public void testGetFactor() { + int factor = 5; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + + assertEquals(factor, modification.getFactor()); + } + + @Test + public void testSetFactor() { + IntegerMultiplyModification modification = new IntegerMultiplyModification(2); + + int newFactor = 10; + modification.setFactor(newFactor); + + assertEquals(newFactor, modification.getFactor()); + } + + @Test + public void testCopyConstructor() { + int factor = 7; + IntegerMultiplyModification original = new IntegerMultiplyModification(factor); + IntegerMultiplyModification copy = new IntegerMultiplyModification(original); + + assertEquals(original.getFactor(), copy.getFactor()); + } + + @Test + public void testCreateCopy() { + int factor = 7; + IntegerMultiplyModification original = new IntegerMultiplyModification(factor); + IntegerMultiplyModification copy = original.createCopy(); + + assertEquals(original.getFactor(), copy.getFactor()); + + // In this implementation, equals() only checks values, not instance identity + assertEquals(original, copy, "Objects with the same factor should be equal"); + + // We can verify it's a copy by checking they're not the same reference + assertNotSame(original, copy, "Copy should not be the same reference"); + } + + @Test + public void testEqualsAndHashCode() { + int factor1 = 5; + int factor2 = 5; + int factor3 = 10; + + IntegerMultiplyModification modification1 = new IntegerMultiplyModification(factor1); + IntegerMultiplyModification modification2 = new IntegerMultiplyModification(factor2); + IntegerMultiplyModification modification3 = new IntegerMultiplyModification(factor3); + IntegerAddModification differentModification = new IntegerAddModification(factor1); + + // Test equals + assertEquals(modification1, modification1, "Object should be equal to itself"); + assertEquals(modification1, modification2, "Objects with same factor should be equal"); + assertNotEquals( + modification1, modification3, "Objects with different factors should not be equal"); + assertNotEquals( + modification1, differentModification, "Different types should not be equal"); + assertNotEquals(modification1, null, "Object should not be equal to null"); + assertNotEquals( + modification1, new Object(), "Object should not be equal to different class"); + + // Test hashCode + assertEquals( + modification1.hashCode(), + modification2.hashCode(), + "Equal objects should have same hash code"); + assertNotEquals( + modification1.hashCode(), + modification3.hashCode(), + "Different objects should have different hash codes"); + } + + @Test + public void testToString() { + int factor = 42; + IntegerMultiplyModification modification = new IntegerMultiplyModification(factor); + String toString = modification.toString(); + + assertEquals("IntegerMultiplyModification{factor=" + factor + "}", toString); + } +} diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerShiftModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerShiftModificationTest.java index 88ee0bd2..2d22380d 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerShiftModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerShiftModificationTest.java @@ -69,10 +69,11 @@ public void testShiftLeftWithNullInput() { IntegerShiftLeftModification modification = new IntegerShiftLeftModification(shift); modifiableInteger.setModifications(modification); - int expected = 0 << shift; // Should treat null as 0 - int result = modifiableInteger.getValue(); - - assertEquals(expected, result); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + modifiableInteger.getValue(); + }); } @Test @@ -160,10 +161,11 @@ public void testShiftRightWithNullInput() { IntegerShiftRightModification modification = new IntegerShiftRightModification(shift); modifiableInteger.setModifications(modification); - int expected = 0 >> shift; // Should treat null as 0 - int result = modifiableInteger.getValue(); - - assertEquals(expected, result); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + modifiableInteger.getValue(); + }); } @Test diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModificationTest.java new file mode 100644 index 00000000..eca5d8b7 --- /dev/null +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModificationTest.java @@ -0,0 +1,124 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class IntegerSwapEndianModificationTest { + + private ModifiableInteger modifiableInteger; + + @BeforeEach + void setUp() { + modifiableInteger = new ModifiableInteger(); + } + + @Test + void testSwapEndianModification() { + int originalValue = 0x12345678; + modifiableInteger.setOriginalValue(originalValue); + + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + modifiableInteger.setModifications(modification); + + int result = modifiableInteger.getValue(); + + assertEquals(0x78563412, result); + } + + @Test + void testSwapEndianWithZero() { + int originalValue = 0; + modifiableInteger.setOriginalValue(originalValue); + + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + modifiableInteger.setModifications(modification); + + int expected = 0; // Swapping bytes of 0 is still 0 + int result = modifiableInteger.getValue(); + + assertEquals(expected, result); + } + + @Test + void testSwapEndianWithNullInput() { + modifiableInteger.setOriginalValue(null); + + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + modifiableInteger.setModifications(modification); + + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + modifiableInteger.getValue(); + }); + } + + @Test + void testCreateCopy() { + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + IntegerSwapEndianModification copy = modification.createCopy(); + + // In this implementation, equals() checks for the same class type + // but doesn't check for instance equality, so we don't use assertNotEquals + assertEquals(modification.getClass(), copy.getClass(), "Copy should be the same class"); + assertEquals(modification.hashCode(), copy.hashCode(), "Hash codes should be equal"); + assertEquals(modification, copy, "Objects should be equal"); + + // We can verify it's a copy by checking they're not the same reference + assertNotSame(modification, copy, "Copy should not be the same reference"); + } + + @Test + void testEqualsAndHashCode() { + IntegerSwapEndianModification modification1 = new IntegerSwapEndianModification(); + IntegerSwapEndianModification modification2 = new IntegerSwapEndianModification(); + IntegerAddModification differentModification = new IntegerAddModification(1); + + // Test equals + assertEquals(modification1, modification2, "Equal objects should be equal"); + assertEquals(modification1, modification1, "Object should be equal to itself"); + assertNotEquals( + modification1, differentModification, "Different types should not be equal"); + assertNotEquals(modification1, null, "Object should not be equal to null"); + assertNotEquals( + modification1, new Object(), "Object should not be equal to different class"); + + // Test hashCode + assertEquals( + modification1.hashCode(), + modification2.hashCode(), + "Equal objects should have same hash code"); + } + + @Test + void testToString() { + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + String toString = modification.toString(); + + assertEquals("IntegerSwapEndianModification{}", toString); + } + + @Test + void testApplyMultipleTimes() { + int originalValue = 0x12345678; + modifiableInteger.setOriginalValue(originalValue); + + IntegerSwapEndianModification modification = new IntegerSwapEndianModification(); + modifiableInteger.setModifications(modification, modification); + + int result1 = modifiableInteger.getValue(); // Apply once + + assertEquals(originalValue, result1); + } +} diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java index e954f1e6..96207280 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java @@ -9,84 +9,248 @@ import static org.junit.jupiter.api.Assertions.*; +import de.rub.nds.modifiablevariable.VariableModification; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class ModifiableIntegerTest { +class ModifiableIntegerTest { private ModifiableInteger integer1; - private ModifiableInteger integer2; + private ModifiableInteger nullInteger; @BeforeEach - public void setUp() { + void setUp() { integer1 = new ModifiableInteger(); integer1.setOriginalValue(2); integer2 = new ModifiableInteger(); integer2.setOriginalValue(2); + nullInteger = new ModifiableInteger(); + } + + /** Test of default constructor, of class ModifiableInteger. */ + @Test + void testDefaultConstructor() { + ModifiableInteger instance = new ModifiableInteger(); + assertNull(instance.getOriginalValue()); + assertNull(instance.getValue()); + } + + /** Test of parameterized constructor, of class ModifiableInteger. */ + @Test + void testParameterizedConstructor() { + Integer originalValue = 42; + ModifiableInteger instance = new ModifiableInteger(originalValue); + assertEquals(originalValue, instance.getOriginalValue()); + assertEquals(originalValue, instance.getValue()); + } + + /** Test of copy constructor, of class ModifiableInteger. */ + @Test + void testCopyConstructor() { + Integer originalValue = 42; + ModifiableInteger original = new ModifiableInteger(originalValue); + original.setAssertEquals(100); + + ModifiableInteger copy = new ModifiableInteger(original); + assertEquals(original.getOriginalValue(), copy.getOriginalValue()); + assertEquals(original.getValue(), copy.getValue()); + assertEquals(original.getAssertEquals(), copy.getAssertEquals()); + } + + /** Test of createCopy method, of class ModifiableInteger. */ + @Test + void testCreateCopy() { + ModifiableInteger copy = integer1.createCopy(); + + assertEquals(integer1.getOriginalValue(), copy.getOriginalValue()); + assertEquals(integer1.getValue(), copy.getValue()); + assertNotSame(integer1, copy); + // Verify it's a deep copy - modifying the copy doesn't affect the original + copy.setOriginalValue(999); + assertNotEquals(integer1.getOriginalValue(), copy.getOriginalValue()); } /** Test of getAssertEquals method, of class ModifiableInteger. */ @Test - public void testGetAssertEquals() { + void testGetAssertEquals() { integer1.setAssertEquals(2); assertEquals(2, integer1.getAssertEquals()); + assertNull(nullInteger.getAssertEquals()); } /** Test of setAssertEquals method, of class ModifiableInteger. */ @Test - public void testSetAssertEquals() { - assertNotEquals(3, integer1.getAssertEquals()); + void testSetAssertEquals() { + assertNull(integer1.getAssertEquals()); integer1.setAssertEquals(3); assertEquals(3, integer1.getAssertEquals()); + + integer1.setAssertEquals(null); + assertNull(integer1.getAssertEquals()); } /** Test of getByteArray method, of class ModifiableInteger. */ @Test - public void testGetByteArray() { + void testGetByteArray() { assertArrayEquals(integer1.getByteArray(2), integer2.getByteArray(2)); + + integer1.setOriginalValue(258); // 0x00000102 + byte[] expected = new byte[] {0x01, 0x02}; // Big-endian, 2 bytes + assertArrayEquals(expected, integer1.getByteArray(2)); + + // Test with different sizes + assertArrayEquals(new byte[] {0x00, 0x00, 0x01, 0x02}, integer1.getByteArray(4)); + assertArrayEquals(new byte[] {0x02}, integer1.getByteArray(1)); } /** Test of validateAssertions method, of class ModifiableInteger. */ @Test - public void testValidateAssertions() { + void testValidateAssertions() { + // No assertions set - should be valid assertTrue(integer1.validateAssertions()); + assertTrue(nullInteger.validateAssertions()); + + // Set matching assertion + integer1.setAssertEquals(2); + assertTrue(integer1.validateAssertions()); + + // Set non-matching assertion integer1.setAssertEquals(3); assertFalse(integer1.validateAssertions()); + + // Test with modification + integer1 = new ModifiableInteger(10); + integer1.setAssertEquals(11); + assertFalse(integer1.validateAssertions()); + + VariableModification modifier = new IntegerAddModification(1); + integer1.setModifications(modifier); + assertTrue(integer1.validateAssertions()); + } + + /** Test of isOriginalValueModified method, of class ModifiableInteger. */ + @Test + void testIsOriginalValueModified() { + // No modification + assertFalse(integer1.isOriginalValueModified()); + + // With modification that changes value + VariableModification modifier = new IntegerAddModification(1); + integer1.setModifications(modifier); + assertTrue(integer1.isOriginalValueModified()); + + // With modification that doesn't change value + modifier = new IntegerAddModification(0); + integer2.setModifications(modifier); + assertFalse(integer2.isOriginalValueModified()); + + org.junit.jupiter.api.Assertions.assertThrows( + IllegalStateException.class, + () -> { + nullInteger.isOriginalValueModified(); + }); + + ModifiableInteger nullIntWithExplicit = new ModifiableInteger((Integer) null); + nullIntWithExplicit.setModifications(new IntegerExplicitValueModification(5)); + org.junit.jupiter.api.Assertions.assertThrows( + IllegalStateException.class, + () -> { + nullIntWithExplicit.isOriginalValueModified(); + }); + org.junit.jupiter.api.Assertions.assertThrows( + NullPointerException.class, + () -> { + nullIntWithExplicit.getValue(); + }); } /** Test of getOriginalValue method, of class ModifiableInteger. */ @Test - public void testGetOriginalValue() { + void testGetOriginalValue() { assertEquals(2, integer1.getOriginalValue()); + assertNull(nullInteger.getOriginalValue()); } /** Test of setOriginalValue method, of class ModifiableInteger. */ @Test - public void testSetOriginalValue() { + void testSetOriginalValue() { integer1.setOriginalValue(3); assertEquals(3, integer1.getOriginalValue()); + assertEquals(3, integer1.getValue()); + + integer1.setOriginalValue(null); + assertNull(integer1.getOriginalValue()); + assertNull(integer1.getValue()); } /** Test of toString method, of class ModifiableInteger. */ @Test - public void testToString() { + void testToString() { assertEquals(integer1.toString(), integer2.toString()); + integer1.setOriginalValue(4); assertNotEquals(integer1.toString(), integer2.toString()); + + String nullString = nullInteger.toString(); + assertTrue(nullString.contains("originalValue=null")); + + // Test with modification + VariableModification modifier = new IntegerAddModification(1); + integer2.setModifications(modifier); + String modString = integer2.toString(); + assertEquals( + "ModifiableInteger{originalValue=2, modifications=[IntegerAddModification{summand=1}]}", + modString); } /** Test of equals method, of class ModifiableInteger. */ @Test - public void testEquals() { + void testEquals() { + // Same value assertEquals(integer1, integer2); + + // Same object + assertEquals(integer1, integer1); + + // Different class + assertNotEquals(integer1, new Object()); + + // Null + assertNotEquals(integer1, null); + + // Different values integer2.setOriginalValue(3); assertNotEquals(integer1, integer2); + + // Both null value + ModifiableInteger nullInt1 = new ModifiableInteger(); + ModifiableInteger nullInt2 = new ModifiableInteger(); + assertEquals(nullInt1, nullInt2); + + // One null value + assertNotEquals(integer1, nullInt1); + + // Same after modification + ModifiableInteger int1 = new ModifiableInteger(5); + ModifiableInteger int2 = new ModifiableInteger(4); + int2.setModifications(new IntegerAddModification(1)); + assertEquals(int1, int2); } /** Test of hashCode method, of class ModifiableInteger. */ @Test - public void testHashCode() { + void testHashCode() { + // Same value, same hash code assertEquals(integer1.hashCode(), integer2.hashCode()); + + // Different value, different hash code + integer2.setOriginalValue(3); + assertNotEquals(integer1.hashCode(), integer2.hashCode()); + + // Consistent hash code + int hash1 = integer1.hashCode(); + int hash2 = integer1.hashCode(); + assertEquals(hash1, hash2); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java index cc988ca5..3d883ac7 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java @@ -10,7 +10,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import de.rub.nds.modifiablevariable.VariableModification; -import de.rub.nds.modifiablevariable.longint.LongModificationFactory; +import de.rub.nds.modifiablevariable.longint.LongAddModification; +import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification; +import de.rub.nds.modifiablevariable.longint.LongSubtractModification; +import de.rub.nds.modifiablevariable.longint.LongXorModification; import de.rub.nds.modifiablevariable.longint.ModifiableLong; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,7 +36,7 @@ public void setUp() { @Test public void testAdd() { - VariableModification modifier = LongModificationFactory.add(1L); + VariableModification modifier = new LongAddModification(1L); start.setModifications(modifier); expectedResult = 11L; result = start.getValue(); @@ -43,7 +46,7 @@ public void testAdd() { @Test public void testSub() { - VariableModification modifier = LongModificationFactory.sub(1L); + VariableModification modifier = new LongSubtractModification(1L); start.setModifications(modifier); expectedResult = 9L; result = start.getValue(); @@ -53,7 +56,7 @@ public void testSub() { @Test public void testXor() { - VariableModification modifier = LongModificationFactory.xor(2L); + VariableModification modifier = new LongXorModification(2L); start.setModifications(modifier); expectedResult = 8L; result = start.getValue(); @@ -63,7 +66,7 @@ public void testXor() { @Test public void testExplicitValue() { - VariableModification modifier = LongModificationFactory.explicitValue(7L); + VariableModification modifier = new LongExplicitValueModification(7L); start.setModifications(modifier); expectedResult = 7L; result = start.getValue(); diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/BigIntegerSerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/BigIntegerSerializationTest.java index f4031c6f..70d01a30 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/BigIntegerSerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/BigIntegerSerializationTest.java @@ -12,9 +12,8 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification; -import de.rub.nds.modifiablevariable.biginteger.BigIntegerModificationFactory; import de.rub.nds.modifiablevariable.biginteger.ModifiableBigInteger; -import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayExplicitValueModification; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; @@ -55,7 +54,7 @@ public void setUp() throws JAXBException { JAXBContext.newInstance( ModifiableBigInteger.class, BigIntegerAddModification.class, - ByteArrayModificationFactory.class); + ByteArrayExplicitValueModification.class); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); um = context.createUnmarshaller(); @@ -80,8 +79,7 @@ public void testSerializeDeserializeSimple() throws Exception { @Test public void testSerializeDeserializeWithModification() throws Exception { - VariableModification modifier = - BigIntegerModificationFactory.add(BigInteger.ONE); + VariableModification modifier = new BigIntegerAddModification(BigInteger.ONE); start.setModifications(modifier); m.marshal(start, writer); diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java index e6ee7e55..24cf5df2 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java @@ -80,7 +80,7 @@ public void testSerializeDeserializeSimple() throws Exception { @Test public void testSerializeDeserializeWithModification() throws Exception { VariableModification modifier = - ByteArrayModificationFactory.insertValue(new byte[] {1, 2}, 0); + new ByteArrayInsertValueModification(new byte[] {1, 2}, 0); start.setModifications(modifier); m.marshal(start, writer); diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/LongSerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/LongSerializationTest.java index 5faf289a..5558761c 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/LongSerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/LongSerializationTest.java @@ -10,9 +10,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import de.rub.nds.modifiablevariable.VariableModification; -import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; +import de.rub.nds.modifiablevariable.bytearray.ByteArrayExplicitValueModification; import de.rub.nds.modifiablevariable.longint.LongAddModification; -import de.rub.nds.modifiablevariable.longint.LongModificationFactory; import de.rub.nds.modifiablevariable.longint.ModifiableLong; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; @@ -53,7 +52,7 @@ public void setUp() throws JAXBException { JAXBContext.newInstance( ModifiableLong.class, LongAddModification.class, - ByteArrayModificationFactory.class); + ByteArrayExplicitValueModification.class); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); um = context.createUnmarshaller(); @@ -77,7 +76,7 @@ public void testSerializeDeserializeSimple() throws Exception { @Test public void testSerializeDeserializeWithModification() throws Exception { - VariableModification modifier = LongModificationFactory.add(1L); + VariableModification modifier = new LongAddModification(1L); start.setModifications(modifier); m.marshal(start, writer); diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/StringSerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/StringSerializationTest.java index c6cd3724..e01e2c2b 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/StringSerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/StringSerializationTest.java @@ -12,7 +12,6 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.string.ModifiableString; import de.rub.nds.modifiablevariable.string.StringInsertValueModification; -import de.rub.nds.modifiablevariable.string.StringModificationFactory; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; @@ -75,7 +74,7 @@ public void testSerializeDeserializeSimple() throws Exception { @Test public void testSerializeDeserializeWithModification() throws Exception { - VariableModification modifier = StringModificationFactory.insertValue("Uff! ", 0); + VariableModification modifier = new StringInsertValueModification("Uff! ", 0); start.setModifications(modifier); m.marshal(start, writer); diff --git a/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationTest.java index 9f3124b2..52c94b26 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationTest.java @@ -27,10 +27,10 @@ public void setUp() { result = null; } - /** Test of add method, of class ByteModificationFactory. */ + /** Test of add method, of class ByteAddModification. */ @Test public void testAdd() { - VariableModification modifier = ByteModificationFactory.add(Byte.valueOf("1")); + VariableModification modifier = new ByteAddModification(Byte.valueOf("1")); start.setModifications(modifier); expectedResult = Byte.valueOf("11"); result = start.getValue(); @@ -38,10 +38,10 @@ public void testAdd() { assertEquals(Byte.valueOf("10"), start.getOriginalValue()); } - /** Test of sub method, of class ByteModificationFactory. */ + /** Test of sub method, of class ByteSubtractModification. */ @Test public void testSub() { - VariableModification modifier = ByteModificationFactory.sub(Byte.valueOf("1")); + VariableModification modifier = new ByteSubtractModification(Byte.valueOf("1")); start.setModifications(modifier); expectedResult = Byte.valueOf("9"); result = start.getValue(); @@ -49,10 +49,10 @@ public void testSub() { assertEquals(Byte.valueOf("10"), start.getOriginalValue()); } - /** Test of xor method, of class ByteModificationFactory. */ + /** Test of xor method, of class ByteXorModification. */ @Test public void testXor() { - VariableModification modifier = ByteModificationFactory.xor(Byte.valueOf("2")); + VariableModification modifier = new ByteXorModification(Byte.valueOf("2")); start.setModifications(modifier); expectedResult = Byte.valueOf("8"); result = start.getValue(); @@ -60,11 +60,10 @@ public void testXor() { assertEquals(Byte.valueOf("10"), start.getOriginalValue()); } - /** Test of explicitValue method, of class ByteModificationFactory. */ + /** Test of explicitValue method, of class ByteExplicitValueModification. */ @Test public void testExplicitValue() { - VariableModification modifier = - ByteModificationFactory.explicitValue(Byte.valueOf("7")); + VariableModification modifier = new ByteExplicitValueModification(Byte.valueOf("7")); start.setModifications(modifier); expectedResult = Byte.valueOf("7"); result = start.getValue(); diff --git a/src/test/java/de/rub/nds/modifiablevariable/string/ModifiableStringTest.java b/src/test/java/de/rub/nds/modifiablevariable/string/ModifiableStringTest.java index 8c84d4ba..42fb626b 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/string/ModifiableStringTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/string/ModifiableStringTest.java @@ -32,7 +32,7 @@ public void setUp() { @Test public void testIsOriginalValueModified() { assertFalse(string.isOriginalValueModified()); - VariableModification modifier = StringModificationFactory.appendValue("_Modified"); + VariableModification modifier = new StringAppendValueModification("_Modified"); string.setModifications(modifier); assertTrue(string.isOriginalValueModified()); } @@ -72,7 +72,7 @@ public void testEquals() { string2.setOriginalValue("TestString"); assertEquals(string, string2); assertEquals(string2, string); - string2.setModifications(StringModificationFactory.appendValue("_Modified")); + string2.setModifications(new StringAppendValueModification("_Modified")); assertNotEquals(string, string2); assertNotEquals(string2, string); assertFalse(string.equals(null)); diff --git a/src/test/java/de/rub/nds/modifiablevariable/string/StringModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/string/StringModificationTest.java index 6da8c997..eca6e232 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/string/StringModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/string/StringModificationTest.java @@ -28,7 +28,7 @@ public void setUp() { @Test public void testAppendModification() { String appendValue = "Appended"; - VariableModification modifier = StringModificationFactory.appendValue(appendValue); + VariableModification modifier = new StringAppendValueModification(appendValue); modifiableString.setModifications(modifier); assertEquals(originalValue + appendValue, modifiableString.getValue()); @@ -37,8 +37,7 @@ public void testAppendModification() { @Test public void testPrependModification() { String prependValue = "Prepended"; - VariableModification modifier = - StringModificationFactory.prependValue(prependValue); + VariableModification modifier = new StringPrependValueModification(prependValue); modifiableString.setModifications(modifier); assertEquals(prependValue + originalValue, modifiableString.getValue()); @@ -47,8 +46,7 @@ public void testPrependModification() { @Test public void testExplicitValueModification() { String explicitValue = "CompletelyDifferent"; - VariableModification modifier = - StringModificationFactory.explicitValue(explicitValue); + VariableModification modifier = new StringExplicitValueModification(explicitValue); modifiableString.setModifications(modifier); assertEquals(explicitValue, modifiableString.getValue()); @@ -58,7 +56,7 @@ public void testExplicitValueModification() { @Test public void testAppendWithEmptyString() { String appendValue = ""; - VariableModification modifier = StringModificationFactory.appendValue(appendValue); + VariableModification modifier = new StringAppendValueModification(appendValue); modifiableString.setModifications(modifier); assertEquals(originalValue, modifiableString.getValue()); @@ -67,8 +65,7 @@ public void testAppendWithEmptyString() { @Test public void testPrependWithEmptyString() { String prependValue = ""; - VariableModification modifier = - StringModificationFactory.prependValue(prependValue); + VariableModification modifier = new StringPrependValueModification(prependValue); modifiableString.setModifications(modifier); assertEquals(originalValue, modifiableString.getValue()); @@ -78,7 +75,7 @@ public void testPrependWithEmptyString() { public void testAppendToEmptyString() { modifiableString.setOriginalValue(""); String appendValue = "JustAppended"; - VariableModification modifier = StringModificationFactory.appendValue(appendValue); + VariableModification modifier = new StringAppendValueModification(appendValue); modifiableString.setModifications(modifier); assertEquals(appendValue, modifiableString.getValue()); @@ -88,8 +85,7 @@ public void testAppendToEmptyString() { public void testPrependToEmptyString() { modifiableString.setOriginalValue(""); String prependValue = "JustPrepended"; - VariableModification modifier = - StringModificationFactory.prependValue(prependValue); + VariableModification modifier = new StringPrependValueModification(prependValue); modifiableString.setModifications(modifier); assertEquals(prependValue, modifiableString.getValue());