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