forked from liangrui1988/java-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodTest.java
More file actions
77 lines (56 loc) · 2.15 KB
/
Copy pathMethodTest.java
File metadata and controls
77 lines (56 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.rui.pro1.vail;
import java.lang.reflect.Method;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import javax.validation.executable.ExecutableValidator;
import org.junit.BeforeClass;
import org.junit.Test;
import com.rui.pro1.vail.v.Car;
public class MethodTest {
static ExecutableValidator executableValidator;
@BeforeClass
public static void setUp() {
// Obtaining an ExecutableValidator instance
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
executableValidator = factory.getValidator().forExecutables();
}
@Test
public void methodT() throws NoSuchMethodException, SecurityException,
InstantiationException, IllegalAccessException {
// Car object = new Car("Morris");
Class clz = Car.class;
Object object = clz.newInstance();
Method method = Car.class.getMethod("drive", int.class, String.class,
String.class, String.class, BeanVail.class);
// Object[] parameterValues = { 1,null};
BeanVail b = new BeanVail();
b.setAge(10000);
Object[] parameterValues = { 1, "a", "", "", b };
// Object[] parameterValues = { 100,"abcdef"};
Set<ConstraintViolation<Object>> violations = executableValidator
.validateParameters(object, method, parameterValues);
System.out.println(violations);
for (ConstraintViolation cv : violations) {
System.out.println(cv.getMessage());
}
}
@Test
public void pp() throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException {
Class clzcar = Car.class;
Object objectcar = clzcar.newInstance();
Method methodx = Car.class.getMethod("drive", int.class, String.class,
String.class, String.class, BeanVail.class);
BeanVail b = new BeanVail();
b.setAge(10000);
Object[] parameterValuestest = { 1, "a", "", "", b };
// Object[] parameterValues = { 100,"abcdef"};
Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(objectcar, methodx,
parameterValuestest);
System.out.println(violations);
for (ConstraintViolation cv : violations) {
System.out.println(cv.getMessage());
}
}
}