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'
project.version = '0.3-SNAPSHOT'
project.ext.name = 'bcsmime-demo'
project.ext.description = '''
project.description = '''
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: 'bcprov-jdk15on', version: '1.53'
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) {

View file

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

View file

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