### Question:
Parser { AccountFormData parseAccountForm(final String body) { final Document document = Jsoup.parse(body); final Element form = document.selectFirst("#js_account_form"); if (form == null) { throw new RuntimeException("Account form element not found."); } return AccountFormData.builder() .authenticityToken(parseAuthenticityToken(form)) .name(parseName(form)) .build(); }    }### Answer:
@Test public void parseAccountFormTest() { final var expected = Parser.AccountFormData.builder() .authenticityToken("TOKEN") .name("NAME") .build(); final var actual = parser.parseAccountForm( "<html><body><form id=\"js_account_form\">" + "<input name=\"name\" value=\"NAME\">" + "<input name=\"authenticity_token\" value=\"TOKEN\">" + "</form></body></html>"); assertEquals(expected, actual); }
@Test public void parseAccountFormTest_noFormElement() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Account form element not found."); parser.parseAccountForm("<html><body></body></html>"); }
@Test public void parseAccountFormTest_noNameElement() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Name element not found."); parser.parseAccountForm( "<html><body><form id=\"js_account_form\">" + "<input name=\"authenticity_token\" value=\"TOKEN\">" + "</form></body></html>"); }
@Test public void parseAccountFormTest_noNameValue() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("`name` is not found."); parser.parseAccountForm( "<html><body><form id=\"js_account_form\">" + "<input name=\"name\" value=\"\">" + "<input name=\"authenticity_token\" value=\"TOKEN\">" + "</form></body></html>"); }
@Test public void parseAccountFormTest_noAuthenticityTokenElement() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Authenticity token element not found."); parser.parseAccountForm( "<html><body><form id=\"js_account_form\">" + "<input name=\"name\" value=\"NAME\">" + "</form></body></html>"); }
@Test public void parseAccountFormTest_noAuthenticityTokenValue() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("`authenticity_token` is not found."); parser.parseAccountForm( "<html><body><form id=\"js_account_form\">" + "<input name=\"name\" value=\"NAME\">" + "<input name=\"authenticity_token\" value=\"\">" + "</form></body></html>"); }