Skip to content

Commit 950cd16

Browse files
authored
[FLINK-26758][container] Migrate tests to JUnit 5
1 parent 7acfa5e commit 950cd16

File tree

3 files changed

+84
-82
lines changed

3 files changed

+84
-82
lines changed

flink-container/src/test/java/org/apache/flink/container/entrypoint/StandaloneApplicationClusterConfigurationParserFactoryTest.java

+65-79
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,31 @@
2828
import org.apache.flink.runtime.entrypoint.parser.CommandLineParser;
2929
import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings;
3030
import org.apache.flink.util.ExceptionUtils;
31-
import org.apache.flink.util.TestLogger;
3231

33-
import org.junit.Before;
34-
import org.junit.Rule;
35-
import org.junit.Test;
36-
import org.junit.rules.TemporaryFolder;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.io.TempDir;
3735

3836
import java.io.File;
3937
import java.io.IOException;
38+
import java.nio.file.Path;
4039
import java.util.Optional;
4140
import java.util.Properties;
4241

43-
import static org.hamcrest.Matchers.arrayContaining;
44-
import static org.hamcrest.Matchers.containsString;
45-
import static org.hamcrest.Matchers.equalTo;
46-
import static org.hamcrest.Matchers.hasEntry;
47-
import static org.hamcrest.Matchers.is;
48-
import static org.hamcrest.core.IsNull.nullValue;
49-
import static org.junit.Assert.assertThat;
50-
import static org.junit.Assert.assertTrue;
51-
import static org.junit.Assert.fail;
42+
import static org.assertj.core.api.Assertions.assertThat;
43+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
44+
import static org.assertj.core.api.Fail.fail;
5245

