diff options
author | Andrew Scull <ascull@google.com> | 2023-09-13 15:37:20 +0000 |
---|---|---|
committer | Andrew Scull <ascull@google.com> | 2023-09-16 19:23:12 +0000 |
commit | 263ca6450e9e7701a6a8a983045c29d4972339ce (patch) | |
tree | c0c46794ed118f18aafd032723237f6dcfd83894 | |
parent | 0b251b5b02a056cabc18853468cd81f9a605e738 (diff) | |
download | cbor-java-263ca6450e9e7701a6a8a983045c29d4972339ce.tar.gz |
Characterize casting behaviour of DataItem encoding
The items are assumed to be instances of the classes from this library
so make that behaviour explicit in the tests.
-rw-r--r-- | src/test/java/co/nstant/in/cbor/CborEncoderTest.java | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/test/java/co/nstant/in/cbor/CborEncoderTest.java b/src/test/java/co/nstant/in/cbor/CborEncoderTest.java index 060a90e..c2e8ee3 100644 --- a/src/test/java/co/nstant/in/cbor/CborEncoderTest.java +++ b/src/test/java/co/nstant/in/cbor/CborEncoderTest.java @@ -10,10 +10,10 @@ import co.nstant.in.cbor.model.MajorType; public class CborEncoderTest { - private class InvalidDataItem extends DataItem { + private class Mock extends DataItem { - public InvalidDataItem() { - super(MajorType.INVALID); + public Mock(MajorType majorType) { + super(majorType); } } @@ -27,7 +27,47 @@ public class CborEncoderTest { @Test(expected = CborException.class) public void shouldNotEncodeInvalidMajorType() throws CborException { - encoder.encode(new InvalidDataItem()); + encoder.encode(new Mock(MajorType.INVALID)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectUnsignedIntegerImplementation() throws CborException { + encoder.encode(new Mock(MajorType.UNSIGNED_INTEGER)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectNegativeIntegerImplementation() throws CborException { + encoder.encode(new Mock(MajorType.NEGATIVE_INTEGER)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectByteStringImplementation() throws CborException { + encoder.encode(new Mock(MajorType.BYTE_STRING)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectUnicodeStringImplementation() throws CborException { + encoder.encode(new Mock(MajorType.UNICODE_STRING)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectArrayImplementation() throws CborException { + encoder.encode(new Mock(MajorType.ARRAY)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectMapImplementation() throws CborException { + encoder.encode(new Mock(MajorType.MAP)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectTagImplementation() throws CborException { + encoder.encode(new Mock(MajorType.TAG)); + } + + @Test(expected = ClassCastException.class) + public void shouldExpectSpecialImplementation() throws CborException { + encoder.encode(new Mock(MajorType.SPECIAL)); } } |