- Collection<String> values = requestParameters.get(parameter);
- return requestParameters.containsKey(parameter) ? values.iterator().next().substring(0, Math.min(maxLength, values.iterator().next().length())) : "";
+ String value = requestParts.get(parameter);
+ return requestParts.containsKey(parameter) ? value.substring(0, Math.min(maxLength, value.length())) : "";
+ }
+ });
+ when(httpRequest.getPartAsStringThrowing(anyString(), anyInt())).thenAnswer(new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ String partName = invocation.getArgument(0);
+ if (!requestParts.containsKey(partName)) throw new NoSuchElementException();
+ String partValue = requestParts.get(partName);
+ if (partValue.length() > invocation.<Integer>getArgument(1)) throw new SizeLimitExceededException();
+ return partValue;