use of org.edx.mobile.http.interceptor.NewVersionBroadcastInterceptor in project edx-app-android by edx.
the class NewVersionAvailableEventTest method postAndRemoveEventFromInterceptor.
/**
* Post the provided data by passing the appropriate headers and status code in a request chain
* through an {@link NewVersionBroadcastInterceptor}, then remove the sticky event from the
* event bus.
*
* @param newVersion The new version.
* @param lastSupportedDate The last supported date.
* @param isUnsupported Whether the current version is unsupported.
* @return The event that was posted. This can be null if the data does not constitute a valid
* event.
*/
@Nullable
private static NewVersionAvailableEvent postAndRemoveEventFromInterceptor(@Nullable final Version newVersion, @Nullable final Date lastSupportedDate, final boolean isUnsupported) throws IOException {
// This will throw an AssumptionViolatedException if the Android runtime
// isn't loaded (i.e. through using the Robolectric test runner).
final EventBus eventBus = getEventBus();
eventBus.removeStickyEvent(NewVersionAvailableEvent.class);
final NewVersionAvailableEvent event = postEventFromInterceptor(new NewVersionBroadcastInterceptor(), newVersion, lastSupportedDate, isUnsupported);
if (event != null) {
assertTrue(eventBus.removeStickyEvent(event));
}
return event;
}
use of org.edx.mobile.http.interceptor.NewVersionBroadcastInterceptor in project edx-app-android by edx.
the class NewVersionAvailableEventTest method postEventFromInterceptor.
/**
* Post the provided data by passing the appropriate headers and status code in a request chain
* through an {@link NewVersionBroadcastInterceptor}.
*
* @param interceptor The interceptor through which the data is to be posted.
* @param newVersion The new version.
* @param lastSupportedDate The last supported date.
* @param isUnsupported Whether the current version is unsupported.
* @return The posted event. This can be null if the data does not constitute a valid event.
*/
@Nullable
private static NewVersionAvailableEvent postEventFromInterceptor(@NonNull final NewVersionBroadcastInterceptor interceptor, @Nullable final Version newVersion, @Nullable final Date lastSupportedDate, final boolean isUnsupported) throws IOException {
// This will throw an AssumptionViolatedException if the Android runtime
// isn't loaded (i.e. through using the Robolectric test runner).
final EventBus eventBus = getEventBus();
eventBus.removeStickyEvent(NewVersionAvailableEvent.class);
final Interceptor.Chain chain = mock(Interceptor.Chain.class);
final Request request = new Request.Builder().url("https://localhost:1/").build();
final Response response;
{
final Response.Builder responseBuilder = new Response.Builder();
responseBuilder.request(request);
responseBuilder.protocol(Protocol.HTTP_1_1);
responseBuilder.code(isUnsupported ? UPGRADE_REQUIRED : ACCEPTED);
if (newVersion != null) {
responseBuilder.header(HEADER_APP_LATEST_VERSION, newVersion.toString());
}
if (lastSupportedDate != null) {
responseBuilder.header(HEADER_APP_VERSION_LAST_SUPPORTED_DATE, ISO8601Utils.format(lastSupportedDate, true));
}
response = responseBuilder.build();
}
when(chain.request()).thenReturn(request);
when(chain.proceed(request)).thenReturn(response);
interceptor.intercept(chain);
final InOrder inOrder = inOrder(chain);
inOrder.verify(chain).request();
inOrder.verify(chain).proceed(request);
verifyNoMoreInteractions(chain);
return eventBus.getStickyEvent(NewVersionAvailableEvent.class);
}
Aggregations