Skip to content

Commit 4fbbe1b

Browse files
committed
Get rid of ArrayUtil.equals(Object[], Object[])
Use JUnit's assertArrayEquals or JVM's Arrays.equals instead.
1 parent ec2d9bd commit 4fbbe1b

File tree

5 files changed

+40
-72
lines changed

5 files changed

+40
-72
lines changed

tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/ArrayUtil.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2014 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 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
@@ -71,21 +71,4 @@ public static boolean contains(Object[] array, Object element) {
7171
return false;
7272
}
7373

74-
/**
75-
* Returns whether two arrays are equal. They must
76-
* have the same size and the same contents.
77-
*
78-
* @param one the first array
79-
* @param two the second array
80-
* @return <code>true</code> if the array are equal,
81-
* <code>false</code> otherwise.
82-
*/
83-
public static boolean equals(Object[] one, Object[] two) {
84-
if (one.length != two.length)
85-
return false;
86-
for (int i = 0; i < one.length; i++)
87-
if (one[i] != two[i])
88-
return false;
89-
return true;
90-
}
9174
}

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IAggregateWorkingSetTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 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
@@ -34,7 +34,6 @@
3434
import org.eclipse.ui.internal.AbstractWorkingSetManager;
3535
import org.eclipse.ui.internal.AggregateWorkingSet;
3636
import org.eclipse.ui.internal.IWorkbenchConstants;
37-
import org.eclipse.ui.tests.harness.util.ArrayUtil;
3837
import org.eclipse.ui.tests.harness.util.UITestCase;
3938
import org.junit.Ignore;
4039
import org.junit.Test;
@@ -128,9 +127,7 @@ public void testGetElemets() throws Throwable {
128127
//</possible client code>
129128

130129
//unexpected
131-
assertTrue(ArrayUtil.equals(
132-
new IAdaptable[] {},
133-
fWorkingSet.getElements()));
130+
assertArrayEquals(new IAdaptable[] {}, fWorkingSet.getElements());
134131
}
135132

136133
/**

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IEditorRegistryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 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
@@ -123,7 +123,7 @@ public void testGetEditors() throws Throwable {
123123
assertEquals(editors[0].getId(), map[1]);
124124
editors2 = fReg.getEditors(FileUtil.createFile(map[0], proj)
125125
.getName());
126-
assertEquals(ArrayUtil.equals(editors, editors2), true);
126+
assertArrayEquals(editors, editors2);
127127
}
128128

129129
// there is no matching editor

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkingSetManagerTest.java

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 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,6 +14,10 @@
1414
*******************************************************************************/
1515
package org.eclipse.ui.tests.api;
1616

17+
import static org.junit.Assert.assertArrayEquals;
18+
19+
import java.util.Arrays;
20+
1721
import org.eclipse.core.resources.IWorkspace;
1822
import org.eclipse.core.resources.ResourcesPlugin;
1923
import org.eclipse.core.runtime.IAdaptable;
@@ -161,22 +165,19 @@ public void testAddPropertyChangeListener() throws Throwable {
161165
public void testAddRecentWorkingSet() throws Throwable {
162166
fWorkingSetManager.addRecentWorkingSet(fWorkingSet);
163167
fWorkingSetManager.addWorkingSet(fWorkingSet);
164-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
165-
fWorkingSetManager.getRecentWorkingSets()));
168+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getRecentWorkingSets());
166169

167170
IWorkingSet workingSet2 = fWorkingSetManager.createWorkingSet(
168171
WORKING_SET_NAME_2, new IAdaptable[] { fWorkspace.getRoot() });
169172
fWorkingSetManager.addRecentWorkingSet(workingSet2);
170173
fWorkingSetManager.addWorkingSet(workingSet2);
171-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { workingSet2,
172-
fWorkingSet }, fWorkingSetManager.getRecentWorkingSets()));
174+
assertArrayEquals(new IWorkingSet[] { workingSet2, fWorkingSet }, fWorkingSetManager.getRecentWorkingSets());
173175
}
174176