5346
/** Tests for the {@link StandaloneApplicationClusterConfigurationParserFactory}. */
54-
public class StandaloneApplicationClusterConfigurationParserFactoryTest extends TestLogger {
47+
class StandaloneApplicationClusterConfigurationParserFactoryTest {
5548

56-
@Rule public TemporaryFolder tempFolder = new TemporaryFolder();
5749
private File confFile;
5850
private String confDirPath;
5951

60-
@Before
61-
public void createEmptyFlinkConfiguration() throws IOException {
62-
File confDir = tempFolder.getRoot();
63-
confDirPath = confDir.getAbsolutePath();
64-
confFile = new File(confDir, GlobalConfiguration.FLINK_CONF_FILENAME);
52+
@BeforeEach
53+
void createEmptyFlinkConfiguration(@TempDir Path tempFolder) throws IOException {
54+
confDirPath = tempFolder.toFile().getAbsolutePath();
55+
confFile = new File(tempFolder.toFile(), GlobalConfiguration.FLINK_CONF_FILENAME);
6556
confFile.createNewFile();
6657
}
6758

@@ -72,8 +63,7 @@ public void createEmptyFlinkConfiguration() throws IOException {
7263
private static final String JOB_CLASS_NAME = "foobar";
7364

7465
@Test
75-
public void testEntrypointClusterConfigurationToConfigurationParsing()
76-
throws FlinkParseException {
66+
void testEntrypointClusterConfigurationToConfigurationParsing() throws FlinkParseException {
7767
final JobID jobID = JobID.generate();
7868
final SavepointRestoreSettings savepointRestoreSettings =
7969
SavepointRestoreSettings.forPath("/test/savepoint/path", true);
@@ -101,25 +91,24 @@ public void testEntrypointClusterConfigurationToConfigurationParsing()
10191

10292
final StandaloneApplicationClusterConfiguration clusterConfiguration =
10393
commandLineParser.parse(args);
104-
assertThat(clusterConfiguration.getJobClassName(), is(equalTo(JOB_CLASS_NAME)));
105-
assertThat(clusterConfiguration.getArgs(), arrayContaining(arg1, arg2));
94+
assertThat(clusterConfiguration.getJobClassName()).isEqualTo(JOB_CLASS_NAME);
95+
assertThat(clusterConfiguration.getArgs()).contains(arg1, arg2);
10696

10797
final Configuration configuration =
10898
StandaloneApplicationClusterEntryPoint.loadConfigurationFromClusterConfig(
10999
clusterConfiguration);
110100

111101
final String strJobId = configuration.get(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID);
112-
assertThat(JobID.fromHexString(strJobId), is(equalTo(jobID)));
113-
assertThat(
114-
SavepointRestoreSettings.fromConfiguration(configuration),
115-
is(equalTo(savepointRestoreSettings)));
102+
assertThat(JobID.fromHexString(strJobId)).isEqualTo(jobID);
103+
assertThat(SavepointRestoreSettings.fromConfiguration(configuration))
104+
.isEqualTo(savepointRestoreSettings);
116105

117-
assertThat(configuration.get(RestOptions.PORT), is(equalTo(restPort)));
118-
assertThat(configuration.get(DeploymentOptions.TARGET), is(equalTo(value)));
106+
assertThat(configuration.get(RestOptions.PORT)).isEqualTo(restPort);
107+
assertThat(configuration.get(DeploymentOptions.TARGET)).isEqualTo(value);
119108
}
120109

121110
@Test
122-
public void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing()
111+
void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing()
123112
throws FlinkParseException {
124113
final JobID jobID = JobID.generate();
125114
final String[] args = {"-c", confDirPath, "--job-id", jobID.toHexString()};
@@ -131,14 +120,13 @@ public void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing
131120
clusterConfiguration);
132121

133122
final String strJobId = configuration.get(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID);
134-
assertThat(JobID.fromHexString(strJobId), is(equalTo(jobID)));
135-
assertThat(
136-
SavepointRestoreSettings.fromConfiguration(configuration),
137-
is(equalTo(SavepointRestoreSettings.none())));
123+
assertThat(JobID.fromHexString(strJobId)).isEqualTo(jobID);
124+
assertThat(SavepointRestoreSettings.fromConfiguration(configuration))
125+
.isEqualTo(SavepointRestoreSettings.none());
138126
}
139127

140128
@Test
141-
public void testEntrypointClusterConfigurationParsing() throws FlinkParseException {
129+
void testEntrypointClusterConfigurationParsing() throws FlinkParseException {
142130
final String key = "key";
143131
final String value = "value";
144132
final int restPort = 1234;
@@ -159,50 +147,48 @@ public void testEntrypointClusterConfigurationParsing() throws FlinkParseExcepti
159147
final StandaloneApplicationClusterConfiguration clusterConfiguration =
160148
commandLineParser.parse(args);
161149

162-
assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
163-
assertThat(clusterConfiguration.getJobClassName(), is(equalTo(JOB_CLASS_NAME)));
164-
assertThat(clusterConfiguration.getRestPort(), is(equalTo(restPort)));
150+
assertThat(clusterConfiguration.getConfigDir()).isEqualTo(confDirPath);
151+
assertThat(clusterConfiguration.getJobClassName()).isEqualTo(JOB_CLASS_NAME);
152+
assertThat(clusterConfiguration.getRestPort()).isEqualTo(restPort);
165153
final Properties dynamicProperties = clusterConfiguration.getDynamicProperties();
166154

167-
assertThat(dynamicProperties, hasEntry(key, value));
155+
assertThat(dynamicProperties).containsEntry(key, value);
168156

169-
assertThat(clusterConfiguration.getArgs(), arrayContaining(arg1, arg2));
157+
assertThat(clusterConfiguration.getArgs()).contains(arg1, arg2);
170158

171-
assertThat(
172-
clusterConfiguration.getSavepointRestoreSettings(),
173-
is(equalTo(SavepointRestoreSettings.none())));
159+
assertThat(clusterConfiguration.getSavepointRestoreSettings())
160+
.isEqualTo(SavepointRestoreSettings.none());
174161

175-
assertThat(clusterConfiguration.getJobId(), is(nullValue()));
162+
assertThat(clusterConfiguration.getJobId()).isNull();
176163
}
177164

178165
@Test
179-
public void testOnlyRequiredArguments() throws FlinkParseException {
166+
void testOnlyRequiredArguments() throws FlinkParseException {
180167
final String[] args = {"--configDir", confDirPath};
181168

182169
final StandaloneApplicationClusterConfiguration clusterConfiguration =
183170
commandLineParser.parse(args);
184171

185-
assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
186-
assertThat(clusterConfiguration.getDynamicProperties(), is(equalTo(new Properties())));
187-
assertThat(clusterConfiguration.getArgs(), is(new String[0]));
188-
assertThat(clusterConfiguration.getRestPort(), is(equalTo(-1)));
189-
assertThat(clusterConfiguration.getHostname(), is(nullValue()));
190-
assertThat(
191-
clusterConfiguration.getSavepointRestoreSettings(),
192-
is(equalTo(SavepointRestoreSettings.none())));
193-
assertThat(clusterConfiguration.getJobId(), is(nullValue()));
194-
assertThat(clusterConfiguration.getJobClassName(), is(nullValue()));
172+
assertThat(clusterConfiguration.getConfigDir()).isEqualTo(confDirPath);
173+
assertThat(clusterConfiguration.getDynamicProperties()).isEqualTo(new Properties());
174+
assertThat(clusterConfiguration.getArgs()).isEqualTo(new String[0]);
175+
assertThat(clusterConfiguration.getRestPort()).isEqualTo(-1);
176+
assertThat(clusterConfiguration.getHostname()).isNull();
177+
assertThat(clusterConfiguration.getSavepointRestoreSettings())
178+
.isEqualTo(SavepointRestoreSettings.none());
179+
assertThat(clusterConfiguration.getJobId()).isNull();
180+
assertThat(clusterConfiguration.getJobClassName()).isNull();
195181
}
196182

197-
@Test(expected = FlinkParseException.class)
198-
public void testMissingRequiredArgument() throws FlinkParseException {
183+
@Test
184+
void testMissingRequiredArgument() {
199185
final String[] args = {};
200-
201-
commandLineParser.parse(args);
186+
assertThatThrownBy(() -> commandLineParser.parse(args))
187+
.isInstanceOf(FlinkParseException.class);
202188
}
203189

204190
@Test
205-
public void testSavepointRestoreSettingsParsing() throws FlinkParseException {
191+
void testSavepointRestoreSettingsParsing() throws FlinkParseException {
206192
final String restorePath = "foobar";
207193
final String[] args = {"-c", confDirPath, "-j", JOB_CLASS_NAME, "-s", restorePath, "-n"};
208194
final StandaloneApplicationClusterConfiguration standaloneApplicationClusterConfiguration =
@@ -211,13 +197,13 @@ public void testSavepointRestoreSettingsParsing() throws FlinkParseException {
211197
final SavepointRestoreSettings savepointRestoreSettings =
212198
standaloneApplicationClusterConfiguration.getSavepointRestoreSettings();
213199

214-
assertThat(savepointRestoreSettings.restoreSavepoint(), is(true));
215-
assertThat(savepointRestoreSettings.getRestorePath(), is(equalTo(restorePath)));
216-
assertThat(savepointRestoreSettings.allowNonRestoredState(), is(true));
200+
assertThat(savepointRestoreSettings.restoreSavepoint()).isTrue();
201+
assertThat(savepointRestoreSettings.getRestorePath()).isEqualTo(restorePath);
202+
assertThat(savepointRestoreSettings.allowNonRestoredState()).isTrue();
217203
}
218204

219205
@Test
220-
public void testSetJobIdManually() throws FlinkParseException {
206+
void testSetJobIdManually() throws FlinkParseException {
221207
final JobID jobId = new JobID();
222208
final String[] args = {
223209
"--configDir", confDirPath, "--job-classname", "foobar", "--job-id", jobId.toString()
@@ -226,11 +212,11 @@ public void testSetJobIdManually() throws FlinkParseException {
226212
final StandaloneApplicationClusterConfiguration standaloneApplicationClusterConfiguration =
227213
commandLineParser.parse(args);
228214

229-
assertThat(standaloneApplicationClusterConfiguration.getJobId(), is(equalTo(jobId)));
215+
assertThat(standaloneApplicationClusterConfiguration.getJobId()).isEqualTo(jobId);
230216
}
231217

232218
@Test
233-
public void testInvalidJobIdThrows() {
219+
void testInvalidJobIdThrows() {
234220
final String invalidJobId = "0xINVALID";
235221
final String[] args = {
236222
"--configDir", confDirPath, "--job-classname", "foobar", "--job-id", invalidJobId
@@ -242,13 +228,13 @@ public void testInvalidJobIdThrows() {
242228
} catch (FlinkParseException e) {
243229
Optional<IllegalArgumentException> cause =
244230
ExceptionUtils.findThrowable(e, IllegalArgumentException.class);
245-
assertTrue(cause.isPresent());
246-
assertThat(cause.get().getMessage(), containsString(invalidJobId));
231+
assertThat(cause).isPresent();
232+
assertThat(cause.get().getMessage()).containsSequence(invalidJobId);
247233
}
248234
}
249235

250236
@Test
251-
public void testShortOptions() throws FlinkParseException {
237+
void testShortOptions() throws FlinkParseException {
252238
final String jobClassName = "foobar";
253239
final JobID jobId = new JobID();
254240
final String savepointRestorePath = "s3://foo/bar";
@@ -264,25 +250,25 @@ public void testShortOptions() throws FlinkParseException {
264250
final StandaloneApplicationClusterConfiguration clusterConfiguration =
265251
commandLineParser.parse(args);
266252

267-
assertThat(clusterConfiguration.getConfigDir(), is(equalTo(confDirPath)));
268-
assertThat(clusterConfiguration.getJobClassName(), is(equalTo(jobClassName)));
269-
assertThat(clusterConfiguration.getJobId(), is(equalTo(jobId)));
253+
assertThat(clusterConfiguration.getConfigDir()).isEqualTo(confDirPath);
254+
assertThat(clusterConfiguration.getJobClassName()).isEqualTo(jobClassName);
255+
assertThat(clusterConfiguration.getJobId()).isEqualTo(jobId);
270256

271257
final SavepointRestoreSettings savepointRestoreSettings =
272258
clusterConfiguration.getSavepointRestoreSettings();
273-
assertThat(savepointRestoreSettings.restoreSavepoint(), is(true));
274-
assertThat(savepointRestoreSettings.getRestorePath(), is(equalTo(savepointRestorePath)));
275-
assertThat(savepointRestoreSettings.allowNonRestoredState(), is(true));
259+
assertThat(savepointRestoreSettings.restoreSavepoint()).isTrue();
260+
assertThat(savepointRestoreSettings.getRestorePath()).isEqualTo(savepointRestorePath);
261+
assertThat(savepointRestoreSettings.allowNonRestoredState()).isTrue();
276262
}
277263

278264
@Test
279-
public void testHostOption() throws FlinkParseException {
265+
void testHostOption() throws FlinkParseException {
280266
final String hostName = "user-specified-hostname";
281267
final String[] args = {
282268
"--configDir", confDirPath, "--job-classname", "foobar", "--host", hostName
283269
};
284270
final StandaloneApplicationClusterConfiguration applicationClusterConfiguration =
285271
commandLineParser.parse(args);
286-
assertThat(applicationClusterConfiguration.getHostname(), is(hostName));
272+
assertThat(applicationClusterConfiguration.getHostname()).isEqualTo(hostName);
287273
}
288274
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
org.apache.flink.util.TestLoggerExtension

flink-table/flink-table-api-java-bridge/src/test/java/org/apache/flink/table/factories/PrintSinkFactoryTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.flink.table.connector.sink.DynamicTableSink;
2727
import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
2828

29-
import org.junit.Test;
29+
import org.junit.jupiter.api.Test;
3030

3131
import java.util.Arrays;
3232
import java.util.HashMap;
@@ -37,7 +37,7 @@
3737
import static org.assertj.core.api.Assertions.assertThat;
3838

3939
/** Tests for {@link PrintTableSinkFactory}. */
40-
public class PrintSinkFactoryTest {
40+
class PrintSinkFactoryTest {
4141

4242
private static final ResolvedSchema SCHEMA =
4343
ResolvedSchema.of(
@@ -46,7 +46,7 @@ public class PrintSinkFactoryTest {
4646
Column.physical("f2", DataTypes.BIGINT()));
4747

4848
@Test
49-
public void testPrint() {
49+
void testPrint() {
5050
Map<String, String> properties = new HashMap<>();
5151
properties.put("connector", "print");
5252
properties.put(PrintConnectorOptions.PRINT_IDENTIFIER.key(), "my_print");

0 commit comments

Comments
 (0)