Skip to content
Open
Changes from 1 commit
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 @@ -38,7 +38,13 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.when;

/**
Expand Down Expand Up @@ -116,7 +122,7 @@ void testEmptyFileList() throws EnforcerRuleException, IOException {
void testFileDoesNotExist() throws IOException {
File f = File.createTempFile("junit", null, temporaryFolder);
f.delete();
assertFalse(f.exists());
assumeFalse(f.exists());
Comment on lines -127 to +129
Copy link
Member

Choose a reason for hiding this comment

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

It will change test logic ... at all
When file will be not deleted .. test will be marked as skipped not failed

Is it intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we don't want to test that the JDK's delete method works as expected, and if the code under test isn't even executed then the test has been skipped, not failed. This case inspired me to write https://cafe.elharo.com/testing/assume-vs-assert/

rule.setFilesList(Collections.singletonList(f));

try {
Expand Down Expand Up @@ -149,7 +155,7 @@ void testFileTooBig() throws IOException {

rule.setFilesList(Collections.singletonList(f));
rule.setMaxsize(10);
assertTrue(f.length() > 10);
assumeTrue(f.length() > 10);
try {
rule.execute();
fail("Should get exception");
Expand All @@ -164,7 +170,7 @@ void testRequireFilesSizeSatisfyAny() throws EnforcerRuleException, IOException
try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) {
out.write("123456789101112131415");
}
assertTrue(f.length() > 10);
assumeTrue(f.length() > 10);

File g = File.createTempFile("junit", null, temporaryFolder);

Expand Down
Loading