1 package org.codehaus.modello.verifier;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.io.Reader;
28 import java.lang.reflect.Method;
29
30 import org.codehaus.plexus.util.xml.XmlStreamReader;
31
32 import static org.junit.jupiter.api.Assertions.assertEquals;
33 import static org.junit.jupiter.api.Assertions.assertTrue;
34 import static org.junit.jupiter.api.Assertions.fail;
35
36 public abstract class Verifier {
37 public abstract void verify() throws Throwable;
38
39 protected File getTestFile(String name) {
40 String basedir = System.getProperty("basedir", new File("").getAbsolutePath());
41
42 return new File(basedir, name);
43 }
44
45 protected String getTestPath(String name) {
46 String basedir = System.getProperty("basedir", new File("").getAbsolutePath());
47
48 return new File(basedir, name).getAbsolutePath();
49 }
50
51 protected Reader getXmlResourceReader(String name) throws IOException {
52 return new XmlStreamReader(getClass().getResourceAsStream(name));
53 }
54
55 protected void assertReader(Class<?> reader, Class<?> model, Class<?> input, Class<?> exception) {
56 Method read;
57
58
59 try {
60 read = reader.getMethod("read", input);
61
62 assertEquals(model, read.getReturnType(), "Bad return type of " + read);
63
64 for (Class<?> e : read.getExceptionTypes()) {
65 assertTrue(
66 IOException.class.equals(e) || exception.equals(e),
67 "Unexpected exception " + e.getName() + " at " + read);
68 }
69 } catch (NoSuchMethodException e) {
70 fail(e.toString());
71 }
72
73
74 try {
75 read = reader.getMethod("read", input, Boolean.TYPE);
76
77 assertEquals(model, read.getReturnType(), "Bad return type of " + read);
78
79 for (Class<?> e : read.getExceptionTypes()) {
80 assertTrue(
81 IOException.class.equals(e) || exception.equals(e),
82 "Unexpected exception " + e.getName() + " at " + read);
83 }
84 } catch (NoSuchMethodException e) {
85 fail(e.toString());
86 }
87 }
88
89 protected void assertWriter(Class<?> writer, Class<?> model, Class<?> output, Class<?> exception) {
90 Method write;
91
92
93 try {
94 write = writer.getMethod("write", output, model);
95
96 for (Class<?> e : write.getExceptionTypes()) {
97 assertTrue(
98 IOException.class.equals(e) || exception.equals(e),
99 "Unexpected exception " + e.getName() + " at " + write);
100 }
101 } catch (NoSuchMethodException e) {
102 fail(e.toString());
103 }
104 }
105 }