### Question:
Gateway { String getApiUrl(String apiVersion) { if (Integer.valueOf(apiVersion) < MIN_API_VERSION) { throw new IllegalArgumentException("API version must be >= " + MIN_API_VERSION); } if (region == null) { throw new IllegalStateException("You must initialize the the Gateway instance with a Region before use"); } return "https: } Gateway(); String getMerchantId(); Gateway setMerchantId(String merchantId); Region getRegion(); Gateway setRegion(Region region); void updateSession(String sessionId, String apiVersion, GatewayMap payload, GatewayCallback callback); Single<GatewayMap> updateSession(String sessionId, String apiVersion, GatewayMap payload); static void start3DSecureActivity(Activity activity, String html); static void start3DSecureActivity(Activity activity, String html, String title); static boolean handle3DSecureResult(int requestCode, int resultCode, Intent data, Gateway3DSecureCallback callback); static void requestGooglePayData(PaymentsClient paymentsClient, PaymentDataRequest request, Activity activity); static boolean handleGooglePayResult(int requestCode, int resultCode, Intent data, GatewayGooglePayCallback callback);  }### Answer:
@Test public void testGetApiUrlThrowsExceptionIfRegionIsNull() throws Exception { String apiVersion = "44"; gateway.region = null; try { String apiUrl = gateway.getApiUrl(apiVersion); fail("Null region should have caused illegal state exception"); } catch (Exception e) { assertTrue(e instanceof IllegalStateException); } }
@Test public void testGetApiUrlThrowsExceptionIfApiVersionIsLessThanMin() throws Exception { String apiVersion = String.valueOf(Gateway.MIN_API_VERSION - 1); try { String apiUrl = gateway.getApiUrl(apiVersion); fail("Api version less than minimum value should have caused illegal argument exception"); } catch (Exception e) { assertTrue(e instanceof IllegalArgumentException); } }
@Test public void testGetApiUrlWorksAsIntended() throws Exception { gateway.region = Gateway.Region.NORTH_AMERICA; String expectedUrl = "https: assertEquals(expectedUrl, gateway.getApiUrl(String.valueOf(Gateway.MIN_API_VERSION))); }