cicaprojekt/cicaprojekt/Tester.java

55 lines
1.6 KiB
Java

package cicaprojekt;
import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Tester {
private Player oneill;
private Player jaffa;
private PlayerBase replicator;
Dungeon loadMap(String param) throws IOException{
Dungeon dungeon = new Dungeon();
dungeon.buildDungeon(new File(param));
return dungeon;
}
void listPlayers() {
System.out.println(oneill);
System.out.println(jaffa);
System.out.println(replicator);
}
/* custom Test annotation */
@Target(ElementType.METHOD) // it's for methods
@Retention(RetentionPolicy.RUNTIME) // we want to retain annotations in runtime
private @interface Test {}
/* run all methods annotated with @Test */
public boolean runAllTests() throws InvocationTargetException, IllegalAccessException
{
boolean testspassed = true;
for (Method m : this.getClass().getMethods()) // iterate over all methods of this
{
if (m.isAnnotationPresent(Test.class)) // if its annotated with @Test...
{
Boolean testresult = (Boolean) m.invoke(null); // call it!
if (!testresult)
{
testspassed = false;
}
}
}
return testspassed;
}
}