1 package org.codehaus.plexus.util.reflection;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23
24
25
26
27
28
29
30
31 public class ReflectorTest {
32 private Project project;
33
34 private Reflector reflector;
35
36
37
38
39
40
41 @BeforeEach
42 public void setUp() throws Exception {
43 project = new Project();
44 project.setModelVersion("1.0.0");
45 project.setVersion("42");
46
47 reflector = new Reflector();
48 }
49
50
51
52
53
54
55 @Test
56 public void testObjectPropertyFromName() throws Exception {
57 assertEquals("1.0.0", reflector.getObjectProperty(project, "modelVersion"));
58 }
59
60
61
62
63
64
65 @org.junit.jupiter.api.Test
66 public void testObjectPropertyFromBean() throws Exception {
67 assertEquals("Foo", reflector.getObjectProperty(project, "name"));
68 }
69
70
71
72
73
74
75 @Test
76 public void testObjectPropertyFromField() throws Exception {
77 assertEquals("42", reflector.getObjectProperty(project, "version"));
78 }
79
80 public static class Project {
81 private String model;
82
83 private String name;
84
85 private String version;
86
87 public void setModelVersion(String modelVersion) {
88 this.model = modelVersion;
89 }
90
91 public void setVersion(String version) {
92 this.version = version;
93 }
94
95 public String modelVersion() {
96 return model;
97 }
98
99 public String getName() {
100 return "Foo";
101 }
102 }
103 }