Table of Contents ⇒ Java Unit Test Library-Artery-Sample
Q02_02.java
package jp.avaj.lib.test;
import jp.avaj.lib.algo.ArValidator;
/**
*Java unit test library-Artery-Validating an object with ArValidator
*
*ArValidator can be used to validate an object.
*ArValidator can define various things, so it can extend the function of the test library..
*/
public class Q02_02 {
public static void main(String[] args) {
//Declare the start of the test case ⇒ Not required if aggregation is not required
ArTest.startTestCase("Q02_02");
//Definition of ArValidator
ArValidator<String> validator = new ArValidator<String>() {
@Override
public boolean check(String value) {
return value.startsWith("a") && value.endsWith("z");
}
//It is convenient to define toString because it will be output to the log..
@Override
public String toString() {
return "For tentative test";
}
};
L.p("Validation");
{
String str = "abcz";
ArTest.isValid("abcz","validater",validator,"str",str);
str = "abc";
ArTest.isValid("abc ⇒ NG","validater",validator,"str",str);
}
L.p("Non-validation");
//Use isNotValid when you want to determine that it is not valid ⇒ is not invalid
{
String str = "abcz";
ArTest.isNotValid("abcz ⇒ NG","validater",validator,"str",str);
str = "abc";
ArTest.isNotValid("abc","validater",validator,"str",str);
}
//End the test case ⇒ Not required if aggregation is not required
ArTest.endTestCase();
}
}
result.txt
**** Q02_02 start ****
Validation
OK abcz:validater=For tentative test:str=abcz
NG abc ⇒ NG:validater=For tentative test:str=abc
jp.avaj.lib.test.Q02_02.main(Q02_02.java:35)
Non-validation
NG abcz ⇒ NG:validater=For tentative test:str=abcz
jp.avaj.lib.test.Q02_02.main(Q02_02.java:42)
OK abc:validater=For tentative test:str=abc
**** Q02_02 summary ****
test count = 4
success = 2
Recommended Posts