Hi folks, I have a method that has to return true if the name is matched by the regular expression or null if the name has special characters or numbers.
This is the method:
@SuppressWarnings("null")
public boolean containsSpecialCharacters(String text) {
Pattern p = Pattern.compile("/^[a-zA-Z\\s]+$/");
//check if the name has special characters
Matcher m = p.matcher(text);
boolean b = m.find();
//cast the null to boolean
Boolean boolean1 = (Boolean) null;
if (m.matches()) {
return true;
}
else {
return boolean1;
}
}
**And this is the test for the method that cannot pass!**
@Test
public void parseBeanCheck() throws NumberFormatException, IOException, SAXException, IntrospectionException {
IngenicoForwardingHelper helper = new IngenicoForwardingHelper();
String test1 = "Steve Jobs";
Assert.assertTrue(helper.containsSpecialCharacters(test1));
//This should return Null
String test2 = "Steve Jobs1";
Assert.assertNull(helper.containsSpecialCharacters(test2));
//This should return Null
String test3 = "Steve Jöbs";
Assert.assertNull(helper.containsSpecialCharacters(test3));
}
Aucun commentaire:
Enregistrer un commentaire