Skip to content

Commit 03e1be1

Browse files
committed
add unit tests for appchecktokenresponse
1 parent 2cdabc5 commit 03e1be1

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.appcheck;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
22+
import static org.junit.Assert.assertThrows;
23+
import static org.junit.Assert.assertTrue;
24+
25+
import com.google.common.collect.ImmutableMap;
26+
import org.junit.Test;
27+
28+
public class VerifyAppCheckTokenResponseTest {
29+
30+
private static final String APP_ID = "test-app-id";
31+
private static final DecodedAppCheckToken DECODED_TOKEN =
32+
new DecodedAppCheckToken(ImmutableMap.<String, Object>of("sub", APP_ID));
33+
34+
@Test
35+
public void testNullAppId_ThrowsException() {
36+
NullPointerException e =
37+
assertThrows(
38+
NullPointerException.class,
39+
() -> new VerifyAppCheckTokenResponse(null, DECODED_TOKEN, null));
40+
assertTrue(e.getMessage().contains("appId must not be null"));
41+
}
42+
43+
@Test
44+
public void testNullToken_ThrowsException() {
45+
NullPointerException e =
46+
assertThrows(
47+
NullPointerException.class,
48+
() -> new VerifyAppCheckTokenResponse(APP_ID, null, null));
49+
assertTrue(e.getMessage().contains("token must not be null"));
50+
}
51+
52+
@Test
53+
public void testGetters_WithoutAlreadyConsumed() {
54+
VerifyAppCheckTokenResponse response =
55+
new VerifyAppCheckTokenResponse(APP_ID, DECODED_TOKEN, null);
56+
57+
assertNotNull(response);
58+
assertEquals(APP_ID, response.getAppId());
59+
assertEquals(DECODED_TOKEN, response.getToken());
60+
assertFalse(response.isAlreadyConsumed().isPresent());
61+
}
62+
63+
@Test
64+
public void testGetters_WithAlreadyConsumedTrue() {
65+
VerifyAppCheckTokenResponse response =
66+
new VerifyAppCheckTokenResponse(APP_ID, DECODED_TOKEN, true);
67+
68+
assertNotNull(response);
69+
assertEquals(APP_ID, response.getAppId());
70+
assertEquals(DECODED_TOKEN, response.getToken());
71+
assertTrue(response.isAlreadyConsumed().isPresent());
72+
assertTrue(response.isAlreadyConsumed().get());
73+
}
74+
75+
@Test
76+
public void testGetters_WithAlreadyConsumedFalse() {
77+
VerifyAppCheckTokenResponse response =
78+
new VerifyAppCheckTokenResponse(APP_ID, DECODED_TOKEN, false);
79+
80+
assertNotNull(response);
81+
assertEquals(APP_ID, response.getAppId());
82+
assertEquals(DECODED_TOKEN, response.getToken());
83+
assertTrue(response.isAlreadyConsumed().isPresent());
84+
assertFalse(response.isAlreadyConsumed().get());
85+
}
86+
}

0 commit comments

Comments
 (0)