### Question:
TokenUtils { static String[] splitToken(String token) throws JWTDecodeException { String[] parts = token.split("\\."); if (parts.length == 2 && token.endsWith(".")) { parts = new String[]{parts[0], parts[1], ""}; } if (parts.length != 3) { throw new JWTDecodeException(String.format("The token was expected to have 3 parts, but got %s.", parts.length)); } return parts; }    }### Answer:
@Test public void shouldSplitToken() throws Exception { String token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJhdXRoMCJ9.W1mx_Y0hbAMbPmfW9whT605AAcxB7REFuJiDAHk2Sdc"; String[] parts = TokenUtils.splitToken(token); assertThat(parts, is(notNullValue())); assertThat(parts, is(arrayWithSize(3))); assertThat(parts[0], is("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0")); assertThat(parts[1], is("eyJpc3MiOiJhdXRoMCJ9")); assertThat(parts[2], is("W1mx_Y0hbAMbPmfW9whT605AAcxB7REFuJiDAHk2Sdc")); }
@Test public void shouldSplitTokenWithEmptySignature() throws Exception { String token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJhdXRoMCJ9."; String[] parts = TokenUtils.splitToken(token); assertThat(parts, is(notNullValue())); assertThat(parts, is(arrayWithSize(3))); assertThat(parts[0], is("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0")); assertThat(parts[1], is("eyJpc3MiOiJhdXRoMCJ9")); assertThat(parts[2], is(isEmptyString())); }
@Test public void shouldThrowOnSplitTokenWithMoreThan3Parts() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The token was expected to have 3 parts, but got 4."); String token = "this.has.four.parts"; TokenUtils.splitToken(token); }
@Test public void shouldThrowOnSplitTokenWithLessThan3Parts() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The token was expected to have 3 parts, but got 2."); String token = "two.parts"; TokenUtils.splitToken(token); }