Tests: added test to check copy() methods removes;

This commit is contained in:
Oleg Agafonov 2019-03-30 20:26:35 +04:00
parent 1c2f5d7940
commit b8782d572d
2 changed files with 34 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import mage.constants.SuperType;
import mage.game.draft.RateCard;
import mage.game.permanent.token.Token;
import mage.game.permanent.token.TokenImpl;
import mage.watchers.Watcher;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@ -24,6 +25,7 @@ import org.reflections.Reflections;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -405,6 +407,34 @@ public class VerifyCardDataTest {
}
}
@Test
@Ignore // TODO: enable it on copy() methods removing
public void checkWatcherCopyMethods() {
Collection<String> errorsList = new ArrayList<>();
Collection<String> warningsList = new ArrayList<>();
Reflections reflections = new Reflections("mage.");
Set<Class<? extends Watcher>> watcherClassesList = reflections.getSubTypesOf(Watcher.class);
for (Class<? extends Watcher> watcherClass : watcherClassesList) {
try {
Method m = watcherClass.getMethod("copy");
if (!m.getGenericReturnType().getTypeName().equals("T")) {
errorsList.add("error, copy() method must be deleted from watcher class: " + watcherClass.getName());
}
} catch (NoSuchMethodException e) {
errorsList.add("error, can't find copy() method in watcher class: " + watcherClass.getName());
}
}
printMessages(warningsList);
printMessages(errorsList);
if (errorsList.size() > 0) {
Assert.fail("Found watcher errors: " + errorsList.size());
}
}
@Test
@Ignore // TODO: enable test after massive token fixes
public void checkMissingTokenData() {

View file

@ -8,6 +8,7 @@ import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import org.apache.log4j.Logger;
/**
*
@ -17,6 +18,8 @@ import mage.game.events.GameEvent;
*/
public abstract class Watcher implements Serializable {
private static final Logger logger = Logger.getLogger(Watcher.class);
protected UUID controllerId;
protected UUID sourceId;
protected boolean condition;
@ -84,7 +87,7 @@ public abstract class Watcher implements Serializable {
constructor.setAccessible(true);
return (T) constructor.newInstance(this);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
logger.error("Can't copy watcher: " + e.getMessage(), e);
}
return null;
}