Skip to content

Commit 3672c97

Browse files
committed
Minor improvements to o.e.core.filebuffers.tests
Various cleanups and modernizations provoked by unstable test as can be seen at https://download.eclipse.org/eclipse/downloads/drops4/I20260306-1800/testresults/html/org.eclipse.core.filebuffers.tests_ep440I-unit-linux-x86_64-java25_linux.gtk.x86_64_25.html
1 parent 68c7255 commit 3672c97

15 files changed

+48
-119
lines changed

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/AbstractFileBufferDocCreationTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
import static org.junit.jupiter.api.Assertions.assertEquals;
1717

18-
import java.util.Arrays;
19-
import java.util.HashSet;
2018
import java.util.Set;
2119

2220
import org.junit.jupiter.api.Test;
@@ -35,7 +33,6 @@
3533

3634
import org.eclipse.jface.text.IDocument;
3735

38-
3936
/**
4037
* @since 3.4
4138
*/
@@ -124,8 +121,8 @@ private void assertParticipantsInvoked(String path, Class<?>... expectedDSPsArra
124121
for (LocationKind lk : lks) {
125122
IDocument document= fManager.createEmptyDocument(IPath.fromOSString(path), lk);
126123
String content= document.get();
127-
Set<String> expectedDSPs= new HashSet<>(Arrays.asList(toString(expectedDSPsArray)));
128-
Set<String> actualDSPs= new HashSet<>(Arrays.asList(content.split("\n")));
124+
Set<String> expectedDSPs= Set.of(toString(expectedDSPsArray));
125+
Set<String> actualDSPs= Set.of(content.split("\n"));
129126
assertEquals(expectedDSPs, actualDSPs);
130127
}
131128
}

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBufferCreation.java

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,6 +18,7 @@
1818
import static org.junit.jupiter.api.Assertions.assertNotNull;
1919
import static org.junit.jupiter.api.Assertions.assertNull;
2020
import static org.junit.jupiter.api.Assertions.assertSame;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
2223

2324
import java.io.File;
@@ -45,19 +46,15 @@
4546
import org.eclipse.jface.text.BadLocationException;
4647
import org.eclipse.jface.text.IDocument;
4748

