Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
52   200   19   5.78
0   118   0.37   9
9     2.11  
1    
 
  YodaUtilityTest       Line # 25 52 19 86.9% 0.86885244
 
  (7)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.base.utility;
17   
18    import org.qedeq.base.test.QedeqTestCase;
19   
20    /**
21    * Test {@link YodaUtility}.
22    *
23    * @author Michael Meyling
24    */
 
25    public class YodaUtilityTest extends QedeqTestCase {
26   
27    /** Very secret number, which is read by yoda with the help of the force. */
28    private static final int secret = 967123;
29   
30    /** Very secret number, which is changed by yoda with the help of the force. */
31    private int changeMe = 815;
32   
33    /**
34    * Test {@link YodaUtility#getFieldValue(Object, String)}.
35    *
36    * @throws Exception Something bad happened.
37    */
 
38  1 toggle public void testGetFieldValue() throws Exception {
39  1 assertEquals(new Integer(secret), YodaUtility.getFieldValue(this, "secret"));
40  1 assertEquals(getOutdir(), YodaUtility.getFieldValue(this, "outdir"));
41  1 try {
42  1 YodaUtility.getFieldValue(this, "unknown");
43  0 fail("Exception expected");
44    } catch (NoSuchFieldException e) {
45    // ok
46    }
47    }
48   
49    /**
50    * Test {@link YodaUtility#getField(Object, String)}.
51    *
52    * @throws Exception Something bad happened.
53    */
 
54  1 toggle public void testGetField() throws Exception {
55  1 assertEquals(this.getClass().getDeclaredField("secret"),
56    YodaUtility.getField(this, "secret"));
57  1 assertEquals(QedeqTestCase.class.getDeclaredField("outdir"),
58    YodaUtility.getField(this, "outdir"));
59  1 try {
60  1 YodaUtility.getField(this, "unknown");
61  0 fail("Exception expected");
62    } catch (NoSuchFieldException e) {
63    // ok
64    }
65    }
66   
67    /**
68    * Test {@link YodaUtility#executeMethod(Object, String, Class[], Object[])}.
69    *
70    * @throws Exception Something bad happened.
71    */
 
72  1 toggle public void testExecuteMethod() throws Exception {
73  1 assertEquals(getOutdir(), YodaUtility.executeMethod(this, "getOutdir",
74    new Class[]{}, new Object[]{}));
75  1 try {
76  1 YodaUtility.executeMethod(this, "getoutdir",
77    new Class[]{}, new Object[]{});
78  0 fail("exception expected");
79    } catch (NoSuchMethodException e) {
80    // ok
81    }
82  1 final String time = "" + System.currentTimeMillis();
83  1 assertEquals(myTestMethod(time),
84    YodaUtility.executeMethod(this, "myTestMethod",
85    new Class[]{String.class}, new Object[]{ time}));
86  1 try {
87  1 YodaUtility.executeMethod(this, "myTestMethodi",
88    new Class[]{String.class}, new Object[]{ time});
89  0 fail("exception expected");
90    } catch (NoSuchMethodException e) {
91    // ok
92    }
93  1 try {
94  1 YodaUtility.executeMethod(this, "myTestMethod",
95    new Class[]{}, new Object[]{});
96  0 fail("exception expected");
97    } catch (NoSuchMethodException e) {
98    // ok
99    }
100    }
101   
 
102  2 toggle private String myTestMethod(final String my) {
103  2 return my + "done!";
104    }
105   
106    /**
107    * Test {@link YodaUtility#executeMethod(String, String, Class[], Object[]).
108    *
109    * @throws Exception Something bad happened.
110    */
 
111  1 toggle public void testExecuteMethod2() throws Exception {
112  1 try {
113  1 YodaUtility.executeMethod(this.getClass().getName(), "getOutdir",
114    new Class[]{}, new Object[]{});
115  0 fail("exception expected");
116    } catch (NoSuchMethodException e) {
117    // ok
118    }
119  1 try {
120  1 YodaUtility.executeMethod(this.getClass().getName(), "getoutdir",
121    new Class[]{}, new Object[]{});
122  0 fail("exception expected");
123    } catch (NoSuchMethodException e) {
124    // ok
125    }
126  1 final String time = "" + System.currentTimeMillis();
127  1 assertEquals(myStaticTestMethod(time),
128    YodaUtility.executeMethod(this.getClass().getName(), "myStaticTestMethod",
129    new Class[]{String.class}, new Object[]{ time}));
130  1 try {
131  1 YodaUtility.executeMethod(this.getClass().getName(), "myStaticTestMethodi",
132    new Class[]{String.class}, new Object[]{ time});
133    } catch (NoSuchMethodException e) {
134    // ok
135    }
136  1 try {
137  1 YodaUtility.executeMethod(this.getClass().getName(), "myStaticTestMethod",
138    new Class[]{}, new Object[]{});
139    } catch (NoSuchMethodException e) {
140    // ok
141    }
142    }
143   
 
144  2 toggle private static String myStaticTestMethod(final String my) {
145  2 return my + "done!";
146    }
147   
148    /**
149    * Test {@link YodaUtility#existsMethod(Class, String, Class[])}.
150    *
151    * @throws Exception Something bad happened.
152    */
 
153  1 toggle public void testExistsMethod() throws Exception {
154  1 assertTrue(YodaUtility.existsMethod(this.getClass(), "getOutdir",
155    new Class[]{}));
156  1 assertFalse(YodaUtility.existsMethod(this.getClass(), "getOutdir",
157    new Class[]{Integer.TYPE}));
158  1 assertFalse(YodaUtility.existsMethod(this.getClass(), "getTevqOutdir",
159    new Class[]{}));
160  1 assertTrue(YodaUtility.existsMethod(this.getClass(), "testExistsMethod",
161    new Class[]{}));
162    }
163   
164    /**
165    * Test {@link YodaUtility#getFieldValue(Object, String)}.
166    *
167    * @throws Exception Something bad happened.
168    */
 
169  1 toggle public void testSetFieldValue() throws Exception {
170  1 try {
171  1 YodaUtility.setFieldContent(this, "secret", new Integer(37846));
172    // System.out.println("secret=" + secret);
173  0 fail("Exception expected");
174    } catch (Exception e) {
175    // expected;
176    }
177  1 changeMe = 0;
178  1 YodaUtility.setFieldContent(this, "changeMe", new Integer(37846));
179  1 assertEquals(37846, changeMe);;
180    }
181   
182    /**
183    * Test {@link YodaUtility#existsMethod(String, String, Class[])}.
184    *
185    * @throws Exception Something bad happened.
186    */
 
187  1 toggle public void testExistsMethod2() throws Exception {
188  1 assertTrue(YodaUtility.existsMethod(this.getClass().getName(), "getOutdir",
189    new Class[]{}));
190  1 assertFalse(YodaUtility.existsMethod(this.getClass().getName(), "getOutdir",
191    new Class[]{Integer.TYPE}));
192  1 assertFalse(YodaUtility.existsMethod(this.getClass().getName(), "getTevqOutdir",
193    new Class[]{}));
194  1 assertTrue(YodaUtility.existsMethod(this.getClass().getName(), "testExistsMethod2",
195    new Class[]{}));
196  1 assertFalse(YodaUtility.existsMethod("this.is.a.non.existing.Class", "getOutdir",
197    new Class[]{}));
198    }
199   
200    }