Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java48
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/IUListFormatterTest.java45
3 files changed, 43 insertions, 54 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
index feb1cc712..7859591e4 100644
--- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF
@@ -54,7 +54,9 @@ Require-Bundle: org.eclipse.equinox.frameworkadmin,
org.eclipse.equinox.p2.operations;bundle-version="2.1.0",
org.eclipse.equinox.p2.ui.sdk.scheduler,
org.eclipse.equinox.p2.artifact.repository;bundle-version="[1.3.0,2.0.0)",
- org.hamcrest.library;bundle-version="1.3.0"
+ org.hamcrest.library;bundle-version="1.3.0",
+ org.mockito.mockito-core,
+ net.bytebuddy.byte-buddy
Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository
Bundle-RequiredExecutionEnvironment: JavaSE-11
Eclipse-BundleShape: dir
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
index 87a7e53fb..1a66379d9 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/ChecksumVerifierTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015, 2019 Mykola Nikishov.
+ * Copyright (c) 2015, 2021 Mykola Nikishov and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,12 +13,10 @@
*******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.processors;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.not;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.mockito.AdditionalMatchers.not;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
@@ -66,9 +64,8 @@ public class ChecksumVerifierTest {
@Test
public void testInitialize() throws IOException, IllegalArgumentException, SecurityException {
- IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
- expect(processingStepDescriptor.getData()).andReturn(checksum);
- replay(processingStepDescriptor);
+ IProcessingStepDescriptor processingStepDescriptor = mock(IProcessingStepDescriptor.class);
+ when(processingStepDescriptor.getData()).thenReturn(checksum);
ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, providerName, algorithmId, false);
@@ -77,21 +74,18 @@ public class ChecksumVerifierTest {
Assert.assertEquals(Status.OK_STATUS, verifier.getStatus());
verifier.close();
- verify(processingStepDescriptor);
}
@Test
public void testInitialize_DownloadChecksum() throws IOException, IllegalArgumentException, SecurityException {
- IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
- expect(processingStepDescriptor.getData()).andReturn(downloadProperty);
- IArtifactDescriptor artifactDescriptor = createMock(IArtifactDescriptor.class);
- replay(processingStepDescriptor);
- expect(artifactDescriptor.getProperty(eq(downloadProperty))).andReturn(checksum);
- expect(artifactDescriptor.getProperty(not(eq(downloadProperty)))).andReturn(null).times(1, 2);
+ IProcessingStepDescriptor processingStepDescriptor = mock(IProcessingStepDescriptor.class);
+ when(processingStepDescriptor.getData()).thenReturn(downloadProperty);
+ IArtifactDescriptor artifactDescriptor = mock(IArtifactDescriptor.class);
+ when(artifactDescriptor.getProperty(eq(downloadProperty))).thenReturn(checksum);
+ when(artifactDescriptor.getProperty(not(eq(downloadProperty)))).thenReturn(null);
HashMap<String, String> properties = new HashMap<>();
properties.put(downloadProperty, checksum);
- expect(artifactDescriptor.getProperties()).andReturn(properties);
- replay(artifactDescriptor);
+ when(artifactDescriptor.getProperties()).thenReturn(properties);
ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, providerName, algorithmId, false);
@@ -100,21 +94,18 @@ public class ChecksumVerifierTest {
Assert.assertEquals(Status.OK_STATUS, verifier.getStatus());
verifier.close();
- verify(processingStepDescriptor);
}
@Test
public void testInitialize_ArtifactChecksum() throws IOException, IllegalArgumentException, SecurityException {
- IProcessingStepDescriptor processingStepDescriptor = createMock(IProcessingStepDescriptor.class);
- expect(processingStepDescriptor.getData()).andReturn(artifactProperty);
- IArtifactDescriptor artifactDescriptor = createMock(IArtifactDescriptor.class);
- replay(processingStepDescriptor);
- expect(artifactDescriptor.getProperty(eq(artifactProperty))).andReturn(checksum);
+ IProcessingStepDescriptor processingStepDescriptor = mock(IProcessingStepDescriptor.class);
+ when(processingStepDescriptor.getData()).thenReturn(artifactProperty);
+ IArtifactDescriptor artifactDescriptor = mock(IArtifactDescriptor.class);
+ when(artifactDescriptor.getProperty(eq(artifactProperty))).thenReturn(checksum);
HashMap<String, String> properties = new HashMap<>();
properties.put(artifactProperty, checksum);
- expect(artifactDescriptor.getProperties()).andReturn(properties);
- expect(artifactDescriptor.getProperty(not(eq(artifactProperty)))).andReturn(null).times(1, 2);
- replay(artifactDescriptor);
+ when(artifactDescriptor.getProperties()).thenReturn(properties);
+ when(artifactDescriptor.getProperty(not(eq(artifactProperty)))).thenReturn(null);
ChecksumVerifier verifier = new ChecksumVerifier(digestAlgorithm, providerName, algorithmId, false);
@@ -123,6 +114,5 @@ public class ChecksumVerifierTest {
Assert.assertEquals(Status.OK_STATUS, verifier.getStatus());
verifier.close();
- verify(processingStepDescriptor);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/IUListFormatterTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/IUListFormatterTest.java
index efa48f080..a2e1bf8ea 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/IUListFormatterTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/director/IUListFormatterTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2017 SAP AG and others.
+ * Copyright (c) 2014, 2021 SAP AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,22 +14,21 @@
package org.eclipse.equinox.p2.tests.director;
import static java.util.Arrays.asList;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.getCurrentArguments;
-import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.easymock.IAnswer;
import org.eclipse.equinox.internal.p2.director.app.IUListFormatter;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
public class IUListFormatterTest {
@Test
@@ -75,37 +74,35 @@ public class IUListFormatterTest {
}
private static IInstallableUnit createIU(String id, String version, String name, String description) {
- IInstallableUnit iu = createNiceMock(id, IInstallableUnit.class);
- expect(iu.getId()).andStubReturn(id);
- expect(iu.getVersion()).andStubReturn(Version.create(version));
+ IInstallableUnit iu = mock(IInstallableUnit.class);
+ when(iu.getId()).thenReturn(id);
+ when(iu.getVersion()).thenReturn(Version.create(version));
final Map<String, String> properties = new HashMap<>(3, 1);
properties.put(IInstallableUnit.PROP_NAME, name);
properties.put(IInstallableUnit.PROP_DESCRIPTION, description);
- expect(iu.getProperties()).andStubReturn(properties);
- expect(iu.getProperty((String) anyObject())).andStubAnswer(new MapAnswer<>(properties));
- expect(iu.getProperty((String) anyObject(), (String) anyObject())).andStubAnswer(new MapAnswer<>(properties));
- replay(iu);
+ when(iu.getProperties()).thenReturn(properties);
+ when(iu.getProperty(anyString())).thenAnswer(new MapAnswer<>(properties));
+ when(iu.getProperty(anyString(), anyString())).thenAnswer(new MapAnswer<>(properties));
return iu;
}
private static IInstallableUnit createIU(String id, String version, int propCount) {
- IInstallableUnit iu = createNiceMock(id, IInstallableUnit.class);
- expect(iu.getId()).andStubReturn(id);
- expect(iu.getVersion()).andStubReturn(Version.create(version));
+ IInstallableUnit iu = mock(IInstallableUnit.class);
+ when(iu.getId()).thenReturn(id);
+ when(iu.getVersion()).thenReturn(Version.create(version));
final Map<String, String> properties = new HashMap<>(propCount, 1);
for (int i = 0; i < propCount; i++) {
properties.put("prop_" + i, "propValue_" + i);
}
- expect(iu.getProperties()).andStubReturn(properties);
- expect(iu.getProperty((String) anyObject())).andStubAnswer(new MapAnswer<>(properties));
- expect(iu.getProperty((String) anyObject(), (String) anyObject())).andStubAnswer(new MapAnswer<>(properties));
- replay(iu);
+ when(iu.getProperties()).thenReturn(properties);
+ when(iu.getProperty(anyString())).thenAnswer(new MapAnswer<>(properties));
+ when(iu.getProperty(anyString(), anyString())).thenAnswer(new MapAnswer<>(properties));
return iu;
}
- private static final class MapAnswer<T> implements IAnswer<T> {
+ private static final class MapAnswer<T> implements Answer<T> {
private final Map<?, T> map;
MapAnswer(Map<?, T> map) {
@@ -113,8 +110,8 @@ public class IUListFormatterTest {
}
@Override
- public T answer() throws Throwable {
- return map.get(getCurrentArguments()[0]);
+ public T answer(InvocationOnMock arg) throws Throwable {
+ return map.get(arg.getArguments()[0]);
}
}

Back to the top