Skip to content

Commit fca4635

Browse files
committed
Remove useless assert/fail methods from CoreTest
These methods are already provided by JUnit itself.
1 parent 4e49249 commit fca4635

File tree

22 files changed

+407
-605
lines changed

22 files changed

+407
-605
lines changed

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileCacheTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@ public void assertNotSame(String message, byte[] expected, byte[] actual) {
6161
* Returns the byte[] contents of the given file.
6262
*/
6363
private byte[] getBytes(File cachedFile) {
64-
FileInputStream in = null;
65-
ByteArrayOutputStream out = null;
66-
try {
67-
in = new FileInputStream(cachedFile);
68-
out = new ByteArrayOutputStream();
69-
transferData(in, out);
70-
in.close();
71-
out.close();
64+
try (FileInputStream in = new FileInputStream(cachedFile);
65+
ByteArrayOutputStream out = new ByteArrayOutputStream();) {
66+
in.transferTo(out);
7267
return out.toByteArray();
7368
} catch (IOException e) {
7469
fail("Exception in FileCacheTest.getBytes", e);

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/builders/BuildContextTest.java

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.internal.builders;
1515

16+
import static org.junit.Assert.assertArrayEquals;
17+
1618
import org.eclipse.core.internal.events.BuildContext;
1719
import org.eclipse.core.internal.resources.BuildConfiguration;
1820
import org.eclipse.core.resources.*;
@@ -133,22 +135,22 @@ public void testBuildContext() {
133135
IBuildContext context;
134136

135137
context = new BuildContext(p0v0, new IBuildConfiguration[] {p0v0, p1v0}, buildOrder);
136-
assertEquals("1.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
137-
assertEquals("1.1", new IBuildConfiguration[] {p0v1, p1v0}, context.getAllReferencingBuildConfigs());
138-
assertEquals("1.2", new IBuildConfiguration[] {p0v0, p1v0}, context.getRequestedConfigs());
138+
assertArrayEquals("1.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
139+
assertArrayEquals("1.1", new IBuildConfiguration[] { p0v1, p1v0 }, context.getAllReferencingBuildConfigs());
140+
assertArrayEquals("1.2", new IBuildConfiguration[] { p0v0, p1v0 }, context.getRequestedConfigs());
139141

140142
context = new BuildContext(p0v1, buildOrder, buildOrder);
141-
assertEquals("2.0", new IBuildConfiguration[] {p0v0}, context.getAllReferencedBuildConfigs());
142-
assertEquals("2.1", new IBuildConfiguration[] {p1v0}, context.getAllReferencingBuildConfigs());
143+
assertArrayEquals("2.0", new IBuildConfiguration[] { p0v0 }, context.getAllReferencedBuildConfigs());
144+
assertArrayEquals("2.1", new IBuildConfiguration[] { p1v0 }, context.getAllReferencingBuildConfigs());
143145

144146
context = new BuildContext(p1v0, buildOrder, buildOrder);
145-
assertEquals("3.0", new IBuildConfiguration[] {p0v0, p0v1}, context.getAllReferencedBuildConfigs());
146-
assertEquals("3.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
147+
assertArrayEquals("3.0", new IBuildConfiguration[] { p0v0, p0v1 }, context.getAllReferencedBuildConfigs());
148+
assertArrayEquals("3.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
147149

148150
// And it works with no build context too
149151
context = new BuildContext(p1v0);
150-
assertEquals("4.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
151-
assertEquals("4.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
152+
assertArrayEquals("4.0", new IBuildConfiguration[] {}, context.getAllReferencedBuildConfigs());
153+
assertArrayEquals("4.1", new IBuildConfiguration[] {}, context.getAllReferencingBuildConfigs());
152154
}
153155

154156
public void testSingleProjectBuild() throws CoreException {
@@ -186,16 +188,22 @@ public void testWorkspaceBuildProject() throws CoreException {
186188
assertTrue("1.0", ContextBuilder.checkValid());
187189

188190
IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
189-
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
191+
assertArrayEquals("2.0",
192+
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
193+
context.getAllReferencedBuildConfigs());
190194
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);
191195

192196
context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
193-
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
194-
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
197+
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
198+
context.getAllReferencedBuildConfigs());
199+
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
200+
context.getAllReferencingBuildConfigs());
195201

196202
context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
197203
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
198-
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
204+
assertArrayEquals("4.1",
205+
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
206+
context.getAllReferencingBuildConfigs());
199207

200208
// Build just project0
201209
ContextBuilder.clearStats();
@@ -219,16 +227,22 @@ public void testWorkspaceBuildProjects() throws CoreException {
219227
assertTrue("1.0", ContextBuilder.checkValid());
220228

221229
IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
222-
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
230+
assertArrayEquals("2.0",
231+
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
232+
context.getAllReferencedBuildConfigs());
223233
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);
224234

225235
context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
226-
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
227-
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
236+
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
237+
context.getAllReferencedBuildConfigs());
238+
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
239+
context.getAllReferencingBuildConfigs());
228240

229241
context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
230242
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
231-
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
243+
assertArrayEquals("4.1",
244+
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
245+
context.getAllReferencingBuildConfigs());
232246
}
233247

234248
/**
@@ -245,16 +259,22 @@ public void testReferenceActiveVariant() throws CoreException {
245259
assertTrue("1.0", ContextBuilder.checkValid());
246260

247261
IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
248-
assertEquals("2.0", new IBuildConfiguration[] {project2.getActiveBuildConfig(), project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
262+
assertArrayEquals("2.0",
263+
new IBuildConfiguration[] { project2.getActiveBuildConfig(), project1.getActiveBuildConfig() },
264+
context.getAllReferencedBuildConfigs());
249265
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);
250266

251267
context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
252-
assertEquals("3.0", new IBuildConfiguration[] {project2.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
253-
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
268+
assertArrayEquals("3.0", new IBuildConfiguration[] { project2.getActiveBuildConfig() },
269+
context.getAllReferencedBuildConfigs());
270+
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
271+
context.getAllReferencingBuildConfigs());
254272

255273
context = ContextBuilder.getBuilder(project2.getActiveBuildConfig()).contextForLastBuild;
256274
assertEquals("4.0", 0, context.getAllReferencedBuildConfigs().length);
257-
assertEquals("4.1", new IBuildConfiguration[] {project1.getActiveBuildConfig(), project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
275+
assertArrayEquals("4.1",
276+
new IBuildConfiguration[] { project1.getActiveBuildConfig(), project0.getActiveBuildConfig() },
277+
context.getAllReferencingBuildConfigs());
258278
}
259279

260280
/**
@@ -272,13 +292,16 @@ public void testReferenceVariantTwice() throws CoreException {
272292
assertTrue("1.0", ContextBuilder.checkValid());
273293

274294
IBuildContext context = ContextBuilder.getContext(project0.getActiveBuildConfig());
275-
assertEquals("2.0", new IBuildConfiguration[] {project1.getActiveBuildConfig()}, context.getAllReferencedBuildConfigs());
295+
assertArrayEquals("2.0", new IBuildConfiguration[] { project1.getActiveBuildConfig() },
296+
context.getAllReferencedBuildConfigs());
276297
assertEquals("2.1", 0, context.getAllReferencingBuildConfigs().length);
277-
assertEquals("2.2", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs());
298+
assertArrayEquals("2.2", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
299+
context.getRequestedConfigs());
278300

279301
context = ContextBuilder.getBuilder(project1.getActiveBuildConfig()).contextForLastBuild;
280302
assertEquals("3.0", 0, context.getAllReferencedBuildConfigs().length);
281-
assertEquals("3.1", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getAllReferencingBuildConfigs());
303+
assertArrayEquals("3.1", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
304+
context.getAllReferencingBuildConfigs());
282305

283306
// Change the active configuration of project1, and test that two configurations are built
284307
ContextBuilder.clearStats();
@@ -288,8 +311,10 @@ public void testReferenceVariantTwice() throws CoreException {
288311
assertTrue("4.0", ContextBuilder.checkValid());
289312

290313
context = ContextBuilder.getContext(project0.getActiveBuildConfig());
291-
assertEquals("4.1", new IBuildConfiguration[] {project1PreviousActive, project1NewActive}, context.getAllReferencedBuildConfigs());
314+
assertArrayEquals("4.1", new IBuildConfiguration[] { project1PreviousActive, project1NewActive },
315+
context.getAllReferencedBuildConfigs());
292316
assertEquals("4.2", 0, context.getAllReferencingBuildConfigs().length);
293-
assertEquals("4.3", new IBuildConfiguration[] {project0.getActiveBuildConfig()}, context.getRequestedConfigs());
317+
assertArrayEquals("4.3", new IBuildConfiguration[] { project0.getActiveBuildConfig() },
318+
context.getRequestedConfigs());
294319
}
295320
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/BlobStoreTest.java

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.tests.internal.localstore;
1515

16+
import java.io.IOException;
1617
import java.io.InputStream;
1718
import org.eclipse.core.filesystem.*;
1819
import org.eclipse.core.internal.localstore.BlobStore;
@@ -89,7 +90,7 @@ private IFileStore createStore() {
8990
return root;
9091
}
9192

92-
public void testDeleteBlob() {
93+
public void testDeleteBlob() throws CoreException, IOException {
9394
/* initialize common objects */
9495
IFileStore root = createStore();
9596
BlobStore store = new BlobStore(root, 64);
@@ -102,18 +103,14 @@ public void testDeleteBlob() {
102103

103104
/* delete existing blob */
104105
IFileStore target = root.getChild("target");
105-
try {
106-
createFile(target, "bla bla bla");
107-
uuid = store.addBlob(target, true);
108-
} catch (CoreException e) {
109-
fail("4.1", e);
110-
}
106+
createFile(target, "bla bla bla");
107+
uuid = store.addBlob(target, true);
111108
assertTrue("4.2", store.fileFor(uuid).fetchInfo().exists());
112109
store.deleteBlob(uuid);
113110
assertTrue("4.3", !store.fileFor(uuid).fetchInfo().exists());
114111
}
115112

116-
public void testGetBlob() {
113+
public void testGetBlob() throws CoreException, IOException {
117114
/* initialize common objects */
118115
IFileStore root = createStore();
119116
BlobStore store = new BlobStore(root, 64);
@@ -124,31 +121,20 @@ public void testGetBlob() {
124121
store.getBlob(null);
125122
} catch (RuntimeException e) {
126123
ok = true;
127-
} catch (CoreException e) {
128-
fail("2.0", e);
129124
}
130125
assertTrue("2.1", ok);
131126

132127
/* get existing blob */
133128
IFileStore target = root.getChild("target");
134129
UniversalUniqueIdentifier uuid = null;
135130
String content = "nothing important........tnatropmi gnihton";
136-
try {
137-
createFile(target, content);
138-
uuid = store.addBlob(target, true);
139-
} catch (CoreException e) {
140-
fail("3.1", e);
141-
}
142-
InputStream input = null;
143-
try {
144-
input = store.getBlob(uuid);
145-
} catch (CoreException e) {
146-
fail("3.4", e);
147-
}
131+
createFile(target, content);
132+
uuid = store.addBlob(target, true);
133+
InputStream input = store.getBlob(uuid);
148134
assertTrue("4.1", compareContent(getContents(content), input));
149135
}
150136

151-
public void testSetBlob() {
137+
public void testSetBlob() throws CoreException, IOException {
152138
/* initialize common objects */
153139
IFileStore root = createStore();
154140
BlobStore store = new BlobStore(root, 64);
@@ -157,18 +143,9 @@ public void testSetBlob() {
157143
IFileStore target = root.getChild("target");
158144
UniversalUniqueIdentifier uuid = null;
159145
String content = "nothing important........tnatropmi gnihton";
160-
try {
161-
createFile(target, content);
162-
uuid = store.addBlob(target, true);
163-
} catch (CoreException e) {
164-
fail("2.1", e);
165-
}
166-
InputStream input = null;
167-
try {
168-
input = store.getBlob(uuid);
169-
} catch (CoreException e) {
170-
fail("2.4", e);
171-
}
146+
createFile(target, content);
147+
uuid = store.addBlob(target, true);
148+
InputStream input = store.getBlob(uuid);
172149
assertTrue("2.5", compareContent(getContents(content), input));
173150
}
174151
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/LocalStoreTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ public int countChildren(IFolder root) throws CoreException {
7272
* Create a file with random content. If a resource exists in the same path,
7373
* the resource is deleted.
7474
*/
75-
protected void createFile(IFileStore target, String content) throws CoreException {
75+
protected void createFile(IFileStore target, String content) throws CoreException, IOException {
7676
target.delete(EFS.NONE, null);
77-
InputStream input = new ByteArrayInputStream(content.getBytes());
78-
transferData(input, target.openOutputStream(EFS.NONE, null));
77+
try (InputStream input = new ByteArrayInputStream(content.getBytes())) {
78+
input.transferTo(target.openOutputStream(EFS.NONE, null));
79+
}
7980
IFileInfo info = target.fetchInfo();
8081
assertTrue(info.exists() && !info.isDirectory());
8182
}
@@ -86,23 +87,24 @@ protected void createFile(IFileStore target, String content) throws CoreExceptio
8687
*/
8788
protected void createIOFile(java.io.File target, String content) throws IOException {
8889
target.delete();
89-
InputStream input = new ByteArrayInputStream(content.getBytes());
90-
transferData(input, new FileOutputStream(target));
90+
try (InputStream input = new ByteArrayInputStream(content.getBytes())) {
91+
input.transferTo(new FileOutputStream(target));
92+
}
9193
assertTrue(target.exists() && !target.isDirectory());
9294
}
9395

94-
protected void createNode(IFileStore node) throws CoreException {
96+
protected void createNode(IFileStore node) throws CoreException, IOException {
9597
char type = node.getName().charAt(0);
9698
if (type == 'd') {
9799
node.mkdir(EFS.NONE, null);
98100
} else {
99-
InputStream input = getRandomContents();
100-
OutputStream output = node.openOutputStream(EFS.NONE, null);
101-
transferData(input, output);
101+
try (InputStream input = getRandomContents(); OutputStream output = node.openOutputStream(EFS.NONE, null)) {
102+
input.transferTo(output);
103+
}
102104
}
103105
}
104106

105-
protected void createTree(IFileStore[] tree) throws CoreException {
107+
protected void createTree(IFileStore[] tree) throws CoreException, IOException {
106108
for (IFileStore element : tree) {
107109
createNode(element);
108110
}

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/resources/ModelObjectReaderWriterTest.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*******************************************************************************/
1616
package org.eclipse.core.tests.internal.resources;
1717

18+
import static org.junit.Assert.assertArrayEquals;
19+
1820
import java.io.*;
1921
import java.net.URI;
2022
import java.net.URL;
@@ -270,14 +272,10 @@ private String getLongDescriptionURI() {
270272
* @throws CoreException
271273
* @throws IOException
272274
*/
273-
private ProjectDescription readDescription(IFileStore store) throws CoreException {
274-
InputStream input = null;
275-
try {
276-
input = store.openInputStream(EFS.NONE, getMonitor());
275+
private ProjectDescription readDescription(IFileStore store) throws CoreException, IOException {
276+
try (InputStream input = store.openInputStream(EFS.NONE, getMonitor())) {
277277
InputSource in = new InputSource(input);
278278
return new ProjectDescriptionReader(getWorkspace()).read(in);
279-
} finally {
280-
assertClose(input);
281279
}
282280
}
283281

@@ -354,9 +352,9 @@ public void testInvalidProjectDescription2() throws Throwable {
354352
assertNull("2.1", projDesc.getName());
355353
assertEquals("2.2", 0, projDesc.getComment().length());
356354
assertNull("2.3", projDesc.getLocationURI());
357-
assertEquals("2.4", new IProject[0], projDesc.getReferencedProjects());
358-
assertEquals("2.5", new String[0], projDesc.getNatureIds());
359-
assertEquals("2.6", new ICommand[0], projDesc.getBuildSpec());
355+
assertArrayEquals("2.4", new IProject[0], projDesc.getReferencedProjects());
356+
assertArrayEquals("2.5", new String[0], projDesc.getNatureIds());
357+
assertArrayEquals("2.6", new ICommand[0], projDesc.getBuildSpec());
360358
assertNull("2.7", projDesc.getLinks());
361359
}
362360

@@ -373,9 +371,9 @@ public void testInvalidProjectDescription3() throws Throwable {
373371
assertTrue("3.1", projDesc.getName().equals("abc"));
374372
assertEquals("3.2", 0, projDesc.getComment().length());
375373
assertNull("3.3", projDesc.getLocationURI());
376-
assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
377-
assertEquals("3.5", new String[0], projDesc.getNatureIds());
378-
assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
374+
assertArrayEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
375+
assertArrayEquals("3.5", new String[0], projDesc.getNatureIds());
376+
assertArrayEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
379377
assertNull("3.7", projDesc.getLinks());
380378
}
381379

@@ -391,9 +389,9 @@ public void testInvalidProjectDescription4() throws Throwable {
391389
assertTrue("3.1", projDesc.getName().equals("abc"));
392390
assertEquals("3.2", 0, projDesc.getComment().length());
393391
assertNull("3.3", projDesc.getLocationURI());
394-
assertEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
395-
assertEquals("3.5", new String[0], projDesc.getNatureIds());
396-
assertEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
392+
assertArrayEquals("3.4", new IProject[0], projDesc.getReferencedProjects());
393+
assertArrayEquals("3.5", new String[0], projDesc.getNatureIds());
394+
assertArrayEquals("3.6", new ICommand[0], projDesc.getBuildSpec());
397395
LinkDescription link = projDesc.getLinks().values().iterator().next();
398396
assertEquals("3.7", new Path("newLink"), link.getProjectRelativePath());
399397
assertEquals("3.8", PATH_STRING, URIUtil.toPath(link.getLocationURI()).toString());
@@ -656,12 +654,8 @@ protected URI uriFromPortableString(String pathString) {
656654
* @throws CoreException
657655
*/
658656
private void writeDescription(IFileStore store, ProjectDescription description) throws IOException, CoreException {
659-
OutputStream output = null;
660-
try {
661-
output = store.openOutputStream(EFS.NONE, getMonitor());
657+
try (OutputStream output = store.openOutputStream(EFS.NONE, getMonitor());) {
662658
new ModelObjectWriter().write(description, output, System.lineSeparator());
663-
} finally {
664-
assertClose(output);
665659
}
666660

667661
}

0 commit comments

Comments
 (0)