Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FormParseNodeFactory() {}
Objects.requireNonNull(rawResponse, "parameter rawResponse cannot be null");
if (contentType.isEmpty()) {
throw new NullPointerException("contentType cannot be empty");
} else if (!contentType.equals(validContentType)) {
} else if (!contentType.split(";", 2)[0].trim().equalsIgnoreCase(validContentType)) {
throw new IllegalArgumentException("expected a " + validContentType + " content type");
}
String rawText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FormSerializationWriterFactory() {}
Objects.requireNonNull(contentType, "parameter contentType cannot be null");
if (contentType.isEmpty()) {
throw new NullPointerException("contentType cannot be empty");
} else if (!contentType.equals(validContentType)) {
} else if (!contentType.split(";", 2)[0].trim().equalsIgnoreCase(validContentType)) {
throw new IllegalArgumentException("expected a " + validContentType + " content type");
}
return new FormSerializationWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -37,4 +39,40 @@ public void throwsArgumentNullExceptionForNoContentType() throws UnsupportedEnco
assertThrows(
NullPointerException.class, () -> _parseNodeFactory.getParseNode("", rawResponse));
}

@ParameterizedTest
@ValueSource(
strings = {
"application/x-www-form-urlencoded; charset=utf-8",
"application/x-www-form-urlencoded; charset=UTF-8",
"application/x-www-form-urlencoded; charset=us-ascii",
"APPLICATION/X-WWW-FORM-URLENCODED",
"APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8",
"Application/x-www-form-urlencoded",
"Application/x-www-form-urlencoded; charset=utf-8",
})
public void getsParseNodeForContentTypeWithParametersOrCaseVariants(final String inputType)
throws UnsupportedEncodingException {
final var initialString = "key1=value1&key2=value2";
final var rawResponse = new ByteArrayInputStream(initialString.getBytes("UTF-8"));
final var parseNode = _parseNodeFactory.getParseNode(inputType, rawResponse);
assertNotNull(parseNode);
}

@ParameterizedTest
@ValueSource(
strings = {
";",
";;",
"; charset=utf-8",
" ; charset=utf-8",
})
public void throwsIllegalArgumentExceptionForDelimiterOnlyOrMissingMediaType(
final String inputType) throws UnsupportedEncodingException {
final var initialString = "key1=value1&key2=value2";
final var rawResponse = new ByteArrayInputStream(initialString.getBytes("UTF-8"));
assertThrows(
IllegalArgumentException.class,
() -> _parseNodeFactory.getParseNode(inputType, rawResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class SerializationWriterFactoryTests {
private static final FormSerializationWriterFactory _serializationWriterFactory =
Expand All @@ -30,4 +32,36 @@ public void throwsArgumentNullExceptionForNoContentType() {
NullPointerException.class,
() -> _serializationWriterFactory.getSerializationWriter(""));
}

@ParameterizedTest
@ValueSource(
strings = {
"application/x-www-form-urlencoded; charset=utf-8",
"application/x-www-form-urlencoded; charset=UTF-8",
"application/x-www-form-urlencoded; charset=us-ascii",
"APPLICATION/X-WWW-FORM-URLENCODED",
"APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8",
"Application/x-www-form-urlencoded",
"Application/x-www-form-urlencoded; charset=utf-8",
})
public void getsWriterForContentTypeWithParametersOrCaseVariants(final String inputType) {
final var serializationWriter =
_serializationWriterFactory.getSerializationWriter(inputType);
assertNotNull(serializationWriter);
}

@ParameterizedTest
@ValueSource(
strings = {
";",
";;",
"; charset=utf-8",
" ; charset=utf-8",
})
public void throwsIllegalArgumentExceptionForDelimiterOnlyOrMissingMediaType(
final String inputType) {
assertThrows(
IllegalArgumentException.class,
() -> _serializationWriterFactory.getSerializationWriter(inputType));
}
}
Loading