### Question:
FormElement extends Element { public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); } FormElement(Tag tag, String baseUri, Attributes attributes); Elements elements(); FormElement addElement(Element element); Connection submit(); List<Connection.KeyVal> formData();  }### Answer:
@Test public void createsSubmitableConnection() { String html = "<form action='/search'><input name='q'></form>"; Document doc = Jsoup.parse(html, "http: doc.select("[name=q]").attr("value", "jsoup"); FormElement form = ((FormElement) doc.select("form").first()); Connection con = form.submit(); assertEquals(Connection.Method.GET, con.request().method()); assertEquals("http: List<Connection.KeyVal> dataList = (List<Connection.KeyVal>) con.request().data(); assertEquals("q=jsoup", dataList.get(0).toString()); doc.select("form").attr("method", "post"); Connection con2 = form.submit(); assertEquals(Connection.Method.POST, con2.request().method()); }
@Test public void actionWithNoValue() { String html = "<form><input name='q'></form>"; Document doc = Jsoup.parse(html, "http: FormElement form = ((FormElement) doc.select("form").first()); Connection con = form.submit(); assertEquals("http: }
@Test public void actionWithNoBaseUri() { String html = "<form><input name='q'></form>"; Document doc = Jsoup.parse(html); FormElement form = ((FormElement) doc.select("form").first()); boolean threw = false; try { Connection con = form.submit(); } catch (IllegalArgumentException e) { threw = true; assertEquals("Could not determine a form action URL for submit. Ensure you set a base URI when parsing.", e.getMessage()); } assertTrue(threw); }