### Question:
HS256Helper { public String answerAsString() { if (result == null) { return null; } return Base64.encode(result); } HS256Helper(byte[] secret, String challenge); String answerAsString(); byte[] answerAsBytes(); void setSecret(byte[] secret); void setChallenge(String challenge);  }### Answer:
@Test public void shouldPass() { byte[] secretBytes = new byte[32]; secureRandom.nextBytes(secretBytes); String challenge = "challenge"; String response = figureResponse(secretBytes, challenge); HS256Helper helper = new HS256Helper(secretBytes, challenge); String result = helper.answerAsString(); assertThat(result).isEqualTo(response); }
@Test public void shouldReturnNullWithNullSecret() { byte[] secretBytes = null; String challenge = "challenge"; HS256Helper helper = new HS256Helper(secretBytes, challenge); String result = helper.answerAsString(); assertThat(result).isNull(); }
@Test public void shouldReturnWithNullChallenge() { byte[] secretBytes = new byte[32]; String answer = "thNnmggU2ex3L5XXeMNfxf8Wl8STcVZTxscSFEKSxa0="; String challenge = null; HS256Helper helper = new HS256Helper(secretBytes, challenge); String result = helper.answerAsString(); assertThat(result).isEqualTo(answer); }