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