style: 格式化代码

This commit is contained in:
zhouxy108 2025-04-09 21:44:59 +08:00
parent bca4ce531a
commit a05fc6cfe1
6 changed files with 23 additions and 32 deletions

View File

@ -26,9 +26,9 @@ import xyz.zhouxy.plusone.commons.util.StringTools;
*/ */
public interface IDCardNumber { public interface IDCardNumber {
static final char DEFAULT_REPLACED_CHAR = '*'; char DEFAULT_REPLACED_CHAR = '*';
static final int DEFAULT_DISPLAY_FRONT = 1; int DEFAULT_DISPLAY_FRONT = 1;
static final int DEFAULT_DISPLAY_END = 2; int DEFAULT_DISPLAY_END = 2;
/** /**
* 身份证号 * 身份证号

View File

@ -81,7 +81,7 @@ class IWithCodeTests {
assertThrows(NullPointerException.class, () -> WithLongCode.INSTANCE.isCodeEquals(longCode)); assertThrows(NullPointerException.class, () -> WithLongCode.INSTANCE.isCodeEquals(longCode));
} }
private static enum WithCode implements IWithCode<String> { private enum WithCode implements IWithCode<String> {
INSTANCE("testCode"), INSTANCE("testCode"),
SAME_CODE_INSTANCE("testCode"), SAME_CODE_INSTANCE("testCode"),
WRONG_CODE_INSTANCE("wrongCode"), WRONG_CODE_INSTANCE("wrongCode"),
@ -102,7 +102,7 @@ class IWithCodeTests {
} }
} }
private static enum WithIntCode implements IWithIntCode { private enum WithIntCode implements IWithIntCode {
INSTANCE(0), INSTANCE(0),
SAME_CODE_INSTANCE(0), SAME_CODE_INSTANCE(0),
WRONG_CODE_INSTANCE(1), WRONG_CODE_INSTANCE(1),
@ -120,7 +120,7 @@ class IWithCodeTests {
} }
} }
private static enum WithLongCode implements IWithLongCode { private enum WithLongCode implements IWithLongCode {
INSTANCE(0L), INSTANCE(0L),
SAME_CODE_INSTANCE(0L), SAME_CODE_INSTANCE(0L),
WRONG_CODE_INSTANCE(108L), WRONG_CODE_INSTANCE(108L),

View File

@ -181,13 +181,13 @@ public class PagingAndSortingQueryParamsTests {
} }
AccountQueryParams queryParams = jackson.readValue(WRONG_JSON_STR, AccountQueryParams.class); AccountQueryParams queryParams = jackson.readValue(WRONG_JSON_STR, AccountQueryParams.class);
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
} }
static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Test @Test
void testGson() throws Exception { void testGson() {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(LocalDate.class, new TypeAdapter<LocalDate>() { .registerTypeAdapter(LocalDate.class, new TypeAdapter<LocalDate>() {
@ -226,7 +226,7 @@ public class PagingAndSortingQueryParamsTests {
} }
AccountQueryParams queryParams = gson.fromJson(WRONG_JSON_STR, AccountQueryParams.class); AccountQueryParams queryParams = gson.fromJson(WRONG_JSON_STR, AccountQueryParams.class);
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
} }
} }

View File

@ -38,9 +38,7 @@ class QuarterTests {
assertEquals(1, quarter.getValue()); assertEquals(1, quarter.getValue());
assertEquals("Q1", quarter.name()); assertEquals("Q1", quarter.name());
assertThrows(DateTimeException.class, () -> { assertThrows(DateTimeException.class, () -> Quarter.of(0));
Quarter.of(0);
});
// ========== // ==========
@ -85,9 +83,7 @@ class QuarterTests {
assertEquals(2, quarter.getValue()); assertEquals(2, quarter.getValue());
assertEquals("Q2", quarter.name()); assertEquals("Q2", quarter.name());
assertThrows(DateTimeException.class, () -> { assertThrows(DateTimeException.class, () -> Quarter.of(5));
Quarter.of(5);
});
// ========== // ==========
@ -132,9 +128,7 @@ class QuarterTests {
assertEquals(3, quarter.getValue()); assertEquals(3, quarter.getValue());
assertEquals("Q3", quarter.name()); assertEquals("Q3", quarter.name());
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> Quarter.valueOf("Abc"));
Quarter.valueOf("Abc");
});
// ========== // ==========
@ -179,9 +173,7 @@ class QuarterTests {
assertEquals(4, quarter.getValue()); assertEquals(4, quarter.getValue());
assertEquals("Q4", quarter.name()); assertEquals("Q4", quarter.name());
assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> Quarter.valueOf("Q5"));
Quarter.valueOf("Q5");
});
// ========== // ==========

View File

@ -37,9 +37,8 @@ import cn.hutool.core.collection.ConcurrentHashSet;
public class IdGeneratorTests { public class IdGeneratorTests {
final ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, final ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS,
0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
new LinkedBlockingQueue<Runnable>());
@Test @Test
void testSnowflakeIdGenerator() { // NOSONAR void testSnowflakeIdGenerator() { // NOSONAR
@ -48,7 +47,7 @@ public class IdGeneratorTests {
for (int i = 0; i < 10000; i++) { for (int i = 0; i < 10000; i++) {
executor.execute(() -> { executor.execute(() -> {
for (int j = 0; j < 50000; j++) { for (int j = 0; j < 50000; j++) {
if (false == ids.add(snowflake.nextId())) { if (!ids.add(snowflake.nextId())) {
throw new RuntimeException("重复ID"); throw new RuntimeException("重复ID");
} }
} }

View File

@ -87,19 +87,19 @@ class TreeBuilderTests {
Arrays.stream(new Menu[] { B001, B002, B003, B004 }) Arrays.stream(new Menu[] { B001, B002, B003, B004 })
.sorted(Comparator.comparing(Menu::getOrderNum)) .sorted(Comparator.comparing(Menu::getOrderNum))
.collect(Collectors.toList()), .collect(Collectors.toList()),
MenuList.class.cast(menuMap.get("B")).children); ((MenuList) menuMap.get("B")).children);
assertEquals( assertEquals(
Arrays.stream(new Menu[] { C1, C2, C3 }) Arrays.stream(new Menu[] { C1, C2, C3 })
.sorted(Comparator.comparing(Menu::getOrderNum)) .sorted(Comparator.comparing(Menu::getOrderNum))
.collect(Collectors.toList()), .collect(Collectors.toList()),
MenuList.class.cast(menuMap.get("C")).children); ((MenuList) menuMap.get("C")).children);
assertEquals( assertEquals(
Arrays.stream(new Menu[] { C1001, C1002 }) Arrays.stream(new Menu[] { C1001, C1002 })
.sorted(Comparator.comparing(Menu::getOrderNum)) .sorted(Comparator.comparing(Menu::getOrderNum))
.collect(Collectors.toList()), .collect(Collectors.toList()),
MenuList.class.cast(menuMap.get("C1")).children); ((MenuList) menuMap.get("C1")).children);
} }
@ -125,18 +125,18 @@ class TreeBuilderTests {
} }
assertEquals(ImmutableList.of(B001, B002, B003, B004), assertEquals(ImmutableList.of(B001, B002, B003, B004),
MenuList.class.cast(menuMap.get("B")).children); ((MenuList) menuMap.get("B")).children);
assertEquals(ImmutableList.of(C1, C2, C3), assertEquals(ImmutableList.of(C1, C2, C3),
MenuList.class.cast(menuMap.get("C")).children); ((MenuList) menuMap.get("C")).children);
assertEquals(ImmutableList.of(C1001, C1002), assertEquals(ImmutableList.of(C1001, C1002),
MenuList.class.cast(menuMap.get("C1")).children); ((MenuList) menuMap.get("C1")).children);
} }
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
private static abstract class Menu implements Serializable { // NOSONAR private abstract static class Menu implements Serializable {
protected final String parentMenuCode; protected final String parentMenuCode;
protected final String menuCode; protected final String menuCode;
protected final String title; protected final String title;