Skip to content

Commit

Permalink
test: Generic contracts are run only on **.testclasses.** (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus authored and pvojtechovsky committed Oct 30, 2018
1 parent 958224e commit c16bbf3
Show file tree
Hide file tree
Showing 9 changed files with 661 additions and 496 deletions.
599 changes: 599 additions & 0 deletions src/main/java/spoon/ContractVerifier.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void addMethod(CtMethod ctMethod) {
field.setSimpleName(ctMethod.getSimpleName());
field.setModifiers(ctMethod.getModifiers());
field.setType(ctMethod.getType());
field.setShadow(true);
ctAnnotationType.addMethod(field);
}
});
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/spoon/testing/utils/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ private Check() {
throw new AssertionError();
}

public static <T> T assertNotNull(T reference) {
/** throws AssertionError if "reference" is null */
public static <T> T assertNotNull(String msg, T reference) {
if (reference == null) {
throw new AssertionError("Your parameter can't be null.");
throw new AssertionError(msg);
}
return reference;
}

public static <T> T assertNotNull(T reference) {
return assertNotNull("Your parameter can't be null.", reference);
}

public static <T extends File> T assertExists(T file) {
if (!file.exists()) {
throw new AssertionError("You should specify an existing file.");
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/spoon/test/executable/ExecutableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package spoon.test.executable;

import org.junit.Test;
import spoon.ContractVerifier;
import spoon.Launcher;
import spoon.reflect.CtModel;
import spoon.reflect.code.CtBlock;
Expand Down Expand Up @@ -124,6 +125,6 @@ public void testShadowValueOf() {

assertEquals(valueOf, shadowValueOf);
assertEquals(valueOf.getDeclaration(), shadowValueOf.getDeclaration());
MainTest.checkShadow(shadowValueOf.getParent(CtPackage.class));
new ContractVerifier(shadowValueOf.getParent(CtPackage.class)).checkShadow();
}
}
7 changes: 4 additions & 3 deletions src/test/java/spoon/test/generics/GenericsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package spoon.test.generics;

import org.junit.Test;
import spoon.ContractVerifier;
import spoon.Launcher;
import spoon.SpoonModelBuilder;
import spoon.compiler.SpoonResourceHelper;
Expand Down Expand Up @@ -1435,9 +1436,9 @@ public void testIsGenericTypeEqual() {
*/
assertEquals(adaptedMethod.getParameters().get(0).getType(), classGetter.getType());
assertEquals(adaptedMethod.getParameters().get(0).getType(), classSetter.getParameters().get(0).getType());
MainTest.checkParentConsistency(launcher.getFactory().getModel().getRootPackage());
MainTest.checkParentConsistency(adaptedMethod);

new ContractVerifier(launcher.getFactory().getModel().getRootPackage()).checkParentConsistency();
new ContractVerifier().checkParentConsistency(adaptedMethod);
}

@Test
Expand Down
Loading

0 comments on commit c16bbf3

Please sign in to comment.