175177
@Test
176178
public void testAddWorkingSet() throws Throwable {
177179
fWorkingSetManager.addWorkingSet(fWorkingSet);
178-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
179-
fWorkingSetManager.getWorkingSets()));
180+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getWorkingSets());
180181

181182
boolean exceptionThrown = false;
182183
try {
@@ -185,23 +186,20 @@ public void testAddWorkingSet() throws Throwable {
185186
exceptionThrown = true;
186187
}
187188
assertTrue(exceptionThrown);
188-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
189-
fWorkingSetManager.getWorkingSets()));
189+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getWorkingSets());
190190
}
191191

192192
@Test
193193
public void testCreateWorkingSet() throws Throwable {
194194
IWorkingSet workingSet2 = fWorkingSetManager.createWorkingSet(
195195
WORKING_SET_NAME_2, new IAdaptable[] { fWorkspace.getRoot() });
196196
assertEquals(WORKING_SET_NAME_2, workingSet2.getName());
197-
assertTrue(ArrayUtil.equals(new IAdaptable[] { fWorkspace.getRoot() },
198-
workingSet2.getElements()));
197+
assertArrayEquals(new IAdaptable[] { fWorkspace.getRoot() }, workingSet2.getElements());
199198

200199
workingSet2 = fWorkingSetManager.createWorkingSet("",
201200
new IAdaptable[] {});
202201
assertEquals("", workingSet2.getName());
203-
assertTrue(ArrayUtil.equals(new IAdaptable[] {}, workingSet2
204-
.getElements()));
202+
assertArrayEquals(new IAdaptable[] {}, workingSet2.getElements());
205203
}
206204

207205
@Test
@@ -213,8 +211,7 @@ public void testCreateWorkingSetFromMemento() throws Throwable {
213211
IWorkingSet restoredWorkingSet2 = fWorkingSetManager
214212
.createWorkingSet(memento);
215213
assertEquals(WORKING_SET_NAME_2, restoredWorkingSet2.getName());
216-
assertTrue(ArrayUtil.equals(new IAdaptable[] { fWorkspace.getRoot() },
217-
restoredWorkingSet2.getElements()));
214+
assertArrayEquals(new IAdaptable[] { fWorkspace.getRoot() }, restoredWorkingSet2.getElements());
218215
}
219216

220217
@Test
@@ -232,19 +229,16 @@ public void testGetRecentWorkingSets() throws Throwable {
232229

233230
fWorkingSetManager.addRecentWorkingSet(fWorkingSet);
234231
fWorkingSetManager.addWorkingSet(fWorkingSet);
235-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
236-
fWorkingSetManager.getRecentWorkingSets()));
232+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getRecentWorkingSets());
237233

238234
IWorkingSet workingSet2 = fWorkingSetManager.createWorkingSet(
239235
WORKING_SET_NAME_2, new IAdaptable[] { fWorkspace.getRoot() });
240236
fWorkingSetManager.addRecentWorkingSet(workingSet2);
241237
fWorkingSetManager.addWorkingSet(workingSet2);
242-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { workingSet2,
243-
fWorkingSet }, fWorkingSetManager.getRecentWorkingSets()));
238+
assertArrayEquals(new IWorkingSet[] { workingSet2, fWorkingSet }, fWorkingSetManager.getRecentWorkingSets());
244239

245240
fWorkingSetManager.removeWorkingSet(workingSet2);
246-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
247-
fWorkingSetManager.getRecentWorkingSets()));
241+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getRecentWorkingSets());
248242
}
249243

250244
@Test
@@ -261,12 +255,12 @@ public void testRecentWorkingSetsLength() throws Throwable {
261255
fWorkingSetManager.addWorkingSet(workingSet);
262256
workingSets[9 - i] = workingSet;
263257
}
264-
assertTrue(ArrayUtil.equals(workingSets, fWorkingSetManager.getRecentWorkingSets()));
258+
assertArrayEquals(workingSets, fWorkingSetManager.getRecentWorkingSets());
265259

