### Question:
HttpUtils { static String trimWhitespace(final String token) { checkNotNull(token,"Token cannot be null"); int startOffset=0; int endOffset=token.length(); while(startOffset<endOffset) { final char lastChar=token.charAt(startOffset); if(!HttpUtils.isWhitespace(lastChar)) { break; } startOffset++; } while(endOffset>startOffset) { final char lastChar=token.charAt(endOffset-1); if(!HttpUtils.isWhitespace(lastChar)) { break; } endOffset--; } return token.substring(startOffset,endOffset); } private  HttpUtils();   }### Answer:
@Test public void cannotTrimNull() throws Exception { try { HttpUtils.trimWhitespace(null); fail("Should not trim null"); } catch (NullPointerException e) { assertThat(e.getMessage(),equalTo("Token cannot be null")); } }
@Test public void acceptsEmptyStrings() throws Exception { assertThat(HttpUtils.trimWhitespace(""),equalTo("")); }
@Test public void doesNotTrimUntrimmableStrings() throws Exception { assertThat(HttpUtils.trimWhitespace("text"),equalTo("text")); }
@Test public void trimsLeadingWhitespace() throws Exception { assertThat(HttpUtils.trimWhitespace(" \t \ttext"),equalTo("text")); }
@Test public void trimsTrailingWhitespace() throws Exception { assertThat(HttpUtils.trimWhitespace("text \t \t"),equalTo("text")); }
@Test public void trimsBothEndsWhitespace() throws Exception { assertThat(HttpUtils.trimWhitespace("\t \t text\t \t "),equalTo("text")); }