Switch tests to JUnit 4

This commit is contained in:
Jan Dittberner 2015-10-20 17:59:57 +02:00
parent 21465a1be6
commit b009be3e17
3 changed files with 21 additions and 17 deletions

View file

@ -1,8 +1,7 @@
apply plugin: 'java' apply plugin: 'java'
project.version = '0.3-SNAPSHOT' project.version = '0.3-SNAPSHOT'
project.ext.name = 'bcsmime-demo' project.description = '''
project.ext.description = '''
Demonstrate how to perform S/MIME encryption and decryption of mails using BouncyCastle. Demonstrate how to perform S/MIME encryption and decryption of mails using BouncyCastle.
''' '''
@ -14,7 +13,7 @@ dependencies {
compile group: 'org.bouncycastle', name: 'bcmail-jdk15on', version: '1.53' compile group: 'org.bouncycastle', name: 'bcmail-jdk15on', version: '1.53'
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.53' compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.53'
compile group: 'javax.mail', name: 'mail', version: '1.4.4' compile group: 'javax.mail', name: 'mail', version: '1.4.4'
testCompile group: 'junit', name: 'junit', version: '3.8.1' testCompile group: 'junit', name: 'junit', version: '4.12'
} }
task wrapper(type: Wrapper) { task wrapper(type: Wrapper) {

View file

@ -49,7 +49,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -22,8 +22,13 @@
*/ */
package info.dittberner.bcsmime_demo; package info.dittberner.bcsmime_demo;
import junit.framework.TestCase; import java.io.ByteArrayOutputStream;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.io.IOException;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.Security;
import java.security.cert.Certificate;
import java.util.logging.Logger;
import javax.mail.BodyPart; import javax.mail.BodyPart;
import javax.mail.Message.RecipientType; import javax.mail.Message.RecipientType;
@ -34,13 +39,12 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeMultipart;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import org.bouncycastle.jce.provider.BouncyCastleProvider;
import java.security.KeyPairGenerator; import org.junit.Before;
import java.security.KeyStore; import org.junit.Test;
import java.security.Security;
import java.security.cert.Certificate; import static org.junit.Assert.assertNotNull;
import java.util.logging.Logger;
/** /**
* Test Encryption and Decryption. * Test Encryption and Decryption.
@ -49,7 +53,7 @@ import java.util.logging.Logger;
* "mailto:jan.dittberner@t-systems.com>jan.dittberner@t-systems.com</a> * "mailto:jan.dittberner@t-systems.com>jan.dittberner@t-systems.com</a>
* & g t ; * & g t ;
*/ */
public class EncryptDecryptTest extends TestCase { public class EncryptDecryptTest {
String[][] testEntries = new String[][]{ String[][] testEntries = new String[][]{
new String[]{"test1", "testrecpt1@example.org", "Test Recipient 1"}, new String[]{"test1", "testrecpt1@example.org", "Test Recipient 1"},
new String[]{"test2", "testrecpt2@example.org", "Test Recipient 2"} new String[]{"test2", "testrecpt2@example.org", "Test Recipient 2"}
@ -62,7 +66,7 @@ public class EncryptDecryptTest extends TestCase {
* *
* @see junit.framework.TestCase#setUp() * @see junit.framework.TestCase#setUp()
*/ */
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
@ -92,6 +96,7 @@ public class EncryptDecryptTest extends TestCase {
/** /**
* Test of {@link SMIMEEncrypt} and {@link SMIMEDecrypt}. * Test of {@link SMIMEEncrypt} and {@link SMIMEDecrypt}.
*/ */
@Test
public void testEncryptDecryptMail() throws Exception { public void testEncryptDecryptMail() throws Exception {
MimeMessage message = getNewMultipartMessage(); MimeMessage message = getNewMultipartMessage();
assertNotNull(message); assertNotNull(message);
@ -117,8 +122,8 @@ public class EncryptDecryptTest extends TestCase {
*/ */
private MimeMessage getNewMultipartMessage() throws MessagingException, private MimeMessage getNewMultipartMessage() throws MessagingException,
IOException { IOException {
MimeMessage message = new MimeMessage(Session.getDefaultInstance(System Session mailsession = Session.getDefaultInstance(System.getProperties());
.getProperties())); MimeMessage message = new MimeMessage(mailsession);
message.setFrom(new InternetAddress("testsender@example.org", message.setFrom(new InternetAddress("testsender@example.org",
"Test Sender")); "Test Sender"));
for (String[] entry : testEntries) { for (String[] entry : testEntries) {