Skip to content

Commit

Permalink
optimize: Code format optimization (#1577)
Browse files Browse the repository at this point in the history
  • Loading branch information
theNorthWindBlow authored Oct 10, 2024
1 parent a5d1d6f commit 29ad46f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package cn.hippo4j.common.toolkit;

import com.github.dozermapper.core.converters.ConversionException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -37,7 +38,6 @@ public class BeanUtilTest {

@Test
public void beanToBeanConvertTest(){
// Test BeanToAnotherBean
final Person person = new Person();
person.setName("Hippo4j");
person.setAge(1);
Expand All @@ -53,7 +53,6 @@ public void beanToBeanConvertTest(){

@Test
public void beanToMapConvertTest() {
// 测试BeanToMap
final Person person = new Person();
person.setName("Hippo4j");
person.setAge(1);
Expand All @@ -68,7 +67,6 @@ public void beanToMapConvertTest() {

@Test
public void mapToBeanConvertTest() {
// 测试MapToBean
final HashMap<String, Object> map = new HashMap<>();
map.put("name", "Hippo4j");
map.put("age", 1);
Expand Down Expand Up @@ -105,21 +103,16 @@ public void SetToSetConvertTest() {

@Test
public void copyPropertiesBeanToMapTest() {
// 测试BeanToMap
final Person person = new Person();
person.setName("Hippo4j");

final Map<?, ?> convert = BeanUtil.convert(person, Map.class);
Assert.assertEquals("Hippo4j", convert.get("name"));

// static属性应被忽略
Assert.assertFalse(convert.containsKey("STATIC_NAME"));
}

/**
* 测试在不忽略错误情况下,转换失败需要报错。
*/
// @Test(expected = ConversionException.class)
@Test(expected = ConversionException.class)
public void mapToBeanWinErrorTest() {
final Map<String, String> map = new HashMap<>();
map.put("age", "Hippo4j");
Expand Down Expand Up @@ -157,42 +150,88 @@ public void testSetter() {
@NoArgsConstructor
public static class Person {

/**
* STATIC_NAME
*/
public static final String STATIC_NAME = "STATIC_NAME";

/**
* name
*/
private String name;

/**
* age
*/
private int age;

/**
* address
*/
private String address;

/**
* size
*/
private Integer size;
}

@Setter
public static class PersonVo {

/**
* name
*/
private String name;

/**
* age
*/
private int age;
}

@Getter
@Setter
static class Customer {

/**
* name
*/
String name;

/**
* statusCode
*/
Integer statusCode;
}

@Getter
@Setter
static class PreCustomer {

/**
* name
*/
String name;

/**
* statusCode
*/
Integer statusCode;
}

@Getter
@Setter
static class GoodPerson extends Person{

String gender;
String nature;
/**
* gender
*/
private String gender;

/**
* nature
*/
private String nature;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class AdapterThreadPoolElasticSearchMonitorHandler extends AbstractAdapterThreadPoolMonitor {

private AtomicBoolean isIndexExist = null;

@Override
protected void execute(ThreadPoolAdapterState threadPoolAdapterState) {
ElasticSearchThreadPoolRunStateInfo esThreadPoolRunStateInfo = BeanUtil.convert(threadPoolAdapterState, ElasticSearchThreadPoolRunStateInfo.class);
Expand Down Expand Up @@ -149,12 +150,35 @@ public String getType() {
@Builder
private static class EsIndex {

String index;
String type;
String mapping;
Integer shards;
Integer replicas;
String alias;
/**
* index
*/
private String index;

/**
* type
*/
private String type;

/**
* mapping
*/
private String mapping;

/**
* shards
*/
private Integer shards;

/**
* replicas
*/
private Integer replicas;

/**
* alias
*/
private String alias;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
public class WebThreadPoolElasticSearchMonitorHandler extends AbstractWebThreadPoolMonitor {

private AtomicBoolean isIndexExist = null;

@Override
protected void execute(ThreadPoolRunStateInfo poolRunStateInfo) {
ElasticSearchThreadPoolRunStateInfo esThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ElasticSearchThreadPoolRunStateInfo.class);
Expand Down Expand Up @@ -147,11 +148,34 @@ public String getType() {
@Builder
private static class EsIndex {

String index;
String type;
String mapping;
Integer shards;
Integer replicas;
String alias;
/**
* index
*/
private String index;

/**
* type
*/
private String type;

/**
* mapping
*/
private String mapping;

/**
* shards
*/
private Integer shards;

/**
* replicas
*/
private Integer replicas;

/**
* alias
*/
private String alias;
}
}

0 comments on commit 29ad46f

Please sign in to comment.