EventResponse { int getMinBatchInterval() { if (response.getResponseHeaders() != null) { List<String> headerList = response.getResponseHeaders().get("X-UA-Min-Batch-Interval"); if (headerList != null && headerList.size() > 0) { return UAMathUtil.constrain(Integer.parseInt(headerList.get(0)), MIN_BATCH_INTERVAL_MS, MAX_BATCH_INTERVAL_MS); } } return MIN_BATCH_INTERVAL_MS; } EventResponse(@NonNull Response<Void> response); int getStatus();  }
@Test public void testMinBatchInterval() { List<String> stringList = new ArrayList<>(); stringList.add(0, String.valueOf(EventResponse.MAX_BATCH_INTERVAL_MS)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should constrain to the max", eventResponse.getMinBatchInterval(), EventResponse.MAX_BATCH_INTERVAL_MS); stringList.add(0, String.valueOf(EventResponse.MAX_BATCH_INTERVAL_MS + 1)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should constrain to the max", eventResponse.getMinBatchInterval(), EventResponse.MAX_BATCH_INTERVAL_MS); stringList.add(0, String.valueOf(EventResponse.MAX_BATCH_INTERVAL_MS - 1)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should allow values between the min and max", eventResponse.getMinBatchInterval(), EventResponse.MAX_BATCH_INTERVAL_MS - 1); stringList.add(0, String.valueOf(EventResponse.MIN_BATCH_INTERVAL_MS)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should constrain to the min", eventResponse.getMinBatchInterval(), EventResponse.MIN_BATCH_INTERVAL_MS); stringList.add(0, String.valueOf(EventResponse.MIN_BATCH_INTERVAL_MS - 1)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should constrain to the min", eventResponse.getMinBatchInterval(), EventResponse.MIN_BATCH_INTERVAL_MS); stringList.add(0, String.valueOf(EventResponse.MIN_BATCH_INTERVAL_MS + 1)); responseHeaders.put("X-UA-Min-Batch-Interval", stringList); assertEquals("Should allow values between the min and max", eventResponse.getMinBatchInterval(), EventResponse.MIN_BATCH_INTERVAL_MS + 1); }