Skip to content

Commit

Permalink
Merge pull request square#1705 from Wopple/master-wopple
Browse files Browse the repository at this point in the history
Relaxed FormEncodingBuilder to allow building empty forms.
  • Loading branch information
swankjesse committed Jun 16, 2015
2 parents 65b703f + c16d7cc commit b262f2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,15 @@ public final class FormEncodingBuilderTest {
formEncoding.writeTo(buffer);
assertEquals(expected, buffer.readUtf8());
}

@Test public void buildEmptyForm() throws Exception {
RequestBody formEncoding = new FormEncodingBuilder().build();

String expected = "";
assertEquals(expected.length(), formEncoding.contentLength());

Buffer buffer = new Buffer();
formEncoding.writeTo(buffer);
assertEquals(expected, buffer.readUtf8());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public FormEncodingBuilder addEncoded(String name, String value) {
}

public RequestBody build() {
if (content.size() == 0) {
throw new IllegalStateException("Form encoded body must have at least one part.");
}
return RequestBody.create(CONTENT_TYPE, content.snapshot());
}
}

0 comments on commit b262f2a

Please sign in to comment.