Skip to content

Refactor ExitStatus#isRunning for type-safety #4783

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @author JiWon Seo
*
*/
public class ExitStatus implements Serializable, Comparable<ExitStatus> {
Expand Down Expand Up @@ -230,7 +231,7 @@ public ExitStatus replaceExitCode(String code) {
* @return {@code true} if the exit code is {@code EXECUTING} or {@code UNKNOWN}.
*/
public boolean isRunning() {
return "EXECUTING".equals(this.exitCode) || "UNKNOWN".equals(this.exitCode);
return EXECUTING.exitCode.equals(this.exitCode) || UNKNOWN.exitCode.equals(this.exitCode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
/**
* @author Dave Syer
* @author Mahmoud Ben Hassine
* @author JiWon Seo
*
*/
class ExitStatusTests {

@Test
void testExitStatusNullDescription() {
ExitStatus status = new ExitStatus("10", null);
Expand Down Expand Up @@ -153,7 +153,7 @@ void testAddExitDescription() {
}

@Test
void testAddExitDescriptionWIthStacktrace() {
void testAddExitDescriptionWithStacktrace() {
ExitStatus status = ExitStatus.EXECUTING.addExitDescription(new RuntimeException("Foo"));
assertNotSame(ExitStatus.EXECUTING, status);
String description = status.getExitDescription();
Expand Down Expand Up @@ -182,10 +182,19 @@ void testAddExitCodeWithDescription() {
}

@Test
void testUnknownIsRunning() {
void testIsRunningForExecutingAndUnknown() {
assertTrue(ExitStatus.EXECUTING.isRunning());
assertTrue(ExitStatus.UNKNOWN.isRunning());
}

@Test
void testIsRunningForCompletedStoppedFailedNoop() {
assertFalse(ExitStatus.COMPLETED.isRunning());
assertFalse(ExitStatus.FAILED.isRunning());
assertFalse(ExitStatus.STOPPED.isRunning());
assertFalse(ExitStatus.NOOP.isRunning());
}

@Test
void testSerializable() {
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
Expand Down Expand Up @@ -217,5 +226,4 @@ private static Stream<Arguments> provideCustomExitStatuses() {
return Stream.of(Arguments.of(new ExitStatus("CUSTOM")), Arguments.of(new ExitStatus("SUCCESS")),
Arguments.of(new ExitStatus("DONE")));
}

}