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

Code format optimization #1577

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading