Skip to content

Commit

Permalink
Change synchronized initialisation to BeforeAll
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed Jun 28, 2023
1 parent 5148f3b commit 46b2532
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Locale;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import uk.ac.sussex.gdsc.core.ij.RecorderUtils.ImageJRecorderCommand;
import uk.ac.sussex.gdsc.core.ij.RecorderUtils.RecorderCommand;
Expand Down Expand Up @@ -147,13 +148,8 @@ static String trimKey(String key) {
/** The recorder instance. */
static RecorderCommand recorder = null;

@AfterAll
public static void afterAll() {
// Allow GC to do its work
recorder = null;
}

private static synchronized void initialise() {
@BeforeAll
public static void beforeAll() {
if (GraphicsEnvironment.isHeadless()) {
// Exercise the default
ImageJRecorderCommand.INSTANCE.setCommand(null);
Expand All @@ -172,12 +168,17 @@ private static synchronized void initialise() {
}
}

@AfterAll
public static void afterAll() {
// Allow GC to do its work
recorder = null;
}

/**
* No assertions. This just hits code coverage when the command name or options are null.
*/
@Test
void canResetRecorderWithNoCommand() {
initialise();
recorder.saveCommand();
recorder.setCommand(null);
final String[] keys = {"1", "2"};
Expand All @@ -188,7 +189,6 @@ void canResetRecorderWithNoCommand() {

@Test
void testWrapEmptyStrings() {
initialise();
recorder.saveCommand();
recorder.setCommand("test");
recorder.recordOption("a", "1");
Expand All @@ -203,7 +203,6 @@ void testWrapEmptyStrings() {

@Test
void canResetRecorderWithPlainValues() {
initialise();
canResetRecorder(toArray("a", "b"), toArray("1", "2"), toArray("c", "d"), toArray("3", "4"),
null);
canResetRecorder(toArray("a", "b"), toArray("1", "2"), toArray("c", "d"), toArray("3", "4"),
Expand All @@ -220,7 +219,6 @@ void canResetRecorderWithPlainValues() {

@Test
void canResetRecorderWithQuotedValues() {
initialise();
canResetRecorder(toArray("a", "b"), toArray("1 1", "2 2"), toArray("c", "d"),
toArray("3 3", "4 4"), null);
canResetRecorder(toArray("a", "b"), toArray("1 1", "2 2"), toArray("c", "d"),
Expand Down Expand Up @@ -301,7 +299,6 @@ void canResetRecorderWithQuotedValues() {

@Test
void resetRecorderIgnoresInvalidKeys() {
initialise();
canResetRecorder(toArray("a", "b"), toArray("1", "2"), toArray("c", "d"), toArray("3", "4"),
null);
canResetRecorder(toArray("a", "b"), toArray("1", "2"), toArray("c", "d"), toArray("3", "4"),
Expand Down

0 comments on commit 46b2532

Please sign in to comment.