I am creating some unit testing and trying to make some calls. Here is what I have in my working code:
String soapRequest = (SimUtil.readInputStream(request.getInputStream())).toString(); if (soapRequest.equals("My String")) { ... }
and SimUtil.readInputSteam looks like this:
StringBuffer sb = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(inputStream)); final int buffSize = 1024; char[] buf = new char[buffSize]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); sb.append(readData); buf = new char[buffSize]; } } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { LOG.error(e.getMessage(), e); } }
What I'm trying to do is request.getInputStream (), the stream returns a specific string.
HttpServletRequest request = mock(HttpServletRequest.class); ServletInputStream inputStream = mock(ServletInputStream.class); when(request.getInputStream()).thenReturn(inputStream);
So this is the code I want to set
when(inputStream.read()).thenReturn("My String".toInt());
Any help would be greatly appreciated.
Churk source share