Upgrade all tests to JUnit 5

This commit is contained in:
Richard Körber
2022-05-14 12:24:21 +02:00
parent edf2018433
commit f3c7e8a46c
57 changed files with 435 additions and 416 deletions

View File

@@ -40,7 +40,7 @@ public interface ResponseBodyGenerator {
/**
* The content-type of the response body: {@value #RESPONSE_BODY_TYPE}
*/
public static final String RESPONSE_BODY_TYPE = "text/plain";
String RESPONSE_BODY_TYPE = "text/plain";
/**
* Sets the content of the {@link Message}.

View File

@@ -18,7 +18,7 @@ import static org.hamcrest.Matchers.is;
import jakarta.mail.internet.AddressException;
import jakarta.mail.internet.InternetAddress;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests of {@link EmailIdentifier}.

View File

@@ -15,11 +15,12 @@ package org.shredzone.acme4j.smime.challenge;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.net.URI;
import java.net.URL;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Status;
import org.shredzone.acme4j.challenge.Challenge;
import org.shredzone.acme4j.provider.AbstractAcmeProvider;
@@ -63,10 +64,12 @@ public class EmailReply00ChallengeTest extends SMIMETests {
/**
* Test that {@link EmailReply00Challenge#getAuthorization()} is not implemented.
*/
@Test(expected = UnsupportedOperationException.class)
@Test
public void testInvalidGetAuthorization() {
EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge"));
challenge.getAuthorization();
assertThrows(UnsupportedOperationException.class, () -> {
EmailReply00Challenge challenge = new EmailReply00Challenge(mockLogin(), getJSON("emailReplyChallenge"));
challenge.getAuthorization();
});
}
/**

View File

@@ -16,7 +16,7 @@ package org.shredzone.acme4j.smime.csr;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -47,9 +47,8 @@ import org.bouncycastle.pkcs.PKCS10CertificationRequest;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.util.KeyPairUtils;
/**
@@ -60,7 +59,7 @@ public class SMIMECSRBuilderTest {
private static KeyPair testKey;
private static KeyPair testEcKey;
@BeforeClass
@BeforeAll
public static void setup() {
Security.addProvider(new BouncyCastleProvider());
@@ -241,10 +240,12 @@ public class SMIMECSRBuilderTest {
/**
* Make sure an exception is thrown when nothing is set.
*/
@Test(expected = IllegalStateException.class)
@Test
public void testNoEmail() throws IOException {
SMIMECSRBuilder builder = new SMIMECSRBuilder();
builder.sign(testKey);
assertThrows(IllegalStateException.class, () -> {
SMIMECSRBuilder builder = new SMIMECSRBuilder();
builder.sign(testKey);
});
}
/**
@@ -254,13 +255,13 @@ public class SMIMECSRBuilderTest {
public void testNoSign() throws IOException {
SMIMECSRBuilder builder = new SMIMECSRBuilder();
assertThrows("getCSR", IllegalStateException.class, builder::getCSR);
assertThrows("getEncoded", IllegalStateException.class, builder::getEncoded);
assertThrows("write", IllegalStateException.class,() -> {
assertThrows(IllegalStateException.class, builder::getCSR, "getCSR");
assertThrows(IllegalStateException.class, builder::getEncoded, "getEncoded");
assertThrows(IllegalStateException.class, () -> {
try (StringWriter w = new StringWriter()) {
builder.write(w);
}
});
},"write");
}
/**

View File

@@ -16,6 +16,7 @@ package org.shredzone.acme4j.smime.email;
import static jakarta.mail.Message.RecipientType.TO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.util.Optional;
@@ -23,7 +24,7 @@ import java.util.Optional;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.shredzone.acme4j.Identifier;
import org.shredzone.acme4j.exception.AcmeProtocolException;
import org.shredzone.acme4j.smime.EmailIdentifier;
@@ -35,10 +36,10 @@ import org.shredzone.acme4j.smime.challenge.EmailReply00Challenge;
*/
public class EmailProcessorTest extends SMIMETests {
private InternetAddress expectedFrom = email("acme-generator@example.org");
private InternetAddress expectedTo = email("alexey@example.com");
private InternetAddress expectedReplyTo = email("acme-validator@example.org");
private Message message = mockMessage("challenge");
private final InternetAddress expectedFrom = email("acme-generator@example.org");
private final InternetAddress expectedTo = email("alexey@example.com");
private final InternetAddress expectedReplyTo = email("acme-validator@example.org");
private final Message message = mockMessage("challenge");
@Test
public void testEmailParser() throws MessagingException {
@@ -55,46 +56,60 @@ public class EmailProcessorTest extends SMIMETests {
assertThat(processor.getReplyTo(), contains(email("acme-validator@example.org")));
}
@Test(expected = AcmeProtocolException.class)
@Test
public void textExpectedFromFails() {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedFrom(expectedTo);
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedFrom(expectedTo);
});
}
@Test(expected = AcmeProtocolException.class)
@Test
public void textExpectedToFails() {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedTo(expectedFrom);
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedTo(expectedFrom);
});
}
@Test(expected = AcmeProtocolException.class)
@Test
public void textExpectedIdentifierFails1() {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(EmailIdentifier.email(expectedFrom));
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(EmailIdentifier.email(expectedFrom));
});
}
@Test(expected = AcmeProtocolException.class)
@Test
public void textExpectedIdentifierFails2() {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(Identifier.ip("192.168.0.1"));
assertThrows(AcmeProtocolException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.expectedIdentifier(Identifier.ip("192.168.0.1"));
});
}
@Test(expected = IllegalStateException.class)
@Test
public void textNoChallengeFails1() {
EmailProcessor processor = new EmailProcessor(message);
processor.getToken();
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.getToken();
});
}
@Test(expected = IllegalStateException.class)
@Test
public void textNoChallengeFails2() {
EmailProcessor processor = new EmailProcessor(message);
processor.getAuthorization();
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.getAuthorization();
});
}
@Test(expected = IllegalStateException.class)
@Test
public void textNoChallengeFails3() {
EmailProcessor processor = new EmailProcessor(message);
processor.respond();
assertThrows(IllegalStateException.class, () -> {
EmailProcessor processor = new EmailProcessor(message);
processor.respond();
});
}
@Test
@@ -108,11 +123,13 @@ public class EmailProcessorTest extends SMIMETests {
assertThat(processor.respond(), is(notNullValue()));
}
@Test(expected = AcmeProtocolException.class)
@Test
public void testChallengeMismatch() {
EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch");
EmailProcessor processor = new EmailProcessor(message);
processor.withChallenge(challenge);
assertThrows(AcmeProtocolException.class, () -> {
EmailReply00Challenge challenge = mockChallenge("emailReplyChallengeMismatch");
EmailProcessor processor = new EmailProcessor(message);
processor.withChallenge(challenge);
});
}
@Test