Skip to content

Commit d74e0f9

Browse files
committed
Fixing more review comments.
1 parent ae10477 commit d74e0f9

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

src/main/java/org/testng/TestNG.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ public class TestNG {
143143
private final Map<Class<? extends IReporter>, IReporter> m_reporters = Maps.newHashMap();
144144
private final Map<Class<? extends IDataProviderListener>, IDataProviderListener> m_dataProviderListeners = Maps.newHashMap();
145145

146-
protected static final int HAS_NO_TEST = 8;
147146

148147
public static final Integer DEFAULT_VERBOSE = 1;
149148

150-
private boolean m_hasTests= false;
151-
152149
// Command line suite parameters
153150
private int m_threadCount = -1;
154151
private XmlSuite.ParallelMode m_parallelMode = null;
@@ -210,10 +207,10 @@ private void init(boolean useDefaultListeners) {
210207
}
211208

212209
public int getStatus() {
213-
if (m_hasTests) {
214-
return exitCode.getExitCode();
210+
if (!exitCodeListener.hasTests()) {
211+
return ExitCode.HAS_NO_TEST;
215212
}
216-
return HAS_NO_TEST;
213+
return exitCode.getExitCode();
217214
}
218215

219216
/**
@@ -1154,10 +1151,9 @@ public void run() {
11541151
}
11551152

11561153
runExecutionListeners(false /* finish */);
1157-
m_hasTests = this.exitCodeListener.hasTests();
11581154
exitCode = this.exitCodeListener.getStatus();
11591155

1160-
if(!m_hasTests) {
1156+
if(!exitCodeListener.hasTests()) {
11611157
if (TestRunner.getVerbose() > 1) {
11621158
System.err.println("[TestNG] No tests found. Nothing was run");
11631159
usage();
@@ -1243,7 +1239,6 @@ private void generateReports(List<ISuite> suiteRunners) {
12431239
*/
12441240
public List<ISuite> runSuitesLocally() {
12451241
if (m_suites.isEmpty()) {
1246-
this.m_hasTests = false;
12471242
error("No test suite found. Nothing to run");
12481243
usage();
12491244
return Collections.emptyList();
@@ -2005,7 +2000,6 @@ public void onTestStart(ITestResult result) {
20052000
}
20062001

20072002
private void setHasRunTests() {
2008-
m_mainRunner.m_hasTests= true;
20092003
}
20102004

20112005
/**

src/main/java/org/testng/TestNGAntTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ private void ppp(String string) {
722722
protected void actOnResult(int exitValue, boolean wasKilled) {
723723
if(exitValue == -1) {
724724
executeHaltTarget(exitValue);
725-
throw new BuildException("an error occured when running TestNG tests");
725+
throw new BuildException("an error occurred when running TestNG tests");
726726
}
727727

728-
if((exitValue & TestNG.HAS_NO_TEST) == TestNG.HAS_NO_TEST) {
728+
if((exitValue & ExitCode.HAS_NO_TEST) == ExitCode.HAS_NO_TEST) {
729729
if(m_haltOnFailure) {
730730
executeHaltTarget(exitValue);
731731
throw new BuildException("No tests were run");

src/main/java/org/testng/internal/ExitCode.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,32 @@
2121
*/
2222
public class ExitCode {
2323

24+
public static final int HAS_NO_TEST = 8;
25+
private static final int FAILED_WITHIN_SUCCESS = 4;
26+
private static final int SKIPPED = 2;
27+
private static final int FAILED = 1;
28+
private static final int SIZE = 3;
29+
2430
private final BitSet exitCodeBits;
2531

2632
ExitCode() {
27-
this(new BitSet(3));
33+
this(new BitSet(SIZE));
2834
}
2935

3036
public static boolean hasFailureWithinSuccessPercentage(int returnCode) {
31-
return (returnCode >= 4 && returnCode <= 7);
37+
return (returnCode & FAILED_WITHIN_SUCCESS) == FAILED_WITHIN_SUCCESS;
3238
}
3339

3440
public static boolean hasSkipped(int returnCode) {
35-
return (returnCode == 2 || returnCode == 3 || returnCode == 6 || returnCode == 7);
41+
return (returnCode & SKIPPED) == SKIPPED;
3642
}
3743

3844
public static boolean hasFailure(int returnCode) {
39-
return (returnCode == 1 || returnCode == 3);
45+
return (returnCode & FAILED) == FAILED;
4046
}
4147

4248
public static ExitCode newExitCodeRepresentingFailure() {
43-
BitSet bitSet = new BitSet(3);
49+
BitSet bitSet = new BitSet(SIZE);
4450
bitSet.set(0, true);
4551
bitSet.set(1, false);
4652
bitSet.set(2, false);

src/main/java/org/testng/internal/ExitCodeListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class ExitCodeListener implements ITestListener, IReporter {
1414
private boolean hasTests = false;
15-
private ExitCode status = new ExitCode();
15+
private final ExitCode status = new ExitCode();
1616

1717
public ExitCode getStatus() {
1818
return status;

0 commit comments

Comments
 (0)