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 spoon-control-flow tests to JUnit 5 #4615

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@

package fr.inria.controlflow;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import spoon.processing.AbstractProcessor;
import spoon.processing.ProcessingManager;
import spoon.reflect.code.CtIf;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.factory.Factory;
import spoon.support.QueueProcessingManager;

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

/**
* Created by marodrig on 04/01/2016.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

package fr.inria.controlflow;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import spoon.reflect.code.CtStatement;
import spoon.support.reflect.code.CtIfImpl;

import static fr.inria.controlflow.BranchKind.*;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Control flow graph tests
Expand All @@ -38,18 +38,17 @@
*/
public class ControlFlowGraphTests {

@Test(expected = NotFoundException.class)
public void testFindNodeNotFound() throws NotFoundException {
ControlFlowGraph graph = new ControlFlowGraph();

CtStatement s = new CtIfImpl();

ControlFlowNode branch1 = new ControlFlowNode(null, graph, BRANCH);
ControlFlowNode branch2 = new ControlFlowNode(null, graph, BRANCH);
graph.addEdge(branch1, branch2);

ControlFlowNode n = graph.findNode(s);
}
@Test
public void testFindNodeNotFound() throws NotFoundException{
assertThrows(NotFoundException.class, () -> {
ControlFlowGraph graph = new ControlFlowGraph();
CtStatement s = new CtIfImpl();
ControlFlowNode branch1 = new ControlFlowNode(null, graph, BRANCH);
ControlFlowNode branch2 = new ControlFlowNode(null, graph, BRANCH);
graph.addEdge(branch1, branch2);
ControlFlowNode n = graph.findNode(s);
});
}

@Test
public void testFindNode() throws NotFoundException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package fr.inria.controlflow;

import org.junit.Test;
import java.util.*;
import org.junit.jupiter.api.Test;
import spoon.Launcher;
import spoon.reflect.declaration.CtMethod;

import java.util.*;

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

public class ExceptionFlowTests {
@Test
Expand Down Expand Up @@ -281,9 +281,9 @@ public void testAddPathsForEmptyTryBlocksEnabled() {
assertNotNull(findNodeByString(cfg, "bang()"));
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testFinalizerReturnStatementInTryBlockRejected() {

assertThrows(IllegalArgumentException.class, () -> {
// contract: NaiveExceptionControlFlowStrategy should reject a try-catch construct if it is equipped with a
// finalizer and return statements are used anywhere in the construct

Expand All @@ -305,11 +305,12 @@ public void testFinalizerReturnStatementInTryBlockRejected() {
ControlFlowBuilder builder = new ControlFlowBuilder();
builder.setExceptionControlFlowStrategy(new NaiveExceptionControlFlowStrategy());
builder.build(method);
}
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testFinalizerReturnStatementInCatchBlockRejected() {

assertThrows(IllegalArgumentException.class, () -> {
// contract: NaiveExceptionControlFlowStrategy should reject a try-catch construct if it is equipped with a
// finalizer and return statements are used anywhere in the construct

Expand All @@ -333,11 +334,11 @@ public void testFinalizerReturnStatementInCatchBlockRejected() {
ControlFlowBuilder builder = new ControlFlowBuilder();
builder.setExceptionControlFlowStrategy(new NaiveExceptionControlFlowStrategy());
builder.build(method);
}
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void testFinalizerReturnStatementInFinalizerBlockRejected() {

// contract: NaiveExceptionControlFlowStrategy should reject a try-catch construct if it is equipped with a
// finalizer and return statements are used anywhere in the construct

Expand All @@ -363,8 +364,10 @@ public void testFinalizerReturnStatementInFinalizerBlockRejected() {

ControlFlowBuilder builder = new ControlFlowBuilder();
builder.setExceptionControlFlowStrategy(new NaiveExceptionControlFlowStrategy());
builder.build(method);
}
assertThrows(IllegalArgumentException.class, () -> {
builder.build(method);
});
}

@Test
public void testFinalizer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package fr.inria.controlflow;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import spoon.processing.AbstractProcessor;
import spoon.processing.ProcessingManager;
import spoon.reflect.declaration.CtMethod;
Expand All @@ -33,7 +33,7 @@

import static fr.inria.controlflow.BranchKind.BRANCH;
import static fr.inria.controlflow.BranchKind.STATEMENT;
import static junit.framework.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Created by marodrig on 14/10/2015.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
package fr.inria.dataflow;

import fr.inria.controlflow.*;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import spoon.reflect.reference.CtVariableReference;

import java.util.HashSet;

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

public class InitializedVariablesTest {

Expand Down Expand Up @@ -156,8 +156,9 @@ public void testIndex54_Bug() throws Exception {
}


@Ignore("Known bug")

@Test
@Disabled("Known bug")
public void testTwoConsecutiveLoops() throws Exception {
ControlFlowGraph graph = ForwardFlowBuilderVisitorTest.buildGraph(
this.getClass().getResource("/initialized").toURI().getPath(), "twoLoops", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package fr.inria.dataflow;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Created by marodrig on 03/02/2016.
Expand Down