added static filter test, a few other small changes

This commit is contained in:
Evan Kranzler 2021-11-17 08:31:50 -05:00
parent afdae939c3
commit dcb08be4c3
4 changed files with 42 additions and 3 deletions

View file

@ -1,10 +1,10 @@
package mage.filter;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import java.io.Serializable;
import java.util.List;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/**
* @param <E>
@ -29,5 +29,9 @@ public interface Filter<E> extends Serializable {
Filter<E> copy();
public boolean isLockedFilter();
public void setLockedFilter(boolean lockedFilter);
List<Predicate<? super E>> getPredicates();
}

View file

@ -67,10 +67,12 @@ public abstract class FilterImpl<E> implements Filter<E> {
return message;
}
@Override
public boolean isLockedFilter() {
return lockedFilter;
}
@Override
public void setLockedFilter(boolean lockedFilter) {
this.lockedFilter = lockedFilter;
}

View file

@ -752,6 +752,10 @@ public final class StaticFilters {
public static final FilterPermanent FILTER_PERMANENT_EQUIPMENT = new FilterEquipmentPermanent();
static {
FILTER_PERMANENT_EQUIPMENT.setLockedFilter(true);
}
public static final FilterPermanent FILTER_PERMANENT_FORTIFICATION = new FilterPermanent();
static {

View file

@ -0,0 +1,29 @@
package mage;
import mage.filter.Filter;
import mage.filter.StaticFilters;
import org.junit.Assert;
import org.junit.Test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/**
* @author TheElk801
*/
public class StaticFilterTest {
@Test
public void testStaticFilters() throws IllegalAccessException {
for (Field field : StaticFilters.class.getFields()) {
Assert.assertTrue("Field must be public: " + field, Modifier.isPublic(field.getModifiers()));
Assert.assertTrue("Field must be static: " + field, Modifier.isStatic(field.getModifiers()));
Assert.assertTrue("Field must be final: " + field, Modifier.isFinal(field.getModifiers()));
Assert.assertTrue("Field name must start with \"FILTER_\"", field.getName().startsWith("FILTER_"));
Assert.assertEquals("Field name must be all upper case letters", field.getName().toUpperCase(), field.getName());
Object filter = field.get(field.getType());
Assert.assertTrue("Field must be a filter: " + field, filter instanceof Filter);
Assert.assertTrue("Field must be locked: " + field, ((Filter) filter).isLockedFilter());
}
}
}