Skip to content
Permalink
Browse files
Convert to junit5 methods
  • Loading branch information
FSchumacher committed Apr 18, 2022
1 parent 6ffd2dd commit a0eb461d74ac70c8b1f2ad025c008c83110f8ff3
Showing 1 changed file with 13 additions and 15 deletions.
@@ -17,9 +17,6 @@

package org.apache.jmeter;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -31,24 +28,25 @@
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.report.config.ConfigurationException;
import org.apache.jorphan.test.JMeterSerialTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class JMeterTest extends JMeterTestCase implements JMeterSerialTest {
class JMeterTest extends JMeterTestCase implements JMeterSerialTest {

@Test
public void testFailureWhenJmxDoesntExist() {
void testFailureWhenJmxDoesNotExist() {
JMeter jmeter = new JMeter();
try {
jmeter.runNonGui("testPlan.jmx", null, false, null, false);
fail("Expected ConfigurationException to be thrown");
Assertions.fail("Expected ConfigurationException to be thrown");
} catch (ConfigurationException e) {
assertTrue("When the file doesn't exist, this method 'runNonGui' should have a detailed message",
e.getMessage().contains("doesn't exist or can't be opened"));
Assertions.assertTrue(e.getMessage().contains("doesn't exist or can't be opened"),
"When the file doesn't exist, this method 'runNonGui' should have a detailed message");
}
}

@Test
public void testSuccessWhenJmxExists() throws IOException, ConfigurationException {
void testSuccessWhenJmxExists() throws IOException, ConfigurationException {
File temp = File.createTempFile("testPlan", ".jmx");
String testPlan = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<jmeterTestPlan version=\"1.2\" properties=\"5.0\" jmeter=\"5.2-SNAPSHOT\">\n" + " <hashTree>\n"
@@ -72,12 +70,12 @@ public void testSuccessWhenJmxExists() throws IOException, ConfigurationExceptio
JMeter jmeter = new JMeter();
jmeter.runNonGui(temp.getAbsolutePath(), null, false, null, false);
} finally {
assertTrue("File "+ temp.getAbsolutePath()+ " should have been deleted", temp.delete());
Assertions.assertTrue(temp.delete(), () ->"File " + temp.getAbsolutePath() + " should have been deleted");
}
}

@Test
public void testFailureWithMissingPlugin() throws IOException, ConfigurationException {
void testFailureWithMissingPlugin() throws IOException {
File temp = File.createTempFile("testPlan", ".jmx");
String testPlan = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<jmeterTestPlan version=\"1.2\" properties=\"5.0\" jmeter=\"5.2-SNAPSHOT.20190506\">\n"
@@ -114,12 +112,12 @@ public void testFailureWithMissingPlugin() throws IOException, ConfigurationExce
JMeter jmeter = new JMeter();
try {
jmeter.runNonGui(temp.getAbsolutePath(), null, false, null, false);
fail("Expected ConfigurationException to be thrown");
Assertions.fail("Expected ConfigurationException to be thrown");
} catch (ConfigurationException e) {
assertTrue("When the plugin doesn't exist, the method 'runNonGui' should have a detailed message",
e.getMessage().contains("Error in NonGUIDriver Problem loading XML from"));
Assertions.assertTrue(e.getMessage().contains("Error in NonGUIDriver Problem loading XML from"),
"When the plugin doesn't exist, the method 'runNonGui' should have a detailed message");
} finally {
assertTrue("File "+ temp.getAbsolutePath()+ " should have been deleted", temp.delete());
Assertions.assertTrue(temp.delete(), () -> "File " + temp.getAbsolutePath() + " should have been deleted");
}
}
}

0 comments on commit a0eb461

Please sign in to comment.