-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parametrized_tests and parametrized_tests.homework packages
- Loading branch information
1 parent
1a14625
commit d03deba
Showing
9 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
group = 'com.kodilla' | ||
version = '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.3' | ||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
8 changes: 8 additions & 0 deletions
8
kodilla-advanced-tests/src/main/java/com/kodilla/parametrized_tests/NumberChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
public class NumberChecker { | ||
|
||
public boolean isDivisibleByThree(int number) { | ||
return number % 3 == 0; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
kodilla-advanced-tests/src/main/java/com/kodilla/parametrized_tests/StringManipulator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
public class StringManipulator { | ||
|
||
public String reverseWithLowerCase(String input) { | ||
StringBuilder builder = new StringBuilder(input); | ||
return builder.reverse().toString().toLowerCase(); | ||
} | ||
|
||
public int getStringLengthWithoutSpaces(String input) { | ||
String value = input.replaceAll(" ", ""); | ||
return value.length(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
kodilla-advanced-tests/src/main/java/com/kodilla/parametrized_tests/StringValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
public class StringValidator { | ||
|
||
public boolean isBlank(String text) { | ||
return text == null || text.trim().isEmpty(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...a-advanced-tests/src/main/java/com/kodilla/parametrized_tests/homework/UserValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.kodilla.parametrized_tests.homework; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class UserValidator { | ||
public static boolean validateUsername(String username) { | ||
return username.matches("^[a-zA-Z0-9._-]{3,}$"); | ||
} | ||
|
||
public static boolean validateEmail(String email) { | ||
if (null != email) { | ||
String regex = "^([_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.[a-zA-Z]{1,6}))?$"; | ||
Pattern pattern = Pattern.compile(regex); | ||
Matcher matcher = pattern.matcher(email); | ||
return matcher.matches(); | ||
} | ||
return false; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...a-advanced-tests/src/test/java/com/kodilla/parametrized_tests/NumberCheckerTestSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class NumberCheckerTestSuite { | ||
|
||
private NumberChecker numberChecker = new NumberChecker(); | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {0, 3, 6, -3, -12, 15}) | ||
public void shouldReturnTrueForNumberDivisibleByThree(int number) { | ||
boolean result = numberChecker.isDivisibleByThree(number); | ||
assertTrue(result); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {-2, -1, 1, 2, 4, 5}) | ||
public void shouldReturnFalseForNumberNotDivisibleByThree(int number) { | ||
boolean result = numberChecker.isDivisibleByThree(number); | ||
assertFalse(result); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...vanced-tests/src/test/java/com/kodilla/parametrized_tests/StringManipulatorTestSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class StringManipulatorTestSuite { | ||
|
||
private StringManipulator manipulator = new StringManipulator(); | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"test,tset", "OtHEr,rehto", "EVent,tneve", "null,llun", "A,a"}) | ||
public void shouldReverseStringWithLowerCase(String input, String expected) { | ||
assertEquals(expected, manipulator.reverseWithLowerCase(input)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"test,4", " OtHEr ,5", "E V e n t,5", "null ,4", "A,1"}) | ||
public void shouldCalculateStringLengthWithoutSpaces(String input, int expected) { | ||
assertEquals(expected, manipulator.getStringLengthWithoutSpaces(input)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...advanced-tests/src/test/java/com/kodilla/parametrized_tests/StringValidatorTestSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.kodilla.parametrized_tests; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class StringValidatorTestSuite { | ||
|
||
private StringValidator validator = new StringValidator(); | ||
|
||
@Test | ||
public void shouldReturnFalseIfStringIsNotEmpty() { | ||
assertFalse(validator.isBlank("test")); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTrueIfStringIsEmpty() { | ||
assertTrue(validator.isBlank("")); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTrueIfStringHasOnlySpaces() { | ||
assertTrue(validator.isBlank(" ")); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTrueIfStringIsNull() { | ||
assertTrue(validator.isBlank(null)); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = {" ", " "}) | ||
public void shouldReturnTrueIfStringIsEmpty(String text) { | ||
assertTrue(validator.isBlank(text)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...d-tests/src/test/java/com/kodilla/parametrized_tests/homework/UserValidatorTestSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.kodilla.parametrized_tests.homework; | ||
|
||
import com.kodilla.parametrized_tests.StringValidator; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class UserValidatorTestSuite { | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
/* wielkie litery */ "USERNAME", | ||
/* małe litery */ "username", | ||
/* mieszane litery */ "UsErNAme", | ||
/* litery i cyfry */ "Username123", | ||
/* same cyfry */ "123456789", | ||
/* litery, cyfry i dozwolone znaki specjalne */ "23u_s-E.Rname1", | ||
/* same dozwolone znaki specjalne */ "___...---", | ||
/* minimalna długość */ "abc", | ||
/* wysoka długość */ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
}) | ||
public void validateUsernameShouldReturnTrue(String username) { | ||
assertTrue(UserValidator.validateUsername(username)); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { | ||
/* poniżej minimalnej długości */ "Ab", | ||
/* poniżej minimalnej długości */ "a", | ||
/* same niedozwolone znaki specjalne */ "*&^%$", | ||
/* litery i niedozwolone znaki specjalne */ "u%s$e#r!", | ||
/* spacja w środku */ "username 123", | ||
/* same spacje */ " ", | ||
/* enter w środku */ "username\n123", | ||
/* same entery */ "\n\n\n\n" | ||
}) | ||
public void validateUsernameShouldReturnFalse(String username) { | ||
assertFalse(UserValidator.validateUsername(username)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
/* klasyk */ "[email protected]", | ||
/* krótkie części */ "[email protected]", | ||
/* dozwolone znaki specjalne */ "[email protected]", | ||
/* wielkie litery */ "[email protected]", | ||
/* długie części */ "[email protected]", | ||
}) | ||
public void validateEmailShouldReturnTrue(String email) { | ||
assertTrue(UserValidator.validateEmail(email)); | ||
} | ||
|
||
@ParameterizedTest | ||
@NullAndEmptySource | ||
@ValueSource(strings = { | ||
/* bez domeny */ "user", | ||
/* bez domeny niższego poziomu */ "user.com", | ||
/* bez domeny wyższego poziomu */ "user@mail", | ||
/* sama domena */ "@mail.com", | ||
/* niedozwolone znaki specjalne */ "u$er@ma!l.com", | ||
/* kilka "małp" */ "user@[email protected]", | ||
/* znaki specjalne w domenie wyższego poziomu */ "[email protected]_m", | ||
/* same znaki specjalne */ "!#$%@^&*(.)^!", | ||
/* spacje w środku części */ "us [email protected]", "user@ma il.com", "[email protected] m", | ||
/* spacje między częściami */ "user@ mail.com", "user@mail .com" | ||
}) | ||
public void validateEmailShouldReturnFalse(String email) { | ||
assertFalse(UserValidator.validateEmail(email)); | ||
} | ||
} |