mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
Tests: added test to check copy() methods removes;
This commit is contained in:
parent
1c2f5d7940
commit
b8782d572d
2 changed files with 34 additions and 1 deletions
|
|
@ -14,6 +14,7 @@ import mage.constants.SuperType;
|
||||||
import mage.game.draft.RateCard;
|
import mage.game.draft.RateCard;
|
||||||
import mage.game.permanent.token.Token;
|
import mage.game.permanent.token.Token;
|
||||||
import mage.game.permanent.token.TokenImpl;
|
import mage.game.permanent.token.TokenImpl;
|
||||||
|
import mage.watchers.Watcher;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -24,6 +25,7 @@ import org.reflections.Reflections;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
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
|
@Test
|
||||||
@Ignore // TODO: enable test after massive token fixes
|
@Ignore // TODO: enable test after massive token fixes
|
||||||
public void checkMissingTokenData() {
|
public void checkMissingTokenData() {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
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 {
|
public abstract class Watcher implements Serializable {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(Watcher.class);
|
||||||
|
|
||||||
protected UUID controllerId;
|
protected UUID controllerId;
|
||||||
protected UUID sourceId;
|
protected UUID sourceId;
|
||||||
protected boolean condition;
|
protected boolean condition;
|
||||||
|
|
@ -84,7 +87,7 @@ public abstract class Watcher implements Serializable {
|
||||||
constructor.setAccessible(true);
|
constructor.setAccessible(true);
|
||||||
return (T) constructor.newInstance(this);
|
return (T) constructor.newInstance(this);
|
||||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
logger.error("Can't copy watcher: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue