### Question:
TokenReader extends TokenDecoder { public T read(String base64String) { if (base64String == null || base64String.isEmpty()) { throw new IllegalArgumentException("Impossible to obtain a Token from a null or empty string"); } StringBuilder buffer = new StringBuilder(); BufferedReader reader = new BufferedReader(new StringReader(base64String)); String line = null; try { while ((line = reader.readLine()) != null) { buffer.append(line.trim()); } } catch (IOException e) { } finally { try { reader.close(); } catch (IOException e) { } } Matcher matcher = base64urlTokenPattern.matcher(buffer.toString()); if (!matcher.matches()) { throw new IllegalArgumentException(base64String + "is not a valid Token, it does not match with the pattern: " + base64urlTokenPattern.pattern()); } String header = matcher.group(1); String decodedHeader = base64Decode(header); String body = matcher.group(2); String decodedBody = base64Decode(body); String signature = matcher.group(3); return build(base64String, decodedHeader, decodedBody, signature); }  T read(String base64String);  }### Answer:
@Test public void test_read2() { tokenReader = new TokenReader<String>() { protected String build(String rawString, String decodedHeader, String decodedBody, String encodedSignature) { return null; } }; String accessToken = "BadToken"; try { tokenReader.read(accessToken); Assert.fail("failed test"); }catch (IllegalArgumentException e) { } }
@Test public void test_read() { tokenReader = new TokenReader<String>() { protected String build(String rawString, String decodedHeader, String decodedBody, String encodedSignature) { return ""; } }; String accessToken = "eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"; Assert.assertNotNull(tokenReader.read(accessToken)); }