1 15 package org.apache.hivemind.impl; 16 17 import java.io.IOException ; 18 import java.util.NoSuchElementException ; 19 20 import org.apache.hivemind.service.MethodIterator; 21 import org.apache.hivemind.service.MethodSignature; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 24 30 public class TestMethodIterator extends HiveMindTestCase 31 { 32 static interface Play extends Runnable 33 { 34 public void jump(); 35 } 36 37 static interface Runnable2 38 { 39 public void run(); 40 } 41 42 static interface Runnable3 extends Runnable , Runnable2 43 { 44 } 45 46 static interface ToString 47 { 48 public String toString(); 49 } 50 51 52 static interface Openable 53 { 54 public void open(); 55 } 56 57 58 static interface OpenableWithError 59 { 60 public void open() throws IOException ; 61 } 62 63 64 static interface CombinedOpeneable extends Openable, OpenableWithError 65 { 66 } 67 68 public void testNormal() 69 { 70 MethodIterator mi = new MethodIterator(Runnable .class); 71 72 assertTrue(mi.hasNext()); 73 74 MethodSignature actual = mi.next(); 75 76 assertEquals(new MethodSignature(void.class, "run", null, null), actual); 77 78 assertFalse(mi.hasNext()); 79 80 try 81 { 82 mi.next(); 83 } 84 catch (NoSuchElementException ex) 85 { 86 } 88 89 assertEquals(false, mi.getToString()); 90 } 91 92 public void testInherited() 93 { 94 MethodIterator mi = new MethodIterator(Play.class); 95 96 assertTrue(mi.hasNext()); 97 98 101 MethodSignature actual = mi.next(); 102 103 assertEquals(new MethodSignature(void.class, "jump", null, null), actual); 104 105 assertTrue(mi.hasNext()); 106 107 actual = mi.next(); 108 109 assertEquals(new MethodSignature(void.class, "run", null, null), actual); 110 111 assertFalse(mi.hasNext()); 112 113 assertEquals(false, mi.getToString()); 114 } 115 116 public void testFiltersFuplication() 117 { 118 MethodIterator mi = new MethodIterator(Runnable3.class); 119 120 MethodSignature actual = mi.next(); 121 122 assertEquals(new MethodSignature(void.class, "run", null, null), actual); 123 124 assertEquals(false, mi.getToString()); 125 } 126 127 public void testToString() 128 { 129 MethodIterator mi = new MethodIterator(ToString.class); 130 131 MethodSignature actual = mi.next(); 132 133 assertEquals(new MethodSignature(String .class, "toString", null, null), actual); 134 135 assertEquals(true, mi.getToString()); 136 } 137 138 139 public void testFilterInheritedMethods() 140 { 141 MethodIterator mi = new MethodIterator(CombinedOpeneable.class); 142 143 MethodSignature actual = mi.next(); 144 145 assertEquals(new MethodSignature(void.class, "open", null, new Class [] 146 { IOException .class }), actual); 147 148 assertEquals(false, mi.hasNext()); 149 } 150 } | Popular Tags |