View Javadoc
1   package org.codehaus.plexus.util.reflection;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.TestCase;
20  
21  /**
22   * @author Jörg Schaible
23   * @version $Id$
24   */
25  public class ReflectorTest
26      extends TestCase
27  {
28      private Project project;
29  
30      private Reflector reflector;
31  
32      protected void setUp()
33          throws Exception
34      {
35          super.setUp();
36  
37          project = new Project();
38          project.setModelVersion( "1.0.0" );
39          project.setVersion( "42" );
40  
41          reflector = new Reflector();
42      }
43  
44      public void testObjectPropertyFromName()
45          throws Exception
46      {
47          assertEquals( "1.0.0", reflector.getObjectProperty( project, "modelVersion" ) );
48      }
49  
50      public void testObjectPropertyFromBean()
51          throws Exception
52      {
53          assertEquals( "Foo", reflector.getObjectProperty( project, "name" ) );
54      }
55  
56      public void testObjectPropertyFromField()
57          throws Exception
58      {
59          assertEquals( "42", reflector.getObjectProperty( project, "version" ) );
60      }
61  
62      public static class Project
63      {
64          private String model;
65  
66          private String name;
67  
68          private String version;
69  
70          public void setModelVersion( String modelVersion )
71          {
72              this.model = modelVersion;
73          }
74  
75          public void setVersion( String version )
76          {
77              this.version = version;
78          }
79  
80          public String modelVersion()
81          {
82              return model;
83          }
84  
85          public String getName()
86          {
87              return "Foo";
88          }
89      }
90  }