-
Notifications
You must be signed in to change notification settings - Fork 21
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
[SUREFIRE-1556] fail fast on empty element names #11
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,8 @@ | |
*/ | ||
|
||
import java.io.IOException; | ||
|
||
import javax.swing.text.html.HTML; | ||
import java.io.StringWriter; | ||
import javax.swing.text.html.HTML; | ||
|
||
import org.apache.maven.shared.utils.StringUtils; | ||
import org.junit.Assert; | ||
|
@@ -32,13 +31,25 @@ | |
* Test of {@link PrettyPrintXMLWriter} | ||
* | ||
* @author <a href="mailto:[email protected]">Vincent Siveton</a> | ||
* | ||
*/ | ||
public class PrettyPrintXmlWriterTest | ||
{ | ||
private StringWriter w = new StringWriter(); | ||
private StringWriter w = new StringWriter();; | ||
private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( w ); | ||
|
||
@Test | ||
public void testNoStartTag() throws IOException | ||
{ | ||
|
||
try { | ||
writer.startElement( "" ); | ||
Assert.fail( "allowed empty name" ); | ||
} catch ( IllegalArgumentException ex ) { | ||
Assert.assertEquals( "Element name cannot be empty", ex.getMessage() ); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testDefaultPrettyPrintXMLWriter() throws IOException | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the
expected
property in the annotation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Expected
was a bad design now replaced in JUnit 4.13 withassertThrows
. The problem is that@Expected
captures unexpected exceptions thrown from different parts of the method body and thus hides test failures.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
ExpectedException
which is the Rule in JUnit4.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue. This is not a full replacement for the pattern below and risks false negatives. See https://github.com/junit-team/junit4/wiki/Exception-testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elharo
I am a practicle man. You can of course use [1] with anonymous class instead of Lambda but you can use a traditional ExpectedException with the old version of JUnit.
[1]: https://junit.org/junit4/javadoc/4.13/org/junit/Assert.html#assertThrows(java.lang.String,%20java.lang.Class,%20org.junit.function.ThrowingRunnable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has the same problem. It does not guarantee the expected exception was thrown by the right method. JUnit has rightly backed away from this style of testing exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elharo
In practice the last line with main code must be followed by
e.expect
. So yes there is guarantee. It is clear that only that one line has to throw the exception. If it does not, then theExpectedException
fails the build. That's why it was designed in JUnit4. You can use the newassertThrows
but it has another meaning - wrapping the exception and checking a new errors or exceptions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works and it follows the recommendation of the JUnit Wiki and the design of JUnit from 4.13 onward. I'd like to move ahead with fixing this bug. Can I get an approval for this?