266260
fWorkingSetManager.setRecentWorkingSetsLength(7);
267261
IWorkingSet[] workingSets7 = new IWorkingSet[7];
268262
System.arraycopy(workingSets, 0, workingSets7, 0, 7);
269-
assertTrue(ArrayUtil.equals(workingSets7, fWorkingSetManager.getRecentWorkingSets()));
263+
assertArrayEquals(workingSets7, fWorkingSetManager.getRecentWorkingSets());
270264

271265
fWorkingSetManager.setRecentWorkingSetsLength(9);
272266
IWorkingSet[] workingSets9 = new IWorkingSet[9];
@@ -280,7 +274,7 @@ public void testRecentWorkingSetsLength() throws Throwable {
280274
workingSets9[8 - i] = workingSet;
281275
}
282276

283-
assertTrue(ArrayUtil.equals(workingSets9, fWorkingSetManager.getRecentWorkingSets()));
277+
assertArrayEquals(workingSets9, fWorkingSetManager.getRecentWorkingSets());
284278
} finally {
285279
if (oldMRULength > 0) {
286280
fWorkingSetManager.setRecentWorkingSetsLength(oldMRULength);
@@ -302,20 +296,17 @@ public void testGetWorkingSet() throws Throwable {
302296

303297
@Test
304298
public void testGetWorkingSets() throws Throwable {
305-
assertTrue(ArrayUtil.equals(new IWorkingSet[] {}, fWorkingSetManager
306-
.getWorkingSets()));
299+
assertArrayEquals(new IWorkingSet[] {}, fWorkingSetManager.getWorkingSets());
307300

308301
fWorkingSetManager.addWorkingSet(fWorkingSet);
309-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
310-
fWorkingSetManager.getWorkingSets()));
302+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getWorkingSets());
311303

312304
try {
313305
fWorkingSetManager.addWorkingSet(fWorkingSet);
314306
fail("Added the same set twice");
315307
} catch (RuntimeException exception) {
316308
}
317-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
318-
fWorkingSetManager.getWorkingSets()));
309+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, fWorkingSetManager.getWorkingSets());
319310

320311
IWorkingSet workingSet2 = fWorkingSetManager.createWorkingSet(
321312
WORKING_SET_NAME_2, new IAdaptable[] { fWorkspace.getRoot() });
@@ -369,16 +360,14 @@ public void testRemovePropertyChangeListener() throws Throwable {
369360
@Test
370361
public void testRemoveWorkingSet() throws Throwable {
371362
fWorkingSetManager.removeWorkingSet(fWorkingSet);
372-
assertTrue(ArrayUtil.equals(new IWorkingSet[] {}, fWorkingSetManager
373-
.getWorkingSets()));
363+
assertArrayEquals(new IWorkingSet[] {}, fWorkingSetManager.getWorkingSets());
374364

375365
fWorkingSetManager.addWorkingSet(fWorkingSet);
376366
IWorkingSet workingSet2 = fWorkingSetManager.createWorkingSet(
377367
WORKING_SET_NAME_2, new IAdaptable[] { fWorkspace.getRoot() });
378368
fWorkingSetManager.addWorkingSet(workingSet2);
379369
fWorkingSetManager.removeWorkingSet(fWorkingSet);
380-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { workingSet2 },
381-
fWorkingSetManager.getWorkingSets()));
370+
assertArrayEquals(new IWorkingSet[] { workingSet2 }, fWorkingSetManager.getWorkingSets());
382371
}
383372

384373
@Test
@@ -391,9 +380,7 @@ public void testRemoveWorkingSetAfterRename() throws Throwable {
391380
String origName=fWorkingSet.getName();
392381

393382
/* check that workingSetManager contains "fWorkingSet"*/
394-
assertTrue(ArrayUtil.equals(
395-
new IWorkingSet[] { fWorkingSet },
396-
workingSetManager.getWorkingSets()));
383+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, workingSetManager.getWorkingSets());
397384

