Skip to content

Commit

Permalink
Migrate some unit tests to Junit Jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeantessier committed Jan 9, 2025
1 parent 5d836ee commit 73c4937
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,34 @@

package com.jeantessier.dependencyfinder.cli;

import org.junit.jupiter.api.*;

import java.io.*;
import java.util.*;

import junit.framework.*;
import static org.junit.jupiter.api.Assertions.*;

public class TestCommand extends TestCase {
public class TestCommand {
private File outFile;
private String[] args;

protected void setUp() throws Exception {
super.setUp();
@BeforeEach
void setUp() throws Exception {
var random = new Random();
var tempName = "temp" + random.nextInt(1_000);

outFile = File.createTempFile(getName(), "");
assertTrue("Temp file " + outFile + " not deleted", outFile.delete());
outFile = File.createTempFile(tempName, "");
outFile.deleteOnExit();
assertTrue(outFile.delete(), "Temp file " + outFile + " could not be deleted");

args = new String[] {
"-out",
outFile.getAbsolutePath(),
};
}

protected void tearDown() throws Exception {
if (outFile.exists()) {
outFile.delete();
}

super.tearDown();
}

public void testOutNotCreatedIfNotAccessed() throws Exception {
@Test
void testOutNotCreatedIfNotAccessed() throws Exception {
Command sut = new Command() {
protected void doProcessing() throws Exception {
// Do Nothing
Expand All @@ -71,12 +70,13 @@ protected void showSpecificUsage(PrintStream out) {
}
};

assertFalse("Output file " + outFile + " exists before test", outFile.exists());
assertFalse(outFile.exists(), "Output file " + outFile + " exists before test");
sut.run(args);
assertFalse("Output file " + outFile + " exists after test", outFile.exists());
assertFalse(outFile.exists(), "Output file " + outFile + " exists after test");
}

public void testOutCreatedAfterAccess() throws Exception {
@Test
void testOutCreatedAfterAccess() throws Exception {
Command sut = new Command() {
protected void doProcessing() throws Exception {
getOut();
Expand All @@ -87,8 +87,8 @@ protected void showSpecificUsage(PrintStream out) {
}
};

assertFalse("Output file " + outFile + " exists before test", outFile.exists());
assertFalse(outFile.exists(), "Output file " + outFile + " exists before test");
sut.run(args);
assertTrue("Output file " + outFile + " does not exist after test", outFile.exists());
assertTrue(outFile.exists(), "Output file " + outFile + " does not exist after test");
}
}

0 comments on commit 73c4937

Please sign in to comment.