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

test: migrate Maintest to JUnit 5 #4570

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions src/test/java/spoon/test/main/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@
*/
package spoon.test.main;

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.Assertion;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;

import org.junit.jupiter.api.Test;
import spoon.ContractVerifier;
import spoon.Launcher;
import spoon.reflect.declaration.CtPackage;
import spoon.reflect.declaration.CtType;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MainTest {

Expand Down Expand Up @@ -145,7 +138,7 @@ public void testTest() {
//Meta model classes doesn't have to follow test class naming conventions
continue;
}
assertTrue(t.getQualifiedName() + " is not clearly a test class, it should contain 'test' either in its package name or class name", t.getQualifiedName().matches("(?i:.*test.*)"));
assertTrue(t.getQualifiedName().matches("(?i:.*test.*)"), t.getQualifiedName() + " is not clearly a test class, it should contain 'test' either in its package name or class name");
}
}

Expand Down Expand Up @@ -199,25 +192,4 @@ public void testResourcesNotCopiedInTargetDirectory() {
assertTrue(new File("src/test/resources/no-copy-resources/fr/inria/package.html").exists());
assertFalse(new File("target/spooned-without-resources/fr/inria/package.html").exists());
}

@Rule
public final ExpectedSystemExit exit = ExpectedSystemExit.none();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();

@Test
public void testLauncherWithoutArgumentsExitWithSystemExit() {
exit.expectSystemExit();

final PrintStream oldErr = System.err;
System.setErr(new PrintStream(errContent));
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() {
assertTrue(errContent.toString().contains("Usage: java <launcher name> [option(s)]"));
System.setErr(oldErr);
}
});

new Launcher().run(new String[] { });
}
}