398385
fWorkingSet.setName(" ");
399386
assertEquals(" ", fWorkingSet.getName());
@@ -402,7 +389,7 @@ public void testRemoveWorkingSetAfterRename() throws Throwable {
402389
workingSetManager.removeWorkingSet(fWorkingSet);
403390

404391
/* check that "fWorkingSet" was removed after rename*/
405-
if(!ArrayUtil.equals(new IWorkingSet[] {},
392+
if (!Arrays.equals(new IWorkingSet[] {},
406393
workingSetManager.getWorkingSets())){
407394
/*Test Failure, report after restoring state*/
408395
fWorkingSet.setName(origName);

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkingSetTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 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
@@ -13,6 +13,10 @@
1313
*******************************************************************************/
1414
package org.eclipse.ui.tests.api;
1515

16+
import static org.junit.Assert.assertArrayEquals;
17+
18+
import java.util.Arrays;
19+
1620
import org.eclipse.core.resources.IFile;
1721
import org.eclipse.core.resources.IProject;
1822
import org.eclipse.core.resources.IWorkspace;
@@ -24,7 +28,6 @@
2428
import org.eclipse.ui.IWorkingSetManager;
2529
import org.eclipse.ui.XMLMemento;
2630
import org.eclipse.ui.internal.WorkingSet;
27-
import org.eclipse.ui.tests.harness.util.ArrayUtil;
2831
import org.eclipse.ui.tests.harness.util.FileUtil;
2932
import org.eclipse.ui.tests.harness.util.UITestCase;
3033
import org.eclipse.ui.tests.menus.ObjectContributionClasses.IA;
@@ -101,7 +104,7 @@ public void testSetElements() throws Throwable {
101104
IFile f1 = FileUtil.createFile("f1.txt", p1);
102105
IAdaptable[] elements = new IAdaptable[] { f1, p1 };
103106
fWorkingSet.setElements(elements);
104-
assertTrue(ArrayUtil.equals(elements, fWorkingSet.getElements()));
107+
assertArrayEquals(elements, fWorkingSet.getElements());
105108

106109
fWorkingSet.setElements(new IAdaptable[] { f1 });
107110
assertEquals(f1, fWorkingSet.getElements()[0]);
@@ -160,17 +163,16 @@ public void testNoDuplicateWorkingSetName() throws Throwable {
160163
/*
161164
* check that initially workingSetManager contains "fWorkingSet"
162165
*/
163-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
164-
workingSetManager.getWorkingSets()));
166+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, workingSetManager.getWorkingSets());
165167

166168
IWorkingSet wSet = workingSetManager.createWorkingSet(
167169
WORKING_SET_NAME_2, new IAdaptable[] {});
168170
workingSetManager.addWorkingSet(wSet);
169171

170172
/* check that workingSetManager contains "fWorkingSet" and wSet */
171-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet, wSet },
173+
assertTrue(Arrays.equals(new IWorkingSet[] { fWorkingSet, wSet },
172174
workingSetManager.getWorkingSets())
173-
|| ArrayUtil.equals(new IWorkingSet[] { wSet, fWorkingSet },
175+
|| Arrays.equals(new IWorkingSet[] { wSet, fWorkingSet },
174176
workingSetManager.getWorkingSets()));
175177

176178
String sameName = fWorkingSet.getName();
@@ -198,8 +200,7 @@ public void testNoDuplicateWorkingSetNamesDifferentLabels()
198200
/*
199201
* check that initially workingSetManager contains "fWorkingSet"
200202
*/
201-
assertTrue(ArrayUtil.equals(new IWorkingSet[] { fWorkingSet },
202-
workingSetManager.getWorkingSets()));
203+
assertArrayEquals(new IWorkingSet[] { fWorkingSet }, workingSetManager.getWorkingSets());
203204

204205
String sameName = fWorkingSet.getName();
205206
IWorkingSet wSet = workingSetManager.createWorkingSet(sameName,

0 commit comments

Comments
 (0)