Skip to content

Commit e501353

Browse files
committed
Using nested if blocks rather than ternary operator #8433 (comment)
1 parent 98e53cd commit e501353

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

java/maven.junit/src/org/netbeans/modules/maven/junit/JUnitOutputListenerProvider.java

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,13 @@ private String getReportsDirectory(String groupId, String artifactId, String goa
331331
MavenProject currentProject = null;
332332
// get maven module from context if available
333333
OutputVisitor.Context context = visitor.getContext();
334-
Project cp = context != null ? context.getCurrentProject() : null;
335-
if (cp != null) {
336-
NbMavenProject subProject = cp.getLookup().lookup(NbMavenProject.class);
337-
if (subProject != null) {
338-
currentProject = subProject.getMavenProject();
334+
if (context != null) {
335+
Project cp = context.getCurrentProject();
336+
if (cp != null) {
337+
NbMavenProject subProject = cp.getLookup().lookup(NbMavenProject.class);
338+
if (subProject != null) {
339+
currentProject = subProject.getMavenProject();
340+
}
339341
}
340342
}
341343
if (currentProject == null) {
@@ -598,13 +600,19 @@ private boolean usingJUnit4(MavenProject prj) { // SUREFIRE-724
598600
generateTest();
599601
}
600602
OutputVisitor.Context context = visitor.getContext();
601-
Project currentProject = context != null ? context.getCurrentProject() : null;
602-
File outputDir = currentProject != null ? project2outputDirs.remove(currentProject) : null;
603-
TestSession session = outputDir != null ? outputDir2sessions.remove(outputDir) : null;
604-
if (session != null) {
605-
CoreManager junitManager = getManagerProvider();
606-
if (junitManager != null) {
607-
junitManager.sessionFinished(session);
603+
if (context != null) {
604+
Project currentProject = context.getCurrentProject();
605+
if (currentProject != null) {
606+
File outputDir = project2outputDirs.remove(currentProject);
607+
if (outputDir != null) {
608+
TestSession session = outputDir2sessions.remove(outputDir);
609+
if (session != null) {
610+
CoreManager junitManager = getManagerProvider();
611+
if (junitManager != null) {
612+
junitManager.sessionFinished(session);
613+
}
614+
}
615+
}
608616
}
609617
}
610618
runningTestClass = null;
@@ -643,28 +651,30 @@ static Trouble constructTrouble(@NonNull String type, @NullAllowed String messag
643651

644652
public @Override void sequenceFail(String sequenceId, OutputVisitor visitor) {
645653
OutputVisitor.Context context = visitor.getContext();
646-
Project currentProject = context != null ? context.getCurrentProject() : null;
647-
LOG.log(Level.FINE, "Got sequenceFail: {0}, line {1}", new Object[] { currentProject, visitor.getLine() });
648-
// try to get the failed test class. How can this be solved if it is not the first one in the list?
649-
if (currentProject != null && surefireRunningInParallel) {
650-
String saveRunningTestClass = runningTestClass;
651-
652-
for (String s : runningTestClassesInParallel) {
653-
File outputDir = locateOutputDirAndWait(s, false);
654-
// match the output dir to the project
655-
if (outputDir != null) {
656-
Project outputOwner = FileOwnerQuery.getOwner(FileUtil.toFileObject(outputDir));
657-
if (outputOwner == currentProject) {
658-
LOG.log(Level.FINE, "Found unfinished test {0} in {1}, trying to finish", new Object[] { s, currentProject });
659-
runningTestClass = s;
660-
if (Objects.equals(saveRunningTestClass, s)) {
661-
saveRunningTestClass = null;
654+
if (context != null) {
655+
Project currentProject = context.getCurrentProject();
656+
LOG.log(Level.FINE, "Got sequenceFail: {0}, line {1}", new Object[] {currentProject, visitor.getLine()});
657+
// try to get the failed test class. How can this be solved if it is not the first one in the list?
658+
if (currentProject != null && surefireRunningInParallel) {
659+
String saveRunningTestClass = runningTestClass;
660+
661+
for (String s : runningTestClassesInParallel) {
662+
File outputDir = locateOutputDirAndWait(s, false);
663+
// match the output dir to the project
664+
if (outputDir != null) {
665+
Project outputOwner = FileOwnerQuery.getOwner(FileUtil.toFileObject(outputDir));
666+
if (outputOwner == currentProject) {
667+
LOG.log(Level.FINE, "Found unfinished test {0} in {1}, trying to finish", new Object[] {s, currentProject});
668+
runningTestClass = s;
669+
if (Objects.equals(saveRunningTestClass, s)) {
670+
saveRunningTestClass = null;
671+
}
672+
generateTest();
662673
}
663-
generateTest();
664674
}
665675
}
676+
runningTestClass = saveRunningTestClass;
666677
}
667-
runningTestClass = saveRunningTestClass;
668678
}
669679
sequenceEnd(sequenceId, visitor);
670680
}

0 commit comments

Comments
 (0)