Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Metody {
- public boolean validateZipCode(String zipCode) {
- return zipCode.matches("\\d{2}-\\d{3}");
- }
- public static List<String> findEmails(String longText) {
- Pattern p = Pattern.compile("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\\\"(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21\\\\x23-\\\\x5b\\\\x5d-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])*\\\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\\\x01-\\\\x08\\\\x0b\\\\x0c\\\\x0e-\\\\x1f\\\\x21-\\\\x5a\\\\x53-\\\\x7f]|\\\\\\\\[\\\\x01-\\\\x09\\\\x0b\\\\x0c\\\\x0e-\\\\x7f])+)\\\\])");
- Matcher m = p.matcher(longText);
- List<String> results = new ArrayList<>();
- while(m.find()) {
- results.add(m.group());
- }
- return results;
- }
- }
- import java.util.ArrayList;
- import java.util.List;
- import org.junit.Test;
- import static org.junit.Assert.*;
- /**
- *
- * @author kc
- */
- public class MetodyTest {
- /**
- * Test of validateZipCode method, of class Metody.
- */
- @Test
- public void testValidateZipCode() {
- System.out.println("validateZipCode");
- String zipCode = "80-855";
- Metody instance = new Metody();
- boolean expResult = true;
- boolean result = instance.validateZipCode(zipCode);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- @Test
- public void testValidateZipCode2() {
- System.out.println("validateZipCode");
- String zipCode = "abcd";
- Metody instance = new Metody();
- boolean expResult = false;
- boolean result = instance.validateZipCode(zipCode);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- @Test
- public void testValidateZipCode3() {
- System.out.println("validateZipCode");
- String zipCode = "tekst 85-855";
- Metody instance = new Metody();
- boolean expResult = false;
- boolean result = instance.validateZipCode(zipCode);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- /**
- * Test of findEmails method, of class Metody.
- */
- @Test
- public void testFindEmails() {
- System.out.println("findEmails");
- String longText = "gsajkldgaklsgajgemail@o2.pldsajaskdaljfalsfkalkf lkfajsjjjjskk looqeiq kar.cie@gmail.com djkjdjutuj 812841 1.@@85.com";
- List<String> expResult = new ArrayList();
- expResult.add("kar.cie@gmail.com");
- expResult.add("email@o2.pl");
- List<String> result = Metody.findEmails(longText);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- @Test
- public void testFindEmails2() {
- System.out.println("findEmails");
- String longText = "błąd/..@gmail.com email123@gmail.com złymai_.l@@test.pl";
- List<String> expResult = new ArrayList();
- expResult.add("email123@gmail.com");
- List<String> result = Metody.findEmails(longText);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- @Test
- public void testFindEmails3() {
- System.out.println("findEmails");
- String longText = "Pusty tekst, oczekiwany brak adresów email.";
- List<String> expResult = new ArrayList();
- List<String> result = Metody.findEmails(longText);
- assertEquals(expResult, result);
- // TODO review the generated test code and remove the default call to fail.
- fail("The test case is a prototype.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement