use of com.microsoft.identity.common.internal.controllers.BrokerMsalController in project microsoft-authentication-library-common-for-android by AzureAD.
the class HelloCacheTests method testHelloShouldOnlyTriggerOnce.
@Test
public void testHelloShouldOnlyTriggerOnce() {
final String minimumVer = "1.0";
final String negotiatedVer = "2.5";
class MockStrategy implements IIpcStrategy {
int triggered = 0;
@Nullable
@Override
public Bundle communicateToBroker(@NonNull BrokerOperationBundle bundle) throws BrokerCommunicationException {
triggered += 1;
if (triggered == 2) {
Assert.fail("Should never be triggered");
}
final Bundle resultBundle = new Bundle();
resultBundle.putString(NEGOTIATED_BP_VERSION_KEY, negotiatedVer);
return resultBundle;
}
@Override
public Type getType() {
return Type.CONTENT_PROVIDER;
}
}
class MockController extends BrokerMsalController {
public MockController(Context applicationContext) {
super(applicationContext);
}
@Override
public HelloCache getHelloCache() {
return HelloCacheTests.this.getHelloCache(protocolA);
}
@Override
public String getActiveBrokerPackageName() {
return brokerAppName;
}
}
final MockController controller = new MockController(ApplicationProvider.getApplicationContext());
final MockStrategy strategy = new MockStrategy();
final CommandParameters parameters = CommandParameters.builder().requiredBrokerProtocolVersion(minimumVer).build();
try {
final String negotiatedProtocolVersion = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
final String negotiatedProtocolVersion2 = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
Assert.assertEquals(negotiatedProtocolVersion, negotiatedProtocolVersion2);
} catch (BaseException e) {
Assert.fail();
}
}
Aggregations