1 // Tags: JDK1.1 |
|
2 |
|
3 // Copyright (C) 2002 Free Software Foundation, Inc. |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.lang.reflect.Method; |
|
23 |
|
24 import gnu.testlet.Testlet; |
|
25 import gnu.testlet.TestHarness; |
|
26 import java.lang.reflect.Method; |
|
27 |
|
28 /** |
|
29 * Tests java.lang.reflect.Method.equals(). |
|
30 * |
|
31 * @author Mark Wielaard <mark@klomp.org> |
|
32 */ |
|
33 public class equals implements Testlet |
|
34 { |
|
35 void q() { } |
|
36 void r() { } |
|
37 |
|
38 public String toString() { return "funny equals class thing"; } |
|
39 |
|
40 public void m() { } |
|
41 public void m(String s) { } |
|
42 |
|
43 private Method getMethod(Class c, String n, Class[] ts) |
|
44 { |
|
45 try |
|
46 { |
|
47 return c.getDeclaredMethod(n, ts); |
|
48 } |
|
49 catch (NoSuchMethodException nsme) |
|
50 { |
|
51 throw new RuntimeException("Warning - no such method: " + c + ", " + n); |
|
52 } |
|
53 } |
|
54 |
|
55 public void test (TestHarness harness) |
|
56 { |
|
57 Method m1, m2; |
|
58 Class[] ts; |
|
59 |
|
60 ts = new Class[0]; |
|
61 m1 = getMethod(equals.class, "q", ts); |
|
62 m2 = getMethod(equals.class, "q", ts); |
|
63 harness.check(m1.equals(m2), "same method q"); |
|
64 |
|
65 m2 = getMethod(equals.class, "r", ts); |
|
66 harness.check(!m1.equals(m2), "different method names q and r"); |
|
67 |
|
68 m1 = getMethod(String.class, "toString", ts); |
|
69 m2 = getMethod(equals.class, "toString", ts); |
|
70 harness.check(!m1.equals(m2), "different declaring classes for toString"); |
|
71 |
|
72 m1 = getMethod(equals.class, "m", ts); |
|
73 ts = new Class[1]; |
|
74 ts[0] = String.class; |
|
75 m2 = getMethod(equals.class, "m", ts); |
|
76 harness.check(!m1.equals(m2), "different argument types m"); |
|
77 |
|
78 harness.check(!m1.equals(null), "nothing equals null"); |
|
79 } |
|
80 } |
|