48-
49-
5049
public class FileBufferCreation {
5150

5251
private final static String CONTENT1= "This is the content of the workspace file.";
5352
private final static String CONTENT2= "This is the content of the link target.";
5453
private final static String CONTENT3= "This is the content of the external file.";
5554
private final static String CONTENT4= "This is the content of a file in a linked folder.";
5655

57-
5856
private IProject fProject;
5957

60-
6158
@BeforeEach
6259
public void setUp() throws Exception {
6360
fProject= ResourceHelper.createProject("project");
@@ -166,11 +163,7 @@ public void test2() throws Exception {
166163
assertEquals(CONTENT1, document2.get());
167164
assertSame(buffer2, manager.getTextFileBuffer(document2));
168165

169-
try {
170-
document1.replace(0, document1.getLength(), CONTENT3);
171-
} catch (BadLocationException x) {
172-
assertTrue(false);
173-
}
166+
assertThrows(BadLocationException.class, () -> document1.replace(0, document1.getLength(), CONTENT3));
174167

175168
assertEquals(CONTENT3, document2.get());
176169

@@ -198,7 +191,7 @@ public void test3_1() throws Exception {
198191

199192
IDocument document= buffer.getDocument();
200193
assertNotNull(document);
201-
assertTrue(CONTENT2.equals(document.get()));
194+
assertEquals(CONTENT2, document.get());
202195
assertSame(buffer, manager.getTextFileBuffer(document));
203196

204197
manager.disconnect(path, LocationKind.NORMALIZE, null);
@@ -221,7 +214,7 @@ public void test3_2() throws Exception {
221214

222215
IDocument document= buffer.getDocument();
223216
assertNotNull(document);
224-
assertTrue(CONTENT4.equals(document.get()));
217+
assertEquals(CONTENT4, document.get());
225218
assertSame(buffer, manager.getTextFileBuffer(document));
226219

227220
manager.disconnect(path, LocationKind.NORMALIZE, null);
@@ -259,11 +252,7 @@ public void test4() throws Exception {
259252
assertEquals(document1.get(), document2.get());
260253
assertEquals(CONTENT2, document1.get());
261254

262-
try {
263-
document1.replace(0, document1.getLength(), CONTENT1);
264-
} catch (BadLocationException x) {
265-
assertFalse(false);
266-
}
255+
document1.replace(0, document1.getLength(), CONTENT1);
267256

268257
assertFalse(document1.get().equals(document2.get()));
269258

@@ -290,7 +279,7 @@ public void test5() throws Exception {
290279

291280
IDocument document= buffer.getDocument();
292281
assertNotNull(document);
293-
assertTrue(CONTENT3.equals(document.get()));
282+
assertEquals(CONTENT3, document.get());
294283
assertSame(buffer, manager.getTextFileBuffer(document));
295284

296285
manager.disconnect(path, LocationKind.NORMALIZE, null);
@@ -330,11 +319,7 @@ public void test6() throws Exception {
330319
assertEquals(document1.get(), document2.get());
331320
assertEquals(CONTENT3, document1.get());
332321

333-
try {
334-
document1.replace(0, document1.getLength(), CONTENT1);
335-
} catch (BadLocationException x) {
336-
assertFalse(false);
337-
}
322+
document1.replace(0, document1.getLength(), CONTENT1);
338323

339324
assertFalse(document1.get().equals(document2.get()));
340325

@@ -359,7 +344,7 @@ public void test7() throws Exception {
359344

360345
IDocument document= buffer.getDocument();
361346
assertNotNull(document);
362-
assertTrue("".equals(document.get()));
347+
assertTrue(document.get().isEmpty());
363348
assertSame(buffer, manager.getTextFileBuffer(document));
364349

365350
manager.disconnect(path, LocationKind.NORMALIZE, null);
@@ -428,11 +413,7 @@ public void test2_new() throws Exception {
428413
assertEquals(CONTENT1, document2.get());
429414
assertSame(buffer2, manager.getTextFileBuffer(document2));
430415

431-
try {
432-
document1.replace(0, document1.getLength(), CONTENT3);
433-
} catch (BadLocationException x) {
434-
assertTrue(false);
435-
}
416+
assertThrows(BadLocationException.class, () -> document1.replace(0, document1.getLength(), CONTENT3));
436417

437418
assertEquals(CONTENT3, document2.get());
438419

@@ -460,7 +441,7 @@ public void test3_1_IFILE() throws Exception {
460441

461442
IDocument document= buffer.getDocument();
462443
assertNotNull(document);
463-
assertTrue(CONTENT2.equals(document.get()));
444+
assertEquals(CONTENT2, document.get());
464445
assertSame(buffer, manager.getTextFileBuffer(document));
465446

466447
manager.disconnect(path, LocationKind.IFILE, null);
@@ -483,7 +464,7 @@ public void test3_2_new() throws Exception {
483464

484465
IDocument document= buffer.getDocument();
485466
assertNotNull(document);
486-
assertTrue(CONTENT4.equals(document.get()));
467+
assertEquals(CONTENT4, document.get());
487468
assertSame(buffer, manager.getTextFileBuffer(document));
488469

489470
manager.disconnect(path, LocationKind.IFILE, null);
@@ -521,11 +502,7 @@ public void test4_IFILE() throws Exception {
521502
assertEquals(document1.get(), document2.get());
522503
assertEquals(CONTENT2, document1.get());
523504

524-
try {
525-
document1.replace(0, document1.getLength(), CONTENT1);
526-
} catch (BadLocationException x) {
527-
assertFalse(false);
528-
}
505+
document1.replace(0, document1.getLength(), CONTENT1);
529506

530507
assertFalse(document1.get().equals(document2.get()));
531508

@@ -552,7 +529,7 @@ public void test5_location() throws Exception {
552529

553530
IDocument document= buffer.getDocument();
554531
assertNotNull(document);
555-
assertTrue(CONTENT3.equals(document.get()));
532+
assertEquals(CONTENT3, document.get());
556533
assertSame(buffer, manager.getTextFileBuffer(document));
557534

558535
manager.disconnect(path, LocationKind.LOCATION, null);
@@ -574,7 +551,7 @@ public void test7_location() throws Exception {
574551

575552
IDocument document= buffer.getDocument();
576553
assertNotNull(document);
577-
assertTrue("".equals(document.get()));
554+
assertTrue(document.get().isEmpty());
578555
assertSame(buffer, manager.getTextFileBuffer(document));
579556

580557
manager.disconnect(path, LocationKind.LOCATION, null);
@@ -597,7 +574,7 @@ public void test7_IFileStore() throws Exception {
597574

598575
IDocument document= buffer.getDocument();
599576
assertNotNull(document);
600-
assertTrue("".equals(document.get()));
577+
assertTrue(document.get().isEmpty());
601578
assertSame(buffer, manager.getTextFileBuffer(document));
602579

603580
manager.disconnectFileStore(fileStore, null);

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,10 +14,8 @@
1414
package org.eclipse.core.filebuffers.tests;
1515

1616
import static org.junit.jupiter.api.Assertions.assertTrue;
17-
import static org.junit.jupiter.api.Assertions.fail;
1817

1918
import java.io.File;
20-
import java.io.IOException;
2119
import java.io.OutputStream;
2220

2321
import org.junit.jupiter.api.AfterEach;
@@ -71,9 +69,6 @@ protected IPath createPath(IProject project) throws Exception {
7169
return file.getFullPath();
7270
}
7371

74-
/*
75-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
76-
*/
7772
@Override
7873
protected void setReadOnly(boolean state) throws Exception {
7974
IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath());
@@ -115,8 +110,6 @@ protected boolean modifyUnderlyingFile() throws Exception {
115110
try (OutputStream out= fileStore.openOutputStream(EFS.NONE, null)) {
116111
out.write("Changed content of file in linked folder".getBytes());
117112
out.flush();
118-
} catch (IOException x) {
119-
fail();
120113
}
121114
IFileInfo fileInfo= fileStore.fetchInfo();
122115
fileInfo.setLastModified(1000);

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForLinkedFiles.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -54,9 +54,6 @@ protected IPath createPath(IProject project) throws Exception {
5454
return file.getFullPath();
5555
}
5656

57-
/*
58-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
59-
*/
6057
@Override
6158
protected void setReadOnly(boolean state) throws Exception {
6259
IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath());

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonAccessibleWorkspaceFiles.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -59,9 +59,6 @@ public void tearDown() {
5959
super.tearDown();
6060
}
6161

62-
/*
63-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
64-
*/
6562
@Override
6663
protected void setReadOnly(boolean state) throws Exception {
6764
IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath());

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingExternalFiles.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -47,9 +47,6 @@ protected IPath createPath(IProject project) throws Exception {
4747
return IPath.fromOSString(path.toFile().getAbsolutePath());
4848
}
4949

50-
/*
51-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
52-
*/
5350
@Override
5451
protected void setReadOnly(boolean state) throws Exception {
5552
IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath());

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -91,9 +91,6 @@ public void testBug118199_fixed() throws Exception {
9191
assertTrue(file.exists());
9292
}
9393

94-
/*
95-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
96-
*/
9794
@Override
9895
protected void setReadOnly(boolean state) throws Exception {
9996
IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath());

tests/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,9 +14,7 @@
1414
package org.eclipse.core.filebuffers.tests;
1515

1616
import static org.junit.jupiter.api.Assertions.assertTrue;
17-
import static org.junit.jupiter.api.Assertions.fail;
1817

19-
import java.io.IOException;
2018
import java.io.OutputStream;
2119

2220
import org.osgi.framework.Bundle;
@@ -50,9 +48,6 @@ protected IPath createPath(IProject project) throws Exception {
5048
return file.getFullPath();
5149
}
5250

53-
/*
54-
* @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
55-
*/
5651
@Override
5752
protected void setReadOnly(boolean state) throws Exception {
5853
IFile file= FileBuffers.getWorkspaceFileAtLocation(getPath());
@@ -94,8 +89,6 @@ protected boolean modifyUnderlyingFile() throws Exception {
9489
try (OutputStream out= fileStore.openOutputStream(EFS.NONE, null)) {
9590
out.write("Changed content of workspace file".getBytes());
9691
out.flush();
97-
} catch (IOException x) {
98-
fail();
9992
}
10093
IFileInfo fileInfo= fileStore.fetchInfo();
10194
fileInfo.setLastModified(1000);

0 commit comments

Comments
 (0)