MapzenRouterHttpHandler implements GenericHttpHandler { @NonNull TurnByTurnHttpHandler turnByTurnHandler() { return handler; } MapzenRouterHttpHandler(@NonNull Context context);  MapzenRouterHttpHandler(@NonNull Context context, @NonNull String url,
      @NonNull LogLevel logLevel);  static final String DEFAULT_URL; static final LogLevel DEFAULT_LOG_LEVEL; }
@Test public void init_shouldSetApiKey() throws Exception { MapzenRouterHttpHandler.ChainProceder proceder = mock( MapzenRouterHttpHandler.ChainProceder.class); httpHandler.chainProceder = proceder; Interceptor.Chain chain = mock(Interceptor.Chain.class); httpHandler.turnByTurnHandler().onRequest(chain); Map params = new HashMap(); params.put(NAME_API_KEY, "fake-mapzen-api-key"); Map headers = new HashMap(); headers.put(HEADER_USER_AGENT, USER_AGENT); verify(proceder).proceed(chain, params, headers); }
@Test public void init_shouldUpdateApiKey() throws Exception { MapzenManager.instance(context).setApiKey("updated-mapzen-api-key"); MapzenRouterHttpHandler.ChainProceder proceder = mock( MapzenRouterHttpHandler.ChainProceder.class); httpHandler.chainProceder = proceder; Interceptor.Chain chain = mock(Interceptor.Chain.class); httpHandler.turnByTurnHandler().onRequest(chain); Map params = new HashMap(); params.put(NAME_API_KEY, "updated-mapzen-api-key"); Map headers = new HashMap(); headers.put(HEADER_USER_AGENT, USER_AGENT); verify(proceder).proceed(chain, params, headers); }
@Test public void onRequest_shouldProceedWithDefaultParamsAndHeaders() throws Exception { httpHandler.turnByTurnHandler().setApiKey("test-key"); MapzenRouterHttpHandler.ChainProceder proceder = mock( MapzenRouterHttpHandler.ChainProceder.class); httpHandler.chainProceder = proceder; Interceptor.Chain chain = mock(Interceptor.Chain.class); httpHandler.turnByTurnHandler().onRequest(chain); Map params = new HashMap(); params.put(NAME_API_KEY, "test-key"); Map headers = new HashMap(); headers.put(HEADER_USER_AGENT, USER_AGENT); verify(proceder).proceed(chain, params, headers); }
@Test public void onRequest_shouldProceedWithAllParamsAndHeaders() throws Exception { httpHandler.turnByTurnHandler().setApiKey("test-key"); MapzenRouterHttpHandler.ChainProceder proceder = mock( MapzenRouterHttpHandler.ChainProceder.class); httpHandler.chainProceder = proceder; Interceptor.Chain chain = mock(Interceptor.Chain.class); testParams = new HashMap(); testParams.put("param", "value"); testHeaders = new HashMap(); testHeaders.put("header", "value"); httpHandler.turnByTurnHandler().onRequest(chain); Map params = new HashMap(); params.put(NAME_API_KEY, "test-key"); params.putAll(testParams); Map headers = new HashMap(); headers.put(HEADER_USER_AGENT, USER_AGENT); headers.putAll(testHeaders); verify(proceder).proceed(chain, params, headers); }
@Test public void initWithCustomUrlAndLogLevelShouldCallConstructor() throws Exception { MapzenRouterHttpHandler handler = new MapzenRouterHttpHandler(context, "http: GenericHttpHandler.LogLevel.BODY) { @Override public Map<String, String> queryParamsForRequest() { return null; } @Override public Map<String, String> headersForRequest() { return null; } }; String endpoint = TestHttpHandlerHelper.getEndpoint(handler.turnByTurnHandler()); assertThat(endpoint).isEqualTo("http: HttpLoggingInterceptor.Level level = TestHttpHandlerHelper.getLogLevel( handler.turnByTurnHandler()); assertThat(level).isEqualTo(HttpLoggingInterceptor.Level.BODY); }