diff --git a/pom.xml b/pom.xml
index c65f37a7..fa47a9a5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -265,7 +265,7 @@
org.mockito
mockito-testng
- 0.1.1
+ 0.2.0
test
diff --git a/src/test/java/org/simplify4u/plugins/TestUtils.java b/src/test/java/org/simplify4u/plugins/TestUtils.java
index b22dbab3..34653736 100644
--- a/src/test/java/org/simplify4u/plugins/TestUtils.java
+++ b/src/test/java/org/simplify4u/plugins/TestUtils.java
@@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;
import org.bouncycastle.openpgp.PGPPublicKey;
+import org.mockito.Mockito;
/**
* @author Slawomir Jaranowski.
@@ -45,7 +46,7 @@ public static PGPPublicKey getPGPgpPublicKey(long keyID) {
bytes = Arrays.copyOfRange(bytes, 1, bytes.length);
}
- PGPPublicKey pgpKey = mock(PGPPublicKey.class);
+ PGPPublicKey pgpKey = mock(PGPPublicKey.class, Mockito.withSettings().lenient());
when(pgpKey.getFingerprint()).thenReturn(bytes);
when(pgpKey.isMasterKey()).thenReturn(true);
diff --git a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java
index 6151df6e..39837aac 100644
--- a/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java
+++ b/src/test/java/org/simplify4u/plugins/keyserver/PGPKeysCacheTest.java
@@ -45,14 +45,12 @@
import com.google.common.io.ByteStreams;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
-import io.vavr.control.Try;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoSession;
import org.mockito.Spy;
+import org.mockito.testng.MockitoTestNGListener;
import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerList;
import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerListFallback;
import org.simplify4u.plugins.keyserver.PGPKeysCache.KeyServerListLoadBalance;
@@ -63,8 +61,10 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
+@Listeners(MockitoTestNGListener.class)
public class PGPKeysCacheTest {
public static final PGPKeyId KEY_ID_1 = PGPKeyId.from(1L);
@@ -99,19 +99,14 @@ public List prepareKeyServerClient() throws IOException {
return Collections.singletonList(keysServerClient);
}
- MockitoSession mockitoSession;
-
@BeforeMethod
void setup() throws IOException {
- mockitoSession = Mockito.mockitoSession().initMocks(this).startMocking();
cachePath = Files.createTempDirectory("cache-path-test");
}
@AfterMethod
- void cleanup() {
- Try.run(() -> MoreFiles.deleteRecursively(cachePath, RecursiveDeleteOption.ALLOW_INSECURE))
- .andFinallyTry(mockitoSession::finishMocking)
- .get();
+ void cleanup() throws IOException {
+ MoreFiles.deleteRecursively(cachePath, RecursiveDeleteOption.ALLOW_INSECURE);
}
@Test
diff --git a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java
index d6247a45..a911c91d 100644
--- a/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java
+++ b/src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java
@@ -18,7 +18,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.simplify4u.plugins.TestArtifactBuilder.testArtifact;
@@ -49,8 +48,8 @@ public class KeysMapTest {
@BeforeMethod
void setup() throws ResourceNotFoundException {
- doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
- .when(resourceManager).getResourceAsInputStream(anyString());
+// doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+// .when(resourceManager).getResourceAsInputStream(anyString());
}
@Test
@@ -60,7 +59,7 @@ public void isComponentSet() {
@Test
public void nullLocationTest() throws Exception {
- reset(resourceManager);
+// reset(resourceManager);
keysMap.load(null);
verifyNoInteractions(resourceManager);
@@ -69,7 +68,7 @@ public void nullLocationTest() throws Exception {
@Test
public void emptyLocationTest() throws Exception {
- reset(resourceManager);
+// reset(resourceManager);
keysMap.load("");
verifyNoInteractions(resourceManager);
@@ -79,6 +78,9 @@ public void emptyLocationTest() throws Exception {
@Test
public void validKeyFromMap() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
+
keysMap.load("/keysMap.list");
verify(resourceManager).getResourceAsInputStream(anyString());
@@ -137,6 +139,9 @@ public void validKeyFromMap() throws Exception {
@Test
public void invalidKeyFromMap() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
+
keysMap.load("/keysMap.list");
verify(resourceManager).getResourceAsInputStream(anyString());
@@ -150,6 +155,8 @@ public void invalidKeyFromMap() throws Exception {
@Test
public void specialValueNoSig() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
keysMap.load("/keysMap.list");
@@ -177,6 +184,8 @@ public void specialValueNoSig() throws Exception {
@Test
public void specialValueBadSig() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
keysMap.load("/keysMap.list");
@@ -189,6 +198,8 @@ public void specialValueBadSig() throws Exception {
@Test
public void specialValueNoKey() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
keysMap.load("/keysMap.list");
@@ -201,9 +212,11 @@ public void specialValueNoKey() throws Exception {
@Test
public void shortKeyShouldThrownException() throws Exception {
+ doAnswer(invocation -> getClass().getResourceAsStream(invocation.getArgument(0)))
+ .when(resourceManager).getResourceAsInputStream(anyString());
+
Assertions.assertThatCode(() -> keysMap.load("/keyMap-keyToShort.list"))
.isExactlyInstanceOf(IllegalArgumentException.class)
.hasMessage("Key length for = 0x10 is 8 bits, should be between 64 and 160 bits");
-
}
}
diff --git a/src/test/java/org/simplify4u/plugins/utils/MavenProxyTest.java b/src/test/java/org/simplify4u/plugins/utils/MavenProxyTest.java
index 74221b9a..a6167756 100644
--- a/src/test/java/org/simplify4u/plugins/utils/MavenProxyTest.java
+++ b/src/test/java/org/simplify4u/plugins/utils/MavenProxyTest.java
@@ -32,6 +32,7 @@
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.simplify4u.plugins.AbstractPGPMojo;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@@ -47,6 +48,12 @@ public class MavenProxyTest {
@InjectMocks
private MavenProxy mavenProxy;
+ @AfterMethod
+ void cleanup() {
+ // not possibility to setup final field in MavenProxy
+ mavenProxy = null;
+ }
+
/**
* test that if we set a proxy, we want to ensure that it is the right one from our config
*