Skip to content

Commit a79f3c6

Browse files
committed
improve: Rewrite code using rewrite-maven-plugin
1 parent 186e574 commit a79f3c6

File tree

49 files changed

+230
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+230
-245
lines changed

flink-platform-alert/src/main/java/com/flink/platform/alert/AlertSender.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ private String getJobRunDetails(Long flowRunId) {
7676
.eq(JobRunInfo::getFlowRunId, flowRunId));
7777

7878
StringBuilder buffer = new StringBuilder();
79-
jobRuns.forEach(jobRun -> buffer.append(
80-
String.format("%-10s", jobRun.getStatus().name()))
81-
.append(" : ")
82-
.append(jobRun.getName())
83-
.append("\n"));
79+
jobRuns.forEach(
80+
jobRun -> buffer.append("%-10s".formatted(jobRun.getStatus().name()))
81+
.append(" : ")
82+
.append(jobRun.getName())
83+
.append("\n"));
8484
return buffer.toString();
8585
}
8686

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.flink.platform.alert;
22

3-
import org.junit.Test;
4-
5-
import static org.junit.Assert.assertTrue;
3+
import org.junit.jupiter.api.Test;
64

75
/** Unit test for simple App. */
8-
public class AppTest {
6+
class AppTest {
97

108
/** Test. */
119
@Test
12-
public void testApp() {
13-
assertTrue(true);
14-
}
10+
void app() {}
1511
}

flink-platform-common/src/test/java/com/flink/platform/common/test/DAGTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import com.flink.platform.common.graph.DAG;
44
import com.flink.platform.common.graph.Edge;
55
import com.flink.platform.common.graph.Vertex;
6-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
77

88
/** Junit test for DAG. */
9-
public class DAGTest {
9+
class DAGTest {
1010

1111
@Test
12-
public void test() {
12+
void test() {
1313
DAG<Long, Vertex<Long>, Edge<Long>> dag = new DAG<>();
1414
dag.addVertex(new Vertex<>(1L));
1515
dag.addVertex(new Vertex<>(2L));

flink-platform-common/src/test/java/com/flink/platform/common/test/DurationTest.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
package com.flink.platform.common.test;
2020

2121
import com.flink.platform.common.util.DurationUtil;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.fail;
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertThrows;
26+
import static org.junit.jupiter.api.Assertions.fail;
2627

2728
/** Tests for Duration, copy from flink. */
28-
public class DurationTest {
29+
class DurationTest {
2930

3031
@Test
31-
public void testParseNanos() {
32+
void parseNanos() {
3233
assertEquals(424562, DurationUtil.parse("424562ns").getNano());
3334
assertEquals(424562, DurationUtil.parse("424562nano").getNano());
3435
assertEquals(424562, DurationUtil.parse("424562nanos").getNano());
@@ -38,7 +39,7 @@ public void testParseNanos() {
3839
}
3940

4041
@Test
41-
public void testParseMicros() {
42+
void parseMicros() {
4243
assertEquals(565731 * 1000L, DurationUtil.parse("565731µs").getNano());
4344
assertEquals(565731 * 1000L, DurationUtil.parse("565731micro").getNano());
4445
assertEquals(565731 * 1000L, DurationUtil.parse("565731micros").getNano());
@@ -48,7 +49,7 @@ public void testParseMicros() {
4849
}
4950

5051
@Test
51-
public void testParseMillis() {
52+
void parseMillis() {
5253
assertEquals(1234, DurationUtil.parse("1234").toMillis());
5354
assertEquals(1234, DurationUtil.parse("1234ms").toMillis());
5455
assertEquals(1234, DurationUtil.parse("1234milli").toMillis());
@@ -59,7 +60,7 @@ public void testParseMillis() {
5960
}
6061

6162
@Test
62-
public void testParseSeconds() {
63+
void parseSeconds() {
6364
assertEquals(667766, DurationUtil.parse("667766s").getSeconds());
6465
assertEquals(667766, DurationUtil.parse("667766sec").getSeconds());
6566
assertEquals(667766, DurationUtil.parse("667766secs").getSeconds());
@@ -69,7 +70,7 @@ public void testParseSeconds() {
6970
}
7071

7172
@Test
72-
public void testParseMinutes() {
73+
void parseMinutes() {
7374
assertEquals(7657623, DurationUtil.parse("7657623m").toMinutes());
7475
assertEquals(7657623, DurationUtil.parse("7657623min").toMinutes());
7576
assertEquals(7657623, DurationUtil.parse("7657623minute").toMinutes());
@@ -78,23 +79,23 @@ public void testParseMinutes() {
7879
}
7980

8081
@Test
81-
public void testParseHours() {
82+
void parseHours() {
8283
assertEquals(987654, DurationUtil.parse("987654h").toHours());
8384
assertEquals(987654, DurationUtil.parse("987654hour").toHours());
8485
assertEquals(987654, DurationUtil.parse("987654hours").toHours());
8586
assertEquals(987654, DurationUtil.parse("987654 h").toHours());
8687
}
8788

8889
@Test
89-
public void testParseDays() {
90+
void parseDays() {
9091
assertEquals(987654, DurationUtil.parse("987654d").toDays());
9192
assertEquals(987654, DurationUtil.parse("987654day").toDays());
9293
assertEquals(987654, DurationUtil.parse("987654days").toDays());
9394
assertEquals(987654, DurationUtil.parse("987654 d").toDays());
9495
}
9596

9697
@Test
97-
public void testParseUpperCase() {
98+
void parseUpperCase() {
9899
assertEquals(1L, DurationUtil.parse("1 NS").toNanos());
99100
assertEquals(1000L, DurationUtil.parse("1 MICRO").toNanos());
100101
assertEquals(1L, DurationUtil.parse("1 MS").toMillis());
@@ -105,13 +106,13 @@ public void testParseUpperCase() {
105106
}
106107

107108
@Test
108-
public void testParseTrim() {
109+
void parseTrim() {
109110
assertEquals(155L, DurationUtil.parse(" 155 ").toMillis());
110111
assertEquals(155L, DurationUtil.parse(" 155 ms ").toMillis());
111112
}
112113

113114
@Test
114-
public void testParseInvalid() {
115+
void parseInvalid() {
115116
// empty
116117
try {
117118
DurationUtil.parse("");
@@ -155,8 +156,8 @@ public void testParseInvalid() {
155156
}
156157
}
157158

158-
@Test(expected = IllegalArgumentException.class)
159-
public void testParseNumberOverflow() {
160-
DurationUtil.parse("100000000000000000000000000000000 ms");
159+
@Test
160+
void parseNumberOverflow() {
161+
assertThrows(IllegalArgumentException.class, () -> DurationUtil.parse("100000000000000000000000000000000 ms"));
161162
}
162163
}

flink-platform-common/src/test/java/com/flink/platform/common/test/JsonUtilTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
import com.flink.platform.common.job.SqlContext;
88
import com.flink.platform.common.util.JsonUtil;
99
import lombok.Data;
10-
import org.junit.Test;
10+
import org.junit.jupiter.api.Test;
1111

1212
import java.util.Collections;
1313
import java.util.List;
1414
import java.util.Map;
1515

1616
/** json test. */
17-
public class JsonUtilTest {
17+
class JsonUtilTest {
1818

1919
@Test
20-
public void testEnum() {
20+
void testEnum() {
2121
SqlContext sqlContext = new SqlContext();
2222
sqlContext.setId("a");
2323

@@ -36,7 +36,7 @@ public void testEnum() {
3636
}
3737

3838
@Test
39-
public void test() {
39+
void test() {
4040
String listString =
4141
"[{\"symbol\":\"BILI\",\"costLevel\":1,\"strike\":\"\",\"currency\":\"USD\",\"expiry\":\"\",\"right\":\"\",\"status\":\"LONG\",\"timestamp\":1621990862104},{\"symbol\":\"BIDU\",\"costLevel\":1,\"strike\":\"\",\"currency\":\"USD\",\"expiry\":\"\",\"right\":\"\",\"status\":\"LONG\",\"timestamp\":1621990862101}]";
4242
CollectionLikeType positionListType =
@@ -49,22 +49,22 @@ public void test() {
4949
}
5050

5151
@Test
52-
public void test0() {
52+
void test0() {
5353
String listString = "[\"symbol\",\"BILI\"]";
5454
List<String> strings = JsonUtil.toList(listString);
5555
System.out.println(strings);
5656
}
5757

5858
@Test
59-
public void test1() {
59+
void test1() {
6060
String json =
6161
"{\"symbol\":\"BILI\",\"costLevel\":1,\"strike\":\"\",\"currency\":\"USD\",\"expiry\":\"\",\"right\":\"\",\"status\":\"LONG\",\"timestamp\":1621990862104}";
6262
Map<String, Object> map = JsonUtil.toMap(json);
6363
System.out.println(map);
6464
}
6565

6666
@Test
67-
public void test2() {
67+
void test2() {
6868
String json =
6969
"{\"symbol\":\"BILI\",\"costLevel\":1,\"strike\":\"\",\"currency\":\"USD\",\"expiry\":\"\",\"right\":\"\",\"status\":\"LONG\",\"timestamp\":1621990862104}";
7070
Map<String, String> strMap = JsonUtil.toStrMap(json);

flink-platform-common/src/test/java/com/flink/platform/common/test/SqlTypeTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.flink.platform.common.test;
22

33
import com.flink.platform.common.enums.SqlType;
4-
import org.junit.Test;
4+
import org.junit.jupiter.api.Test;
55

66
import java.util.Map;
77
import java.util.TreeMap;
88
import java.util.stream.Stream;
99

1010
/** sql type test. */
11-
public class SqlTypeTest {
11+
class SqlTypeTest {
1212

1313
@Test
14-
public void test0() {
14+
void test0() {
1515
System.out.println(SqlType.parse("select \n * from table "));
1616
System.out.println(SqlType.parse("insert into \n table select "));
1717
System.out.println(SqlType.parse("insert \n overwrite "));
@@ -20,7 +20,7 @@ public void test0() {
2020
}
2121

2222
@Test
23-
public void test1() {
23+
void test1() {
2424
System.out.println(SqlType.parse("create \n database \n test "));
2525
System.out.println(SqlType.parse("create \n table \n test "));
2626
System.out.println(SqlType.parse("create table \n test "));
@@ -40,7 +40,7 @@ public void test1() {
4040
}
4141

4242
@Test
43-
public void test2() {
43+
void test2() {
4444
System.out.println(SqlType.parse("drop\n database \n db"));
4545
System.out.println(SqlType.parse("drop\n table \n tab"));
4646
System.out.println(SqlType.parse("drop\n temporary \n view v"));
@@ -52,7 +52,7 @@ public void test2() {
5252
}
5353

5454
@Test
55-
public void test3() {
55+
void test3() {
5656
System.out.println(SqlType.parse("alter\n database \n db"));
5757
System.out.println(SqlType.parse("alter\n table \n tb"));
5858
System.out.println(SqlType.parse("alter\n temporary \n function f"));
@@ -61,12 +61,12 @@ public void test3() {
6161
}
6262

6363
@Test
64-
public void test4() {
64+
void test4() {
6565
Stream.iterate(0, i -> i + 1).limit(3).forEach(System.out::println);
6666
}
6767

6868
@Test
69-
public void test5() {
69+
void test5() {
7070
System.out.println(SqlType.parse("show catalogs "));
7171
System.out.println(SqlType.parse("show \n databases "));
7272
System.out.println(SqlType.parse("show tables "));
@@ -78,13 +78,13 @@ public void test5() {
7878
}
7979

8080
@Test
81-
public void test6() {
81+
void test6() {
8282
System.out.println(SqlType.parse("set \n a = b "));
8383
System.out.println("~end6~");
8484
}
8585

8686
@Test
87-
public void test7() {
87+
void test7() {
8888
Map<Integer, String> map = new TreeMap<>();
8989
map.put(1, "1");
9090
map.put(0, "0");
@@ -93,7 +93,7 @@ public void test7() {
9393
}
9494

9595
@Test
96-
public void test8() {
96+
void test8() {
9797
System.out.println(SqlType.parse("select \n * from table limit 10"));
9898
System.out.println(SqlType.parse("select \n * from table limit \n 10000"));
9999
System.out.println(SqlType.parse("select \n * from table limit 2, 10000"));
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package com.flink.platform.common.test;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
54

65
import static com.flink.platform.common.util.StringUtil.byteLength;
76
import static com.flink.platform.common.util.StringUtil.truncateByBytes;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
88

99
/**
1010
* string util test.
1111
*/
12-
public class StringUtilTest {
12+
class StringUtilTest {
1313

1414
@Test
15-
public void testTruncateByBytes() {
15+
void testTruncateByBytes() {
1616
String testStr = "你好,Hello, こんにちは";
1717
System.out.println(truncateByBytes(testStr, 2, true));
1818
System.out.println(truncateByBytes(testStr, 5, true));
@@ -22,9 +22,9 @@ public void testTruncateByBytes() {
2222
System.out.println(truncateByBytes(testStr, 15, false));
2323
System.out.println(truncateByBytes(testStr, 20, true));
2424
System.out.println(truncateByBytes(testStr, 20, false));
25-
Assert.assertTrue(byteLength(truncateByBytes(testStr, 15, false)) <= 15);
26-
Assert.assertTrue(byteLength(truncateByBytes(testStr, 15, true)) <= 15);
27-
Assert.assertTrue(byteLength(truncateByBytes(testStr, 20, false)) <= 20);
28-
Assert.assertTrue(byteLength(truncateByBytes(testStr, 20, true)) <= 20);
25+
assertTrue(byteLength(truncateByBytes(testStr, 15, false)) <= 15);
26+
assertTrue(byteLength(truncateByBytes(testStr, 15, true)) <= 15);
27+
assertTrue(byteLength(truncateByBytes(testStr, 20, false)) <= 20);
28+
assertTrue(byteLength(truncateByBytes(testStr, 20, true)) <= 20);
2929
}
3030
}

flink-platform-cron/src/main/java/com/flink/platform/cron/JobsInJobListStatusChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public void checkJobStatus() {
3939
}
4040

4141
jobRunInfoService.getJobRunsWithUnexpectedStatus().forEach(jobRun -> {
42-
String content = String.format(
43-
ALERT_TEMPLATE, jobRun.getName(), jobRun.getStatus().name());
42+
String content = ALERT_TEMPLATE.formatted(
43+
jobRun.getName(), jobRun.getStatus().name());
4444
JobFlowRun jobFlowRun = jobFlowRunService.getById(jobRun.getFlowRunId());
4545
alertSendingService.sendAlerts(jobFlowRun, content);
4646
});

flink-platform-cron/src/main/java/com/flink/platform/cron/UnscheduledJobFlowChecker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public void checkUnscheduledWorkflow() {
3535
}
3636

3737
jobFlowService.getUnscheduledJobFlows().forEach(jobFlow -> {
38-
String content = String.format(
39-
ALERT_TEMPLATE, jobFlow.getName(), jobFlow.getStatus().name());
38+
String content = ALERT_TEMPLATE.formatted(
39+
jobFlow.getName(), jobFlow.getStatus().name());
4040
alertSendingService.sendErrAlerts(jobFlow, content);
4141
});
4242
}
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.flink.platform.cron;
22

3-
import org.junit.Test;
4-
5-
import static org.junit.Assert.assertTrue;
3+
import org.junit.jupiter.api.Test;
64

75
/** Unit test for simple App. */
8-
public class MapperInitializerTest {
6+
class MapperInitializerTest {
97

108
@Test
11-
public void shouldAnswerWithTrue() {
12-
assertTrue(true);
13-
}
9+
void shouldAnswerWithTrue() {}
1410
}

0 commit comments

Comments
 (0)