Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mockito-testng from 0.1.1 to 0.2.0 #209

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/simplify4u/plugins/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;

import org.bouncycastle.openpgp.PGPPublicKey;
import org.mockito.Mockito;

/**
* @author Slawomir Jaranowski.
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -99,19 +99,14 @@ public List<PGPKeysServerClient> 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
Expand Down
25 changes: 19 additions & 6 deletions src/test/java/org/simplify4u/plugins/keysmap/KeysMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -60,7 +59,7 @@ public void isComponentSet() {

@Test
public void nullLocationTest() throws Exception {
reset(resourceManager);
// reset(resourceManager);
keysMap.load(null);

verifyNoInteractions(resourceManager);
Expand All @@ -69,7 +68,7 @@ public void nullLocationTest() throws Exception {

@Test
public void emptyLocationTest() throws Exception {
reset(resourceManager);
// reset(resourceManager);
keysMap.load("");

verifyNoInteractions(resourceManager);
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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");

Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*
Expand Down