Skip to content

Commit 8ee2a99

Browse files
committed
add check for null for setConsume
1 parent c30d590 commit 8ee2a99

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎src/main/java/com/google/firebase/appcheck/VerifyAppCheckTokenOptions.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.firebase.appcheck;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import java.util.Optional;
2022

2123
/**
@@ -60,11 +62,11 @@ public Builder setConsume(boolean consume) {
6062
/**
6163
* Sets whether to consume the token during verification.
6264
*
63-
* @param consume Optional boolean value.
65+
* @param consume Optional boolean value. Must not be null.
6466
* @return This builder.
6567
*/
6668
public Builder setConsume(Optional<Boolean> consume) {
67-
this.consume = consume != null ? consume : Optional.<Boolean>empty();
69+
this.consume = checkNotNull(consume, "consume must not be null");
6870
return this;
6971
}
7072

‎src/test/java/com/google/firebase/appcheck/VerifyAppCheckTokenOptionsTest.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
package com.google.firebase.appcheck;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertThrows;
2123
import static org.junit.Assert.assertTrue;
2224

25+
import java.util.Optional;
2326
import org.junit.Test;
2427

2528
public class VerifyAppCheckTokenOptionsTest {
@@ -48,4 +51,30 @@ public void testBuilder_SetConsumeFalse() {
4851
assertTrue(options.getConsume().isPresent());
4952
assertFalse(options.getConsume().get());
5053
}
54+
55+
@Test
56+
public void testBuilder_SetConsumeOptional_Present() {
57+
VerifyAppCheckTokenOptions options =
58+
VerifyAppCheckTokenOptions.builder().setConsume(Optional.of(true)).build();
59+
assertNotNull(options);
60+
assertTrue(options.getConsume().isPresent());
61+
assertTrue(options.getConsume().get());
62+
}
63+
64+
@Test
65+
public void testBuilder_SetConsumeOptional_Empty() {
66+
VerifyAppCheckTokenOptions options =
67+
VerifyAppCheckTokenOptions.builder().setConsume(Optional.empty()).build();
68+
assertNotNull(options);
69+
assertFalse(options.getConsume().isPresent());
70+
}
71+
72+
@Test
73+
public void testBuilder_SetConsumeOptionalNull_ThrowsException() {
74+
NullPointerException e =
75+
assertThrows(
76+
NullPointerException.class,
77+
() -> VerifyAppCheckTokenOptions.builder().setConsume((Optional<Boolean>) null));
78+
assertEquals("consume must not be null", e.getMessage());
79+
}
5180
}

0 commit comments

Comments
 (0)