title: Junit Asserting failed HTTP post request
body: <p>I have an HTTPClient test for my spring boot app. I have a class that throws an exception if the a POST request to the server is in a string 2048 bytes or over. </p>
  
  <pre><code>@Component
   public class ApplicationRequestSizeLimitFilter extends OncePerRequestFilter {
  
      @Override
      protected void doFilterInternal(HttpServletRequest request,
              HttpServletResponse response, FilterChain filterChain)
                      throws ServletException, IOException {
          System.out.println(request.getContentLength());
          if (request.getContentLengthLong() &gt;= 2048) {
              throw new IOException("Request content exceeded limit of 2048 bytes");
          }
          filterChain.doFilter(request, response);
  
      }
  
  
  }
  </code></pre>
  
  <p>I created a unit test for it but I am not sure how I can write an assert statement to check if it fails to post the request. </p>
  
  <p>Right now I have this so far in my test class</p>
  
  <pre><code>@Test
      public void testSize() throws ClientProtocolException, IOException {
          Random r = new Random(123);
          long start = System.currentTimeMillis();
          String s = "";
          for (int i = 0; i &lt; 65536; i++)
              s += r.nextInt(2);
          String result = Request.Post(mockAddress)
                  .connectTimeout(2000)
                  .socketTimeout(2000)
                  .bodyString(s, ContentType.TEXT_PLAIN)
                  .execute().returnContent().asString();
  
      }
  </code></pre>
  
  <p>This test fails which is what I want but I want to create an assert so it passes (assert that it fails the http response due to being over the byte limit).</p>