RequestBuffer extends ByteArrayOutputStream { public boolean allDiscardableContent() { int size = size(); if (size == 0) { return true; } for(int i = 0; i < size; i ++) { if (!isDiscardableChar((char)buf[i])) { return false; } } return true; }  static boolean isDiscardableChar(char b); boolean allDiscardableContent();  }
@Test public void allDiscardableContent_EmptyBuffer() throws Exception { RequestBuffer buffer = new RequestBuffer(); assertEquals(0 , buffer.size()); assertTrue(buffer.allDiscardableContent()); }
@Test public void allDiscardableContent_DiscardableCharacters() throws Exception { RequestBuffer buffer = new RequestBuffer(); buffer.write(' '); buffer.write('\t'); buffer.write('\r'); buffer.write('\t'); assertTrue(buffer.allDiscardableContent()); }
@Test public void allDiscardableContent_LastOneIsNotDiscardable() throws Exception { RequestBuffer buffer = new RequestBuffer(); buffer.write(' '); buffer.write('\t'); buffer.write('\r'); buffer.write('\t'); buffer.write('H'); assertFalse(buffer.allDiscardableContent()); }