File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
main/java/com/iab/gdpr/consent
test/java/com/iab/gdpr/consent Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,14 @@ public static VendorConsent fromBase64String(String consentString) {
2020 if (isNullOrEmpty (consentString ))
2121 throw new IllegalArgumentException ("Null or empty consent string passed as an argument" );
2222
23- final Bits bits = new Bits (BASE64_DECODER .decode (consentString ));
23+ return fromByteArray (BASE64_DECODER .decode (consentString ));
24+ }
25+
26+ public static VendorConsent fromByteArray (byte [] bytes ) {
27+ if (bytes == null || bytes .length == 0 )
28+ throw new IllegalArgumentException ("Null or empty consent bytes passed as an argument" );
29+
30+ final Bits bits = new Bits (bytes );
2431 final int version = getVersion (bits );
2532 switch (version ) {
2633 case 1 :
Original file line number Diff line number Diff line change @@ -24,6 +24,17 @@ public void testNullConsentString() {
2424 // Then IllegalArgumentException exception is thrown
2525 }
2626
27+ @ Test (expected = IllegalArgumentException .class )
28+ public void testNullConsentBytes () {
29+ // Given: null consent string
30+ byte [] consentBytes = null ;
31+
32+ // When: decoder is called
33+ final VendorConsent vendorConsent = VendorConsentDecoder .fromByteArray (consentBytes );
34+
35+ // Then IllegalArgumentException exception is thrown
36+ }
37+
2738 @ Test (expected = IllegalArgumentException .class )
2839 public void testEmptyConsentString () {
2940 // Given: empty consent string
@@ -36,6 +47,18 @@ public void testEmptyConsentString() {
3647
3748 }
3849
50+ @ Test (expected = IllegalArgumentException .class )
51+ public void testEmptyConsentBytes () {
52+ // Given: empty consent string
53+ byte [] consentBytes = new byte [0 ];
54+
55+ // When: decoder is called
56+ final VendorConsent vendorConsent = VendorConsentDecoder .fromByteArray (consentBytes );
57+
58+ // Then IllegalArgumentException exception is thrown
59+
60+ }
61+
3962 @ Test (expected = IllegalStateException .class )
4063 public void testUnknownVersion () {
4164 // Given: unknown version number in consent string
You can’t perform that action at this time.
0 commit comments