Skip to content

Commit 72adf81

Browse files
committed
Add common4j-local unit tests for new onboarding fields
The Common Code Coverage Compare PR-vs-Dev pipeline only counts coverage contributed by tests in the same module as the production code. Our existing adapter round-trip tests live in common (Robolectric) and exercise the common4j fields indirectly through Gson/Lombok-generated getters/setters, but those calls don't show up in the common4j JaCoCo report. Adds two small common4j-local unit test classes that directly exercise the new fields, restoring full coverage on the changed lines: - AcquireTokenResultTest: getOnboardingBlob/setOnboardingBlob with default, set, and clear cases. - InteractiveTokenCommandParametersTest: getOnboardingSeedJson default and round-trip through the Lombok builder.
1 parent 255d966 commit 72adf81

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.common.java.commands.parameters;
24+
25+
import static org.mockito.Mockito.mock;
26+
27+
import com.microsoft.identity.common.java.interfaces.IPlatformComponents;
28+
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
32+
/**
33+
* Tests for {@link InteractiveTokenCommandParameters} accessors, including the onboarding
34+
* telemetry seed JSON field carried into the broker IPC request bundle.
35+
*/
36+
public class InteractiveTokenCommandParametersTest {
37+
38+
@Test
39+
public void onboardingSeedJson_DefaultsToNull() {
40+
final InteractiveTokenCommandParameters params = InteractiveTokenCommandParameters.builder()
41+
.platformComponents(mock(IPlatformComponents.class))
42+
.build();
43+
Assert.assertNull(params.getOnboardingSeedJson());
44+
}
45+
46+
@Test
47+
public void onboardingSeedJson_RoundTripsThroughBuilder() {
48+
final String seedJson = "{\"schema_version\":\"1.0.0\","
49+
+ "\"session_correlation_id\":\"abc-123\","
50+
+ "\"onboarding_mode\":\"brokered\"}";
51+
final InteractiveTokenCommandParameters params = InteractiveTokenCommandParameters.builder()
52+
.platformComponents(mock(IPlatformComponents.class))
53+
.onboardingSeedJson(seedJson)
54+
.build();
55+
Assert.assertEquals(seedJson, params.getOnboardingSeedJson());
56+
}
57+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.common.java.result;
24+
25+
import org.junit.Assert;
26+
import org.junit.Test;
27+
28+
/**
29+
* Tests for {@link AcquireTokenResult} accessors, including the onboarding telemetry blob
30+
* field used to convey broker-side onboarding telemetry back to the client.
31+
*/
32+
public class AcquireTokenResultTest {
33+
34+
@Test
35+
public void onboardingBlob_DefaultsToNull() {
36+
final AcquireTokenResult result = new AcquireTokenResult();
37+
Assert.assertNull(result.getOnboardingBlob());
38+
}
39+
40+
@Test
41+
public void onboardingBlob_RoundTripsThroughSetter() {
42+
final String blobJson = "{\"schema_version\":\"1.0.0\","
43+
+ "\"session_correlation_id\":\"abc-123\","
44+
+ "\"onboarding_mode\":\"brokered\"}";
45+
final AcquireTokenResult result = new AcquireTokenResult();
46+
result.setOnboardingBlob(blobJson);
47+
Assert.assertEquals(blobJson, result.getOnboardingBlob());
48+
}
49+
50+
@Test
51+
public void onboardingBlob_NullSetterClearsValue() {
52+
final AcquireTokenResult result = new AcquireTokenResult();
53+
result.setOnboardingBlob("non-null");
54+
result.setOnboardingBlob(null);
55+
Assert.assertNull(result.getOnboardingBlob());
56+
}
57+
}

0 commit comments

Comments
 (0)