Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify syntax of asserts in tests (Assert.assert* -> assert*) #2604

Merged
merged 13 commits into from
Oct 2, 2018
19 changes: 10 additions & 9 deletions src/test/java/spoon/LauncherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

Expand All @@ -28,14 +29,14 @@ public void testInitEnvironmentDefault() throws Exception {

final Environment environment = launcher.getEnvironment();
// specify the default values
Assert.assertFalse(environment.isAutoImports());
Assert.assertFalse(environment.isUsingTabulations());
Assert.assertFalse(environment.isPreserveLineNumbers());
assertFalse(environment.isAutoImports());
assertFalse(environment.isUsingTabulations());
assertFalse(environment.isPreserveLineNumbers());
assertEquals(4, environment.getTabulationSize());
Assert.assertTrue(environment.isCopyResources());
assertTrue(environment.isCopyResources());

JavaOutputProcessor processor = (JavaOutputProcessor) environment.getDefaultFileGenerator();
Assert.assertTrue(processor.getPrinter() instanceof DefaultJavaPrettyPrinter);
assertTrue(processor.getPrinter() instanceof DefaultJavaPrettyPrinter);

// now assertions on the model builder
final SpoonModelBuilder builder = launcher.getModelBuilder();
Expand All @@ -55,12 +56,12 @@ public void testInitEnvironment() throws Exception {
final Environment environment = launcher.getEnvironment();

// Verify if the environment is correct.
Assert.assertTrue(environment.isAutoImports());
Assert.assertTrue(environment.isUsingTabulations());
Assert.assertTrue(environment.isPreserveLineNumbers());
assertTrue(environment.isAutoImports());
assertTrue(environment.isUsingTabulations());
assertTrue(environment.isPreserveLineNumbers());
assertEquals(42, environment.getTabulationSize());
assertEquals(5, environment.getComplianceLevel());
Assert.assertFalse(environment.isCopyResources());
assertFalse(environment.isCopyResources());

final SpoonModelBuilder builder = launcher.getModelBuilder();
assertEquals(new File("spooned2").getCanonicalFile(), builder.getSourceOutputDirectory());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/api/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void init() {
"-i", "src/test/resources/spoon/test/api/",
"-o", "fancy/fake/apitest" // we shouldn't write anything anyway
});
Assert.assertEquals(3, l.size());
assertEquals(3, l.size());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/compilation/CompilationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void compileTest() throws Exception {

Class<?> aClass = urlClassLoader.loadClass("Simple");
Method m = aClass.getMethod("m");
Assert.assertEquals(42, m.invoke(aClass.newInstance()));
assertEquals(42, m.invoke(aClass.newInstance()));
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/spoon/test/constructor/ConstructorTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package spoon.test.constructor;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import spoon.Launcher;
Expand All @@ -25,6 +24,7 @@
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.testing.utils.ModelUtils.canBeBuilt;
Expand All @@ -48,8 +48,8 @@ public void setUp() {
public void testImplicitConstructor() throws Exception {
CtClass<?> ctType = (CtClass) ModelUtils.buildClass(ImplicitConstructor.class);

Assert.assertTrue(ctType.getConstructor().isImplicit());
Assert.assertFalse(aClass.getConstructor().isImplicit());
assertTrue(ctType.getConstructor().isImplicit());
assertFalse(aClass.getConstructor().isImplicit());
}

@Test
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/spoon/test/executable/ExecutableRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static spoon.testing.utils.ModelUtils.build;
import static spoon.testing.utils.ModelUtils.canBeBuilt;

Expand All @@ -36,13 +37,13 @@ public class ExecutableRefTest {
@Test
public void methodTest() throws Exception {
CtAbstractInvocation<?> ctAbstractInvocation = this.getInvocationFromMethod("testMethod");
Assert.assertTrue(ctAbstractInvocation instanceof CtInvocation<?>);
assertTrue(ctAbstractInvocation instanceof CtInvocation<?>);

CtExecutableReference<?> executableReference = ctAbstractInvocation.getExecutable();
Assert.assertNotNull(executableReference);
assertNotNull(executableReference);

Method method = executableReference.getActualMethod();
Assert.assertNotNull(method);
assertNotNull(method);

assertEquals("Hello World",
method.invoke(null, ((CtLiteral<?>) ctAbstractInvocation.getArguments().get(0)).getValue()));
Expand All @@ -51,13 +52,13 @@ public void methodTest() throws Exception {
@Test
public void constructorTest() throws Exception {
CtAbstractInvocation<?> ctAbstractInvocation = this.getInvocationFromMethod("testConstructor");
Assert.assertTrue(ctAbstractInvocation instanceof CtConstructorCall<?>);
assertTrue(ctAbstractInvocation instanceof CtConstructorCall<?>);

CtExecutableReference<?> executableReference = ctAbstractInvocation.getExecutable();
Assert.assertNotNull(executableReference);
assertNotNull(executableReference);

Constructor<?> constructor = executableReference.getActualConstructor();
Assert.assertNotNull(constructor);
assertNotNull(constructor);

assertEquals("Hello World",
constructor.newInstance(((CtLiteral<?>) ctAbstractInvocation.getArguments().get(0)).getValue()));
Expand Down Expand Up @@ -97,20 +98,20 @@ private CtAbstractInvocation<?> getInvocationFromMethod(String methodName) throw
Factory factory = build(ExecutableRefTestSource.class, MyIntf.class);

CtClass<ExecutableRefTestSource> clazz = factory.Class().get(ExecutableRefTestSource.class);
Assert.assertNotNull(clazz);
assertNotNull(clazz);

List<CtMethod<?>> methods = clazz.getMethodsByName(methodName);
assertEquals(1, methods.size());

CtMethod<?> ctMethod = methods.get(0);
CtBlock<?> ctBody = ctMethod.getBody();
Assert.assertNotNull(ctBody);
assertNotNull(ctBody);

List<CtStatement> ctStatements = ctBody.getStatements();
assertEquals(1, ctStatements.size());

CtStatement ctStatement = ctStatements.get(0);
Assert.assertTrue(ctStatement instanceof CtAbstractInvocation<?>);
assertTrue(ctStatement instanceof CtAbstractInvocation<?>);

return (CtAbstractInvocation<?>) ctStatement;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/intercession/IntercessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testInsertEnd() {
.compile();
CtMethod<?> foo = (CtMethod<?>) clazz.getMethods().toArray()[0];
CtMethod<?> fooClone = foo.clone();
Assert.assertEquals(foo, fooClone);
assertEquals(foo, fooClone);
CtBlock<?> body = foo.getBody();
assertEquals(2, body.getStatements().size());

Expand All @@ -95,7 +95,7 @@ public void testEqualConstructor() {
.compile();
CtConstructor<?> foo = (CtConstructor<?>) clazz.getConstructors().toArray()[0];
CtConstructor<?> fooClone = foo.clone();
Assert.assertEquals(foo, fooClone);
assertEquals(foo, fooClone);

CtBlock<?> body = foo.getBody();

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/spoon/test/main/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ public void biScan(CtElement element, CtElement other) {
counterBiScan.scan++;
if (element == null) {
if (other != null) {
Assert.fail("element can't be null if other isn't null.");
fail("element can't be null if other isn't null.");
}
} else if (other == null) {
Assert.fail("other can't be null if element isn't null.");
fail("other can't be null if element isn't null.");
} else {
// contract: all elements have been cloned and are still equal
assertEquals(element, other);
Expand Down Expand Up @@ -433,7 +433,7 @@ public void checkModelIsTree() {
Exception firstStack = allElements.put(ele, secondStack);
if (firstStack != null) {
if(firstStack == dummyException) {
Assert.fail("The Spoon model is not a tree. The " + ele.getClass().getSimpleName() + ":" + ele.toString() + " is shared");
fail("The Spoon model is not a tree. The " + ele.getClass().getSimpleName() + ":" + ele.toString() + " is shared");
}
//the element ele was already visited. It means it used on more places
//report the stacktrace of first and second usage, so that place can be found easily
Expand All @@ -449,7 +449,7 @@ public void checkModelIsTree() {

String report = problems.toString();
if (!report.isEmpty()) {
Assert.fail(report);
fail(report);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/parent/ParentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testParent() {
minus.setRightHandOperand(literal);
minus.setLeftHandOperand(literal);
} catch (Exception e) {
Assert.fail();
fail();
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ public void testParentOfPrimitiveReference() throws Exception {
public static void checkParentContract(CtPackage pack) {
pack.filterChildren(null).forEach((CtElement elem) -> {
// there is always one parent
Assert.assertTrue("no parent for "+elem.getClass()+"-"+elem.getPosition(), elem.isParentInitialized());
assertTrue("no parent for "+elem.getClass()+"-"+elem.getPosition(), elem.isParentInitialized());
});

// the scanner and the parent are in correspondence
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/spoon/test/pkg/PackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ public void testPackage() throws Exception {
Assert.assertSame(PackageTestClass.class, clazz.getActualClass());

CtPackage ctPackage = clazz.getPackage();
Assert.assertEquals("spoon.test.pkg.name", ctPackage.getQualifiedName());
Assert.assertEquals("", ctPackage.getDocComment());
assertEquals("spoon.test.pkg.name", ctPackage.getQualifiedName());
assertEquals("", ctPackage.getDocComment());
assertTrue(CtPackage.class.isAssignableFrom(ctPackage.getParent().getClass()));

ctPackage = (CtPackage) ctPackage.getParent();
Assert.assertEquals("spoon.test.pkg", ctPackage.getQualifiedName());
assertEquals("spoon.test.pkg", ctPackage.getQualifiedName());
Assert.assertNotNull(ctPackage.getPosition());
Assert.assertEquals(packageInfoFile.getCanonicalPath(), ctPackage.getPosition().getFile().getCanonicalPath());
Assert.assertEquals(1, ctPackage.getPosition().getLine());
Assert.assertEquals(0, ctPackage.getPosition().getSourceStart());
Assert.assertEquals(71, ctPackage.getPosition().getSourceEnd());
Assert.assertEquals(1, ctPackage.getAnnotations().size());
Assert.assertEquals("This is test\nJavaDoc.", ctPackage.getComments().get(0).getContent());
assertEquals(packageInfoFile.getCanonicalPath(), ctPackage.getPosition().getFile().getCanonicalPath());
assertEquals(1, ctPackage.getPosition().getLine());
assertEquals(0, ctPackage.getPosition().getSourceStart());
assertEquals(71, ctPackage.getPosition().getSourceEnd());
assertEquals(1, ctPackage.getAnnotations().size());
assertEquals("This is test\nJavaDoc.", ctPackage.getComments().get(0).getContent());

CtAnnotation<?> annotation = ctPackage.getAnnotations().get(0);
Assert.assertSame(Deprecated.class, annotation.getAnnotationType().getActualClass());
Assert.assertEquals(packageInfoFile.getCanonicalPath(), annotation.getPosition().getFile().getCanonicalPath());
Assert.assertEquals(5, annotation.getPosition().getLine());
assertEquals(packageInfoFile.getCanonicalPath(), annotation.getPosition().getFile().getCanonicalPath());
assertEquals(5, annotation.getPosition().getLine());

assertTrue(CtPackage.class.isAssignableFrom(ctPackage.getParent().getClass()));

ctPackage = (CtPackage) ctPackage.getParent();
Assert.assertEquals("spoon.test", ctPackage.getQualifiedName());
Assert.assertEquals("", ctPackage.getDocComment());
assertEquals("spoon.test", ctPackage.getQualifiedName());
assertEquals("", ctPackage.getDocComment());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public void testQualifiedThisRef() {
ctTypes.add(ctClass);
printer.getElementPrinterHelper().writeHeader(ctTypes, imports);
printer.scan(ctClass);
Assert.assertTrue(printer.getResult().contains("Object o = this"));
Assert.assertTrue(printer.getResult().contains("Object o2 = QualifiedThisRef.this"));
assertTrue(printer.getResult().contains("Object o = this"));
assertTrue(printer.getResult().contains("Object o2 = QualifiedThisRef.this"));
}

@Test
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/spoon/test/replace/ReplaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ public void testReplaceField() {
CtClass<?> sample = factory.Package().get("spoon.test.replace.testclasses")
.getType("Foo");

Assert.assertEquals(factory.Type().createReference(int.class), sample.getField("i").getType());
assertEquals(factory.Type().createReference(int.class), sample.getField("i").getType());

// replace with another type
CtField replacement = factory.Core().createField();
replacement.setSimpleName("i");
replacement.setType(factory.Type().createReference(double.class));
sample.getField("i").replace(replacement);
Assert.assertEquals(factory.Type().createReference(double.class), sample.getField("i").getType());
assertEquals(factory.Type().createReference(double.class), sample.getField("i").getType());

// replace with another name
replacement = factory.Core().createField();
Expand All @@ -226,7 +226,7 @@ public void testReplaceField() {
sample.getField("i").replace(replacement);
Assert.assertNull(sample.getField("i"));
Assert.assertNotNull(sample.getField("j"));
Assert.assertEquals(factory.Type().createReference(double.class), sample.getField("j").getType());
assertEquals(factory.Type().createReference(double.class), sample.getField("j").getType());
}

@Test
Expand Down Expand Up @@ -266,7 +266,7 @@ public void testReplaceTwoMethods() {
Assert.assertNull(sample.getMethod("foo"));
Assert.assertNotNull(sample.getMethod("notfoo"));
Assert.assertNotNull(sample.getMethod("notfoo2"));
Assert.assertEquals(originCountOfMethods+1, sample.getTypeMembers().size());
assertEquals(originCountOfMethods+1, sample.getTypeMembers().size());
}

@Test
Expand All @@ -277,13 +277,13 @@ public void testReplaceExpression() {
CtVariable<?> var = sample.getBody().getStatement(0);

Assert.assertTrue(var.getDefaultExpression() instanceof CtLiteral);
Assert.assertEquals(3, ((CtLiteral<?>) var.getDefaultExpression()).getValue());
assertEquals(3, ((CtLiteral<?>) var.getDefaultExpression()).getValue());

CtLiteral replacement = factory.Core().createLiteral();
replacement.setValue(42);
var.getDefaultExpression().replace(replacement);

Assert.assertEquals(42, ((CtLiteral<?>) var.getDefaultExpression()).getValue());
assertEquals(42, ((CtLiteral<?>) var.getDefaultExpression()).getValue());

}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/spoon/test/signature/SignatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testNullSignatureInUnboundVariable() {
SpoonModelBuilder builder = new JDTSnippetCompiler(factory, content);
try {
builder.build();
Assert.fail();
fail();
} catch (Exception e) {
// Must fail due to the unbound element "Complex.I"
}
Expand Down