Refactor of the Project on Github.
-Added: Better System to decide what code should be generated. -Added: Unit Tests are now included in the main branch. -Added: Automatic System to test the main branch and ensure that tests work. -Added: Pull Requests now run tests too.
This commit is contained in:
+93
@@ -0,0 +1,93 @@
|
||||
package speiger.src.testers.base.tests.collection;
|
||||
|
||||
import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION;
|
||||
import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE;
|
||||
import static com.google.common.collect.testing.features.CollectionSize.SEVERAL;
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.AbstractCollectionTester;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings({"unchecked", "javadoc" })
|
||||
public class JavaCollectionRemoveIfTester<E> extends AbstractCollectionTester<E>
|
||||
{
|
||||
@CollectionFeature.Require(SUPPORTS_REMOVE)
|
||||
public void testRemoveIf_alwaysFalse()
|
||||
{
|
||||
assertFalse("removeIf(x -> false) should return false", collection.removeIf(x -> false));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
@CollectionFeature.Require(SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
public void testRemoveIf_sometimesTrue()
|
||||
{
|
||||
assertTrue("removeIf(isEqual(present)) should return true", collection.removeIf(Predicate.isEqual(samples.e0())));
|
||||
expectMissing(samples.e0());
|
||||
}
|
||||
|
||||
@CollectionFeature.Require(SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
public void testRemoveIf_allPresent()
|
||||
{
|
||||
assertTrue("removeIf(x -> true) should return true", collection.removeIf(x -> true));
|
||||
expectContents();
|
||||
}
|
||||
|
||||
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION })
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
public void testRemoveIfSomeMatchesConcurrentWithIteration()
|
||||
{
|
||||
try
|
||||
{
|
||||
Iterator<E> iterator = collection.iterator();
|
||||
assertTrue(collection.removeIf(Predicate.isEqual(samples.e0())));
|
||||
iterator.next();
|
||||
fail("Expected ConcurrentModificationException");
|
||||
}
|
||||
catch(ConcurrentModificationException expected)
|
||||
{
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(ZERO)
|
||||
public void testRemoveIf_unsupportedEmptyCollection()
|
||||
{
|
||||
try
|
||||
{
|
||||
assertFalse("removeIf(Predicate) should return false or throw " + "UnsupportedOperationException", collection.removeIf(x -> {
|
||||
throw new AssertionError("predicate should never be called");
|
||||
}));
|
||||
}
|
||||
catch(UnsupportedOperationException tolerated)
|
||||
{
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
public void testRemoveIf_alwaysTrueUnsupported()
|
||||
{
|
||||
try
|
||||
{
|
||||
collection.removeIf(x -> true);
|
||||
fail("removeIf(x -> true) should throw " + "UnsupportedOperationException");
|
||||
}
|
||||
catch(UnsupportedOperationException expected)
|
||||
{
|
||||
}
|
||||
expectUnchanged();
|
||||
assertTrue(collection.contains(samples.e0()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package speiger.src.testers.base.tests.list;
|
||||
|
||||
import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE;
|
||||
import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE;
|
||||
import static java.util.Collections.singleton;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.Helpers;
|
||||
import com.google.common.collect.testing.IteratorFeature;
|
||||
import com.google.common.collect.testing.ListIteratorTester;
|
||||
import com.google.common.collect.testing.testers.AbstractListTester;
|
||||
|
||||
import speiger.src.testers.utils.SpecialFeature;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
public class JavaListListIteratorTester<E> extends AbstractListTester<E>
|
||||
{
|
||||
@SpecialFeature.Require(absent = SpecialFeature.ITERATOR_MODIFIABLE)
|
||||
public void testListIterator_unmodifiable()
|
||||
{
|
||||
runListIteratorTest(UNMODIFIABLE);
|
||||
}
|
||||
|
||||
@SpecialFeature.Require(SpecialFeature.ITERATOR_MODIFIABLE)
|
||||
public void testListIterator_fullyModifiable()
|
||||
{
|
||||
runListIteratorTest(MODIFIABLE);
|
||||
}
|
||||
|
||||
private void runListIteratorTest(Set<IteratorFeature> features)
|
||||
{
|
||||
new ListIteratorTester<E>(4, singleton(e4()), features, Helpers.copyToList(getOrderedElements()), 0)
|
||||
{
|
||||
@Override
|
||||
protected ListIterator<E> newTargetIterator()
|
||||
{
|
||||
resetCollection();
|
||||
return getList().listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void verify(List<E> elements)
|
||||
{
|
||||
expectContents(elements);
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
public void testListIterator_tooLow()
|
||||
{
|
||||
try
|
||||
{
|
||||
getList().listIterator(-1);
|
||||
fail();
|
||||
}
|
||||
catch(IndexOutOfBoundsException expected)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testListIterator_tooHigh()
|
||||
{
|
||||
try
|
||||
{
|
||||
getList().listIterator(getNumElements() + 1);
|
||||
fail();
|
||||
}
|
||||
catch(IndexOutOfBoundsException expected)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testListIterator_atSize()
|
||||
{
|
||||
getList().listIterator(getNumElements());
|
||||
// TODO: run the iterator through ListIteratorTester
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package speiger.src.testers.utils;
|
||||
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.testing.Helpers;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
import com.google.common.collect.testing.features.TesterAnnotation;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "javadoc"})
|
||||
public enum SpecialFeature implements Feature<Collection> {
|
||||
COPYING,
|
||||
CHILDREN_COPY(COPYING),
|
||||
MODIFIABLE,
|
||||
ITERATOR_MODIFIABLE,
|
||||
MAP_ENTRY,
|
||||
DESCENDING,
|
||||
SUBMAP;
|
||||
|
||||
private final Set<Feature<? super Collection>> implied;
|
||||
|
||||
SpecialFeature(Feature<? super Collection>... implied) {
|
||||
this.implied = Helpers.copyToSet(implied);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Feature<? super Collection>> getImpliedFeatures() {
|
||||
return implied;
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@TesterAnnotation
|
||||
public @interface Require {
|
||||
SpecialFeature[] value() default {};
|
||||
|
||||
SpecialFeature[] absent() default {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package speiger.src.testers.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class TestUtils
|
||||
{
|
||||
public static void getSurpession(Collection<Method> methods, Class<?> clz, String...args) {
|
||||
Set<String> set = new HashSet<>(Arrays.asList(args));
|
||||
try {
|
||||
for(Method method : clz.getMethods()) {
|
||||
if(set.contains(method.getName())) methods.add(method);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void getSurpession(Collection<Method> methods, Class<?> clz) {
|
||||
try {
|
||||
for(Method method : clz.getMethods()) {
|
||||
methods.add(method);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Method[] getSurpession(Class<?> clz) {
|
||||
try {
|
||||
return clz.getMethods();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new Method[0];
|
||||
}
|
||||
|
||||
public static Method[] getSurpession(Class<?> clz, String...args) {
|
||||
List<Method> methods = new ArrayList<>();
|
||||
Set<String> set = new HashSet<>(Arrays.asList(args));
|
||||
try {
|
||||
for(Method method : clz.getMethods()) {
|
||||
if(set.contains(method.getName())) methods.add(method);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return methods.toArray(new Method[methods.size()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user