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

HADOOP-19415. [JDK17] Upgrade JUnit from 4 to 5 in hadoop-common Part1. #7339

Merged
merged 9 commits into from
Feb 5, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.XMLUtils;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -85,7 +85,7 @@ protected void readTestConfigFile() {
testConfigFile, e);
success = false;
}
assertTrue("Error reading test config file", success);
assertTrue(success, "Error reading test config file");
}
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public void setUp() throws Exception {
readTestConfigFile();

conf = new Configuration();
conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
true);

clitestDataDir = new File(TEST_CACHE_DATA_DIR).
Expand Down Expand Up @@ -262,10 +262,9 @@ private void displayResults() {
LOG.info("NONE");
}

assertTrue("One of the tests failed. " +
"See the Detailed results to identify " +
"the command that failed", overallResults);

assertTrue(overallResults, "One of the tests failed. " +
"See the Detailed results to identify " +
"the command that failed");
}

/**
Expand Down Expand Up @@ -310,8 +309,8 @@ private boolean compareTextExitCode(ComparatorData compdata,
*********************************/

public void testAll() {
assertTrue("Number of tests has to be greater then zero",
testsFromConfigFile.size() > 0);
assertTrue(testsFromConfigFile.size() > 0,
"Number of tests has to be greater then zero");
LOG.info("TestAll");
// Run the tests defined in the testConf.xml config file.
for (int index = 0; index < testsFromConfigFile.size(); index++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@

import org.apache.hadoop.cli.util.CLICommand;
import org.apache.hadoop.cli.util.CommandExecutor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* Tests for the Command Line Interface (CLI)
*/
public class TestCLI extends CLITestHelper {
@Before
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
}

@After
@AfterEach
@Override
public void tearDown() throws Exception {
super.tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
import org.apache.hadoop.http.HttpServer2;
import org.apache.hadoop.util.XMLUtils;

import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Basic test case that the ConfServlet can write configuration
Expand All @@ -64,7 +68,7 @@ public class TestConfServlet {
new HashMap<String, String>();
private static final Map<String, String> MASK_PROPERTIES = new HashMap<>();

@BeforeClass
@BeforeAll
public static void initTestProperties() {
TEST_PROPERTIES.put("test.key1", "value1");
TEST_PROPERTIES.put("test.key2", "value2");
Expand Down Expand Up @@ -101,10 +105,10 @@ public void testParseHeaders() throws Exception {
verifyMap.put("application/xml", ConfServlet.FORMAT_XML);
verifyMap.put("application/json", ConfServlet.FORMAT_JSON);

HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletRequest request = mock(HttpServletRequest.class);
for(String contentTypeExpected : verifyMap.keySet()) {
String contenTypeActual = verifyMap.get(contentTypeExpected);
Mockito.when(request.getHeader(HttpHeaders.ACCEPT))
when(request.getHeader(HttpHeaders.ACCEPT))
.thenReturn(contentTypeExpected);
assertEquals(contenTypeActual,
ConfServlet.parseAcceptHeader(request));
Expand Down Expand Up @@ -160,9 +164,9 @@ private void verifyGetProperty(Configuration conf, String format,
} else {
// if property name is not empty, and it's not in configuration
// expect proper error code and error message is set to the response
Mockito.verify(response).sendError(
Mockito.eq(HttpServletResponse.SC_NOT_FOUND),
Mockito.eq("Property " + propertyName + " not found"));
verify(response).sendError(
eq(HttpServletResponse.SC_NOT_FOUND),
eq("Property " + propertyName + " not found"));
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package org.apache.hadoop.conf;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests the tool (and the default expression) for deciding which config
* redact.
Expand Down Expand Up @@ -75,9 +76,8 @@ private void testRedact(Configuration conf) throws Exception {
);
for (String key : sensitiveKeys) {
processedText = redactor.redact(key, ORIGINAL_VALUE);
Assert.assertEquals(
"Config parameter wasn't redacted and should be: " + key,
REDACTED_TEXT, processedText);
assertEquals(REDACTED_TEXT, processedText,
"Config parameter wasn't redacted and should be: " + key);
}

List<String> normalKeys = Arrays.asList(
Expand All @@ -90,9 +90,8 @@ private void testRedact(Configuration conf) throws Exception {
);
for (String key : normalKeys) {
processedText = redactor.redact(key, ORIGINAL_VALUE);
Assert.assertEquals(
"Config parameter was redacted and shouldn't be: " + key,
ORIGINAL_VALUE, processedText);
assertEquals(ORIGINAL_VALUE, processedText,
"Config parameter was redacted and shouldn't be: " + key);
}
}
}
Loading