Skip to content

More tests for multi-part #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2023
Merged

More tests for multi-part #15

merged 3 commits into from
Sep 27, 2023

Conversation

robotdan
Copy link
Member

No description provided.

Copy link
Contributor

@bhalsey bhalsey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small test suggestion

try {
MultipartStream stream = new MultipartStream(new ByteArrayInputStream(boundary.getBytes()), "----WebKitFormBoundaryTWfMVJErBoLURJIe".getBytes(), 1024);
stream.process(new HashMap<>(), new LinkedList<>());
} catch (ParseException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could catch this exception with the @Test annotation

@Test(expectedExceptions = { ParseException.class })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that it asserts the particular message. It could be rewritten to use JUnit:

ParseException e = assertThrows(
  ParseException.class,
  () -> stream.process(new HashMap<>(), new LinkedList<>())
);
assertEquals(e.getMessage(), "Invalid multipart body. Ran out of data while processing.");

The only real benefit is narrowing the scope of where the exception is thrown, but it's also more testy to write it this way IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, didn't use the built in because we throw that same exception for several reasons, and wanted to ensure we are throwing the one I expect.

However, I see you can add expectedExceptionsMessageRegExp to the @Test annotation, I could try using that in conjection with expectedExceptions - but maybe same difference at that point.

I'll test it and see if it looks cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it worked, will use it.

@robotdan robotdan merged commit 9d0ba3f into master Sep 27, 2023
@robotdan robotdan deleted the degroff/multi-part-tests branch September 27, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants