1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class NullTest {
@Test
void testConstructor() {
assertEquals(Null.TAG, new Null(Null.TAG, null).getTag());
assertEquals(0x01,
new Null(Null.TAG, new Tag(TagClass.CONTEXT_SPECIFIC, true, 0x01)).getParentTag().getNumber());
}
@Test
void testEncode() {
assertEquals(0, new Null(Null.TAG, null).encodeValueDER().length);
assertArrayEquals(new Byte[]{
0x5, 0x0 // Tag - Length
}, new Null(Null.TAG, null).encodeDER());
}
@Test
void testParse() throws ParseException {
new Null(new BytesReader(new Byte[]{0x5, 0x0}), false);
new Null(new BytesReader(new Byte[]{-95, 2, 0x5, 0x0}), true);
}
@Test
void testParseFail() {
assertThrows(ParseException.class, () ->
new Null(new BytesReader(new Byte[]{0x5, 0x2}), false));
assertThrows(ParseException.class, () ->
new Null(new BytesReader(new Byte[]{0x5, 0x2, 1, 1}), false));
}
}
|