Skip to content
Permalink
Browse files
Make error prone happy by re-throwing catched exception
and while we are here, update to junit5
and get rid of unused code
  • Loading branch information
FSchumacher committed Apr 18, 2022
1 parent 1e93c67 commit fb6322030f9bc1ea97160810c3f83f066544c47c
Showing 2 changed files with 27 additions and 49 deletions.
@@ -17,10 +17,6 @@

package org.apache.jmeter.control;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.junit.stubs.TestSampler;
@@ -31,14 +27,15 @@
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jmeter.threads.JMeterVariables;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class TestIfController extends JMeterTestCase {
class TestIfController extends JMeterTestCase {

@BugId("56160")
@Test
public void testStackOverflow() throws Exception {
void testStackOverflow() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(1);
controller.setContinueForever(false);
@@ -65,15 +62,15 @@ public void testStackOverflow() throws Exception {
sampler.sample(null);
counter++;
}
assertEquals(0, counter);
Assertions.assertEquals(0, counter);
} catch (StackOverflowError e) {
fail("Stackoverflow occurred in testStackOverflow");
throw new AssertionError("Stackoverflow occurred in testStackOverflow", e);
}
}

@BugId("53768")
@Test
public void testBug53768() throws Exception {
void testBug53768() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(1);
controller.setContinueForever(false);
@@ -125,19 +122,19 @@ public void testBug53768() throws Exception {

Sampler sampler = controller.next();
sampler.sample(null);
assertEquals("0", vars.get("VAR1"));
Assertions.assertEquals("0", vars.get("VAR1"));
sampler = controller.next();
sampler.sample(null);
assertEquals("0", vars.get("VAR1"));
Assertions.assertEquals("0", vars.get("VAR1"));

} catch (StackOverflowError e) {
fail("Stackoverflow occurred in testStackOverflow");
throw new AssertionError("Stackoverflow occurred in testStackOverflow", e);
}
}

@Test
@Disabled
public void testProcessing() throws Exception {
void testProcessing() throws Exception {

GenericController controller = new GenericController();

@@ -150,7 +147,7 @@ public void testProcessing() throws Exception {
}

@Test
public void testProcessingTrue() throws Exception {
void testProcessingTrue() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
@@ -170,14 +167,14 @@ public void testProcessingTrue() throws Exception {
Sampler sampler = null;
while ((sampler = controller.next()) != null) {
sampler.sample(null);
assertEquals(order[counter], sampler.getName());
Assertions.assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
Assertions.assertEquals(counter, 6);
}

@Test
public void testProcessingTrueWithExpression() throws Exception {
void testProcessingTrueWithExpression() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
@@ -198,18 +195,18 @@ public void testProcessingTrueWithExpression() throws Exception {
Sampler sampler = null;
while ((sampler = controller.next()) != null) {
sampler.sample(null);
assertEquals(order[counter], sampler.getName());
Assertions.assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
Assertions.assertEquals(counter, 6);
}


/**
* Test false return on sample3 (sample4 doesn't execute)
*/
@Test
public void testEvaluateAllChildrenWithoutSubController() throws Exception {
void testEvaluateAllChildrenWithoutSubController() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
@@ -235,17 +232,17 @@ public void testEvaluateAllChildrenWithoutSubController() throws Exception {
if (sampler.getName().equals("Sample3")) {
ifCont.setCondition("true==false");
}
assertEquals(order[counter], sampler.getName());
Assertions.assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
Assertions.assertEquals(counter, 6);
}

/**
* test 2 loops with a sub generic controller (sample4 doesn't execute)
*/
@Test
public void testEvaluateAllChildrenWithSubController() throws Exception {
void testEvaluateAllChildrenWithSubController() throws Exception {
LoopController controller = new LoopController();
controller.setLoops(2);
controller.addTestElement(new TestSampler("Sample1"));
@@ -274,14 +271,14 @@ public void testEvaluateAllChildrenWithSubController() throws Exception {
if (sampler.getName().equals("Sample3")) {
ifCont.setCondition("true==false");
}
assertEquals(order[counter], sampler.getName());
Assertions.assertEquals(order[counter], sampler.getName());
counter++;
}
assertEquals(counter, 6);
Assertions.assertEquals(counter, 6);
}

@Test
public void shouldIgnoreEmptyLastLine() {
void shouldIgnoreEmptyLastLine() {
GenericController controller = new GenericController();

IfController ifCont = new IfController("true\n");
@@ -296,6 +293,6 @@ public void shouldIgnoreEmptyLastLine() {
ifCont.setRunningVersion(true);

Sampler sampler = controller.next();
assertFalse(sampler == null);
Assertions.assertNotNull(sampler);
}
}
@@ -105,7 +105,7 @@ public void BSH1() throws Exception {
bsh = BSHFParams("", "", null);
assertEquals("", bsh.execute());
} catch (InvalidVariableException e) {
fail("BeanShell not present");
throw new AssertionError("BeanShell not present", e);
}

bsh = BSHFParams("1", null, null);
@@ -158,25 +158,6 @@ public void BSH1() throws Exception {

}

// Helper class used to implement co-routine between two threads
private static class Baton {
void pass() {
done();
try {
wait(1000);
} catch (InterruptedException e) {
System.out.println(e);
}
}

void done() {
notifyAll();
}

}

private static final Baton BATON = new Baton();

// XPathFileContainer tests

public void XPathtestNull() throws Exception {
@@ -207,7 +188,7 @@ public void XPathtestColumns() throws Exception {
int last = 0;
for (int i = 0; i < f.size(); i++) {
last = f.nextRow();
log.debug("found [" + i + "]" + f.getXPathString(last));
log.debug("found [{}]{}", i, f.getXPathString(last));
}
assertEquals(last + 1, f.size());

@@ -275,7 +256,7 @@ public void XPathFile2() throws Exception{

private XPath setupXPath(String file, String expr) throws Exception{
XPath xp = new XPath();
xp.setParameters(makeParams(new Object[]{getResourceFilePath(file), expr}));
xp.setParameters(makeParams(getResourceFilePath(file), expr));
return xp;
}

0 comments on commit fb63220

Please sign in to comment.