import javax.servlet.http.HttpServletRequest;
import org.sonar.api.server.ws.internal.PartImpl;
import org.sonar.api.server.ws.internal.ValidatingRequest;
+import org.sonar.api.utils.log.Loggers;
import org.sonarqube.ws.MediaTypes;
import static com.google.common.base.MoreObjects.firstNonNull;
}
return new PartImpl(part.getInputStream(), part.getSubmittedFileName());
} catch (Exception e) {
- throw new IllegalStateException("Can't read file part", e);
+ Loggers.get(ServletRequest.class).warn("Can't read file part for parameter " + key, e);
+ return null;
}
}
}
@Test
- public void throw_ISE_when_invalid_part() throws Exception {
+ public void returns_null_when_invalid_part() throws Exception {
when(source.getContentType()).thenReturn("multipart/form-data");
InputStream file = mock(InputStream.class);
Part part = mock(Part.class);
when(part.getInputStream()).thenReturn(file);
doThrow(IllegalArgumentException.class).when(source).getPart("param1");
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Can't read file part");
-
- underTest.readInputStreamParam("param1");
+ assertThat(underTest.readInputStreamParam("param1")).isNull();
}
@Test