Skip to content

Commit 5a4a8ab

Browse files
committed
Add more tests
1 parent a9717b6 commit 5a4a8ab

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/main/java/at/favre/lib/bytes/BytesTransformer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public byte[] transform(byte[] currentArray, boolean inPlace) {
6868

6969
for (int i = 0; i < currentArray.length; i++) {
7070
switch (mode) {
71+
default:
7172
case OR:
7273
out[i] = (byte) (currentArray[i] | secondArray[i]);
7374
break;
@@ -77,8 +78,6 @@ public byte[] transform(byte[] currentArray, boolean inPlace) {
7778
case XOR:
7879
out[i] = (byte) (currentArray[i] ^ secondArray[i]);
7980
break;
80-
default:
81-
throw new IllegalArgumentException("unknown bitwise transform mode " + mode);
8281
}
8382
}
8483

@@ -129,12 +128,11 @@ public byte[] transform(byte[] currentArray, boolean inPlace) {
129128
BigInteger bigInt = new BigInteger(currentArray);
130129

131130
switch (type) {
131+
default:
132132
case LEFT_SHIFT:
133133
return bigInt.shiftLeft(shiftCount).toByteArray();
134134
case RIGHT_SHIFT:
135135
return bigInt.shiftRight(shiftCount).toByteArray();
136-
default:
137-
throw new IllegalArgumentException("unknown shift type " + type);
138136
}
139137
}
140138
}

src/main/java/at/favre/lib/bytes/BytesValidators.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
* Util and easy access for {@link BytesValidators}
2626
*/
2727
public class BytesValidators {
28+
29+
private BytesValidators() {
30+
}
31+
2832
/**
2933
* Checks the length of a byte array
3034
*

src/test/java/at/favre/lib/bytes/BytesTransformTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ public void bitSwitch() throws Exception {
261261
}
262262
}
263263

264+
@Test(expected = IllegalArgumentException.class)
265+
public void bitSwitchOutOfBounds() throws Exception {
266+
Bytes.from(4).switchBit(32, true);
267+
}
268+
264269
@Test
265270
public void transform() throws Exception {
266271
assertArrayEquals(example_bytes_two, Bytes.from(example_bytes_two).transform(new BytesTransformer() {

0 commit comments

Comments
 (0)