### Question:
HtmlBody { public String extractInputFieldValueByName(String fieldName) { Elements fields = this.doc.select("input[name=" + fieldName+ "]"); if(fields.size() != 1) { throw new IllegalArgumentException("Could not extract field `" + fieldName + "` since there were more than one" + " or no fields at all within the given body."); } if(Strings.isNullOrEmpty(fields.attr("value"))) { throw new IllegalArgumentException("Could not extract field `" + fieldName + "` since attribute named value is not available."); } return fields.attr("value"); } HtmlBody(String html); String extractInputFieldValueByName(String fieldName); boolean containsId(String id); List<String> extractInputCheckboxNamesByFormId(String formId);  }### Answer:
@Test public void testExtractInputFieldValue_whenFieldIsPresent_shouldReturnValue() { HtmlBody htmlBody = new HtmlBody("<html><input type=\"hidden\" name=\"test\" value=\"val\"></html>"); assertThat(htmlBody.extractInputFieldValueByName("test")).isEqualTo("val"); }
@Test(expected = IllegalArgumentException.class) public void testExtractInputFieldValue_whenFieldNotPresent_shouldThrowException() { HtmlBody htmlBody = new HtmlBody("<html></html>"); htmlBody.extractInputFieldValueByName("test"); }
@Test(expected = IllegalArgumentException.class) public void testExtractInputFieldValue_whenFieldValueNotPresent_shouldThrowException() { HtmlBody htmlBody = new HtmlBody("<html><input type=\"hidden\" name=\"test\"></html>"); htmlBody.extractInputFieldValueByName("test"); }