Skip to content

Commit 0e0ec3d

Browse files
Perform clean code of debug/org.eclipse.unittest.ui
1 parent 1be0f85 commit 0e0ec3d

23 files changed

+270
-171
lines changed

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/UnitTestPreferencesConstants.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ private UnitTestPreferencesConstants() {
5252
* @return a single string composed of the given list
5353
*/
5454
public static String serializeList(String[] list) {
55-
if (list == null)
55+
if (list == null) {
5656
return ""; //$NON-NLS-1$
57+
}
5758

5859
return String.join(String.valueOf(','), list);
5960
}
@@ -67,8 +68,9 @@ public static String serializeList(String[] list) {
6768
public static String[] parseList(String listString) {
6869
List<String> list = new ArrayList<>(10);
6970
StringTokenizer tokenizer = new StringTokenizer(listString, ","); //$NON-NLS-1$
70-
while (tokenizer.hasMoreTokens())
71+
while (tokenizer.hasMoreTokens()) {
7172
list.add(tokenizer.nextToken());
73+
}
7274
return list.toArray(new String[list.size()]);
7375
}
7476

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/junitXmlReport/HistoryEntryHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public class HistoryEntryHandler extends DefaultHandler {
3030

3131
@Override
3232
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
33-
if (Thread.interrupted())
33+
if (Thread.interrupted()) {
3434
throw new OperationCanceledException();
35+
}
3536

3637
if (IXMLTags.NODE_TESTRUN.equals(qName)) {
3738
String attribute = attributes.getValue(IXMLTags.ATTR_ERRORS);

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/junitXmlReport/TestRunHandler.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ public void startDocument() throws SAXException {
9797

9898
@Override
9999
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
100-
if (fMonitor.isCanceled())
100+
if (fMonitor.isCanceled()) {
101101
throw new OperationCanceledException();
102+
}
102103

103104
if (fLocator != null) {
104105
int line = fLocator.getLineNumber();
@@ -109,8 +110,9 @@ public void startElement(String uri, String localName, String qName, Attributes
109110
}
110111
}
111112

112-
if (Thread.interrupted())
113+
if (Thread.interrupted()) {
113114
throw new OperationCanceledException();
115+
}
114116

115117
switch (qName) {
116118
case IXMLTags.NODE_TESTRUN:
@@ -217,8 +219,7 @@ public void startElement(String uri, String localName, String qName, Attributes
217219
}
218220

219221
private void readDuration(ITestElement testElement, Attributes attributes) {
220-
if (testElement instanceof TestElement) {
221-
TestElement element = (TestElement) testElement;
222+
if (testElement instanceof TestElement element) {
222223
String timeString = attributes.getValue(IXMLTags.ATTR_DURATION);
223224
if (timeString != null) {
224225
try {
@@ -270,8 +271,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
270271
case IXMLTags.NODE_FAILURE:
271272
case IXMLTags.NODE_ERROR: {
272273
ITestElement testElement = fTestCase;
273-
if (testElement == null)
274+
if (testElement == null) {
274275
testElement = fTestSuite;
276+
}
275277
handleFailure(testElement);
276278
break;
277279
}
@@ -295,8 +297,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
295297
break;
296298
case IXMLTags.NODE_SKIPPED: {
297299
TestElement testElement = fTestCase;
298-
if (testElement == null)
300+
if (testElement == null) {
299301
testElement = fTestSuite;
302+
}
300303
if (fFailureBuffer != null && fFailureBuffer.length() > 0) {
301304
handleFailure(testElement);
302305
testElement.setAssumptionFailed(true);

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/junitXmlReport/TestRunSessionSerializer.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public TestRunSessionSerializer(TestRunSession testRunSession) {
6464

6565
@Override
6666
public void parse(InputSource input) throws IOException, SAXException {
67-
if (fHandler == null)
67+
if (fHandler == null) {
6868
throw new SAXException("ContentHandler missing"); //$NON-NLS-1$
69+
}
6970

7071
fHandler.startDocument();
7172
handleTestRun();
@@ -109,9 +110,7 @@ private void handleTestRun() throws SAXException {
109110
}
110111

111112
private void handleTestElement(ITestElement testElement) throws SAXException {
112-
if (testElement instanceof TestSuiteElement) {
113-
TestSuiteElement testSuiteElement = (TestSuiteElement) testElement;
114-
113+
if (testElement instanceof TestSuiteElement testSuiteElement) {
115114
AttributesImpl atts = new AttributesImpl();
116115
// Need to store the full #getTestName instead of only the #getSuiteTypeName for
117116
// test factory methods
@@ -121,8 +120,9 @@ private void handleTestElement(ITestElement testElement) throws SAXException {
121120
Double.toString(testSuiteElement.getDuration().toMillis() / 1000.));
122121
}
123122
if (testSuiteElement.getProgressState() != ProgressState.COMPLETED
124-
|| testSuiteElement.getTestResult(false) != Result.UNDEFINED)
123+
|| testSuiteElement.getTestResult(false) != Result.UNDEFINED) {
125124
addCDATA(atts, IXMLTags.ATTR_INCOMPLETE, Boolean.TRUE.toString());
125+
}
126126
if (testSuiteElement.getDisplayName() != null) {
127127
addCDATA(atts, IXMLTags.ATTR_DISPLAY_NAME, testSuiteElement.getDisplayName());
128128
}
@@ -137,17 +137,17 @@ private void handleTestElement(ITestElement testElement) throws SAXException {
137137
}
138138
endElement(IXMLTags.NODE_TESTSUITE);
139139

140-
} else if (testElement instanceof TestCaseElement) {
141-
TestCaseElement testCaseElement = (TestCaseElement) testElement;
142-
140+
} else if (testElement instanceof TestCaseElement testCaseElement) {
143141
AttributesImpl atts = new AttributesImpl();
144142
if (testCaseElement.getDuration() != null) {
145143
addCDATA(atts, IXMLTags.ATTR_DURATION, testCaseElement.getDuration().toString());
146144
}
147-
if (testCaseElement.getProgressState() != ProgressState.COMPLETED)
145+
if (testCaseElement.getProgressState() != ProgressState.COMPLETED) {
148146
addCDATA(atts, IXMLTags.ATTR_INCOMPLETE, Boolean.TRUE.toString());
149-
if (testCaseElement.isIgnored())
147+
}
148+
if (testCaseElement.isIgnored()) {
150149
addCDATA(atts, IXMLTags.ATTR_IGNORED, Boolean.TRUE.toString());
150+
}
151151
if (testCaseElement.isDynamicTest()) {
152152
addCDATA(atts, IXMLTags.ATTR_DYNAMIC_TEST, Boolean.TRUE.toString());
153153
}
@@ -240,8 +240,9 @@ private static String escapeNonUnicodeChars(String string) {
240240
}
241241
buf.append("\\u"); //$NON-NLS-1$
242242
String hex = Integer.toHexString(ch);
243-
for (int j = hex.length(); j < 4; j++)
243+
for (int j = hex.length(); j < 4; j++) {
244244
buf.append('0');
245+
}
245246
buf.append(hex);
246247
} else if (buf != null) {
247248
buf.append(ch);

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/launcher/TestListenerRegistry.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public class TestListenerRegistry {
2828
* @return a {@link TestListenerRegistry} object
2929
*/
3030
public static TestListenerRegistry getDefault() {
31-
if (fgRegistry != null)
31+
if (fgRegistry != null) {
3232
return fgRegistry;
33+
}
3334

3435
fgRegistry = new TestListenerRegistry();
3536
return fgRegistry;

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/launcher/TestViewSupportRegistry.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public class TestViewSupportRegistry {
4646
* @return a {@link TestViewSupportRegistry} object
4747
*/
4848
public static TestViewSupportRegistry getDefault() {
49-
if (fgRegistry != null)
49+
if (fgRegistry != null) {
5050
return fgRegistry;
51+
}
5152

5253
fgRegistry = new TestViewSupportRegistry(
5354
Platform.getExtensionRegistry().getExtensionPoint(ID_EXTENSION_POINT_TEST_VIEW_SUPPORTS));
@@ -83,15 +84,17 @@ private List<TestViewSupportExtension> getAllTestViewSupportExtensions() {
8384
*/
8485
public List<TestViewSupportExtension> getTestViewSupportExtensions(final String filter) {
8586
List<TestViewSupportExtension> all = getAllTestViewSupportExtensions();
86-
if (all == null)
87+
if (all == null) {
8788
return Collections.emptyList();
89+
}
8890

8991
return all.stream().filter(p -> p.getId().startsWith(filter)).collect(Collectors.toList());
9092
}
9193

9294
private void loadTestViewSupportExtensions() {
93-
if (fTestViewSupportExtensions != null)
95+
if (fTestViewSupportExtensions != null) {
9496
return;
97+
}
9598

9699
List<TestViewSupportExtension> items = getConfigurationElements().stream().map(TestViewSupportExtension::new)
97100
.collect(Collectors.toList());

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/model/Status.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,15 @@ public static Status convert(int oldStatus) {
127127
* instance
128128
*/
129129
public Result convertToResult() {
130-
if (isNotRun())
130+
if (isNotRun()) {
131131
return Result.UNDEFINED;
132-
if (isError())
132+
}
133+
if (isError()) {
133134
return Result.ERROR;
134-
if (isFailure())
135+
}
136+
if (isFailure()) {
135137
return Result.FAILURE;
138+
}
136139
if (isRunning()) {
137140
return Result.UNDEFINED;
138141
}

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/model/TestRunSession.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public TestElement createTestElement(TestSuiteElement parent, String id, String
351351
return testElement;
352352
}
353353

354-
private final class NoopLaunch extends Launch {
354+
private static final class NoopLaunch extends Launch {
355355
private NoopLaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator) {
356356
super(launchConfiguration, mode, locator);
357357
}
@@ -471,7 +471,7 @@ public void testEnded(ITestElement testElement, boolean isIgnored) {
471471
if (testElement == null) {
472472
return;
473473
}
474-
if (!(testElement instanceof TestCaseElement)) {
474+
if (!(testElement instanceof TestCaseElement testCaseElement)) {
475475
if (isIgnored) {
476476
((TestElement) testElement).setAssumptionFailed(true);
477477
setStatus(testElement, Status.OK);
@@ -480,13 +480,13 @@ public void testEnded(ITestElement testElement, boolean isIgnored) {
480480
}
481481
return;
482482
}
483-
TestCaseElement testCaseElement = (TestCaseElement) testElement;
484483
if (isIgnored) {
485484
testCaseElement.setIgnored(true);
486485
}
487486

488-
if (testCaseElement.getStatus() == Status.RUNNING)
487+
if (testCaseElement.getStatus() == Status.RUNNING) {
489488
setStatus(testCaseElement, Status.OK);
489+
}
490490

491491
for (ITestSessionListener listener : fSessionListeners) {
492492
listener.testEnded(testCaseElement);
@@ -544,13 +544,13 @@ public void registerTestFailureStatus(TestElement testElement, Result status, Fa
544544
* <code>false</code> otherwise
545545
*/
546546
public void registerTestEnded(TestElement testElement, boolean completed) {
547-
if (testElement instanceof TestCaseElement) {
547+
if (testElement instanceof TestCaseElement testCaseElement) {
548548
if (!completed) {
549549
return;
550550
}
551-
TestCaseElement testCaseElement = (TestCaseElement) testElement;
552-
if (!testCaseElement.getStatus().isErrorOrFailure())
551+
if (!testCaseElement.getStatus().isErrorOrFailure()) {
553552
setStatus(testElement, Status.OK);
553+
}
554554
}
555555
}
556556

@@ -580,8 +580,7 @@ private void addFailures(Collection<TestElement> failures, TestElement testEleme
580580
if (testResult == Result.ERROR || testResult == Result.FAILURE) {
581581
failures.add(testElement);
582582
}
583-
if (testElement instanceof TestSuiteElement) {
584-
TestSuiteElement testSuiteElement = (TestSuiteElement) testElement;
583+
if (testElement instanceof TestSuiteElement testSuiteElement) {
585584
for (TestElement child : testSuiteElement.getChildren()) {
586585
addFailures(failures, child);
587586
}

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/model/TestSuiteElement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ public Status getStatus() {
9797
private Status getCumulatedStatus() {
9898
TestElement[] children = fChildren.toArray(new TestElement[fChildren.size()]); // copy list to avoid concurreny
9999
// problems
100-
if (children.length == 0)
100+
if (children.length == 0) {
101101
return getSuiteStatus();
102+
}
102103

103104
Status cumulated = children[0].getStatus();
104105

@@ -167,8 +168,9 @@ public void childChangedStatus(ITestElement child, Status childStatus) {
167168
}
168169

169170
private void internalSetChildrenStatus(Status status) {
170-
if (fChildrenStatus == status)
171+
if (fChildrenStatus == status) {
171172
return;
173+
}
172174

173175
if (status == Status.RUNNING) {
174176
if (fDuration != null) {

debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/model/UnitTestLaunchListener.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ public class UnitTestLaunchListener implements ILaunchListener {
4545
@Override
4646
public void launchAdded(ILaunch launch) {
4747
ILaunchConfiguration config = launch.getLaunchConfiguration();
48-
if (config == null)
48+
if (config == null) {
4949
return;
50+
}
5051

5152
try {
52-
if (!config.hasAttribute(UnitTestLaunchConfigurationConstants.ATTR_UNIT_TEST_VIEW_SUPPORT))
53+
if (!config.hasAttribute(UnitTestLaunchConfigurationConstants.ATTR_UNIT_TEST_VIEW_SUPPORT)) {
5354
return;
55+
}
5456
} catch (CoreException e1) {
5557
UnitTestPlugin.log(e1);
5658
return;
5759
}
5860

5961
ITestViewSupport testRunnerViewSupport = TestViewSupportRegistry.newTestRunnerViewSupport(config).orElse(null);
60-
if (testRunnerViewSupport == null)
62+
if (testRunnerViewSupport == null) {
6163
return;
64+
}
6265

6366
fTrackedLaunches.add(launch);
6467
}
@@ -70,8 +73,9 @@ public void launchRemoved(final ILaunch launch) {
7073

7174
@Override
7275
public void launchChanged(final ILaunch launch) {
73-
if (!fTrackedLaunches.contains(launch))
76+
if (!fTrackedLaunches.contains(launch)) {
7477
return;
78+
}
7579

7680
// Load session on 1st change (usually 1st process added), although it's not
7781
// much reliable. Each TestRunnerClient should take care of listening to the

0 commit comments

Comments
 (0)