我在下面的代码中的错误是什么,特别是在&test;测试电子邮件地址#()'?
package de.hhn.pp.addressBook.test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import de.hhn.pp.addressBook.logic.ContactImplementation;
import de.hhn.pp.addressbook.api.exceptions.StringNotValidException;
@RunWith(Parameterized.class)
public class Asd {
private String email;
private boolean expectedValue;
private ContactImplementation contact;
public Asd(final String email, final boolean expectedValue) {
this.email = email;
this.expectedValue = expectedValue;
}
/**
* Data.
*
* @return the collection
*/
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] {
// INVALID EMAIL ADDRESSES
// it is not allowed to have digits in the Top Level Domain
{ "personalproductivity@hotmail.com2", false },
// it is not allowed to have the '@' twice
{ "personal@productivity@hotmail.de", false },
// it is not allowed to have special character such as '!'
{ "personal!productivity!@hotmail.de", false },
// Top Level Domain cannot start with a '.'
{ "personalproductivity@.gmail.com", false },
// email address must contain a '@'
{ "personalproductivity.de", false },
// email address must contain a Top Level Domain
{ "personalproductivity@", false },
// it is not allowed to have double '.'
{ "personal..productivity@web.de", false },
// it is not allowed to start with a '.'
{ ".personalproductivity@gmx.edu", false },
// VALID EMAIL ADDRESSES
{ "personalproductivity@hotmail.de", true },
{ "personal+productivity@hotmail.com", true },
{ "personalproductivity2015@web.edu", true },
{ "personal.productivity-SS15@gmail.com", true } };
return Arrays.asList(data);
}
@Test(expected = StringNotValidException.class)
public void testSetEmailString() {
contact.setEmail(email);
}
@Test
public void testIsEmailPatternValid() {
boolean result = ContactImplementation.isEmailPatternValid(email);
assertEquals("Result", this.expectedValue, result);
}
}
在我实现的类中,第一个方法&#39; setEmail(String)&#39;通过检查静态方法&#39; isEmailPatternValid&#39;来设置新的电子邮件地址。返回true。如果电子邮件无效,则抛出一个新的异常,StringNotValidException。
isEmailPatternValid测试效果很好。但我想检查setEmail方法以获得更好的代码覆盖率。我在异常测试中遇到了问题。