Skip to content

Commit 50404de

Browse files
test: add unit tests for utils (#821)
1 parent 2bf6440 commit 50404de

13 files changed

Lines changed: 3252 additions & 0 deletions
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.fesod.sheet.util;
21+
22+
import org.apache.fesod.shaded.cglib.beans.BeanMap;
23+
import org.junit.jupiter.api.Assertions;
24+
import org.junit.jupiter.api.Test;
25+
26+
/**
27+
* Tests {@link BeanMapUtils}
28+
*/
29+
class BeanMapUtilsTest {
30+
31+
public static class TestUser {
32+
private String name;
33+
private int age;
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public void setName(String name) {
40+
this.name = name;
41+
}
42+
43+
public int getAge() {
44+
return age;
45+
}
46+
47+
public void setAge(int age) {
48+
this.age = age;
49+
}
50+
}
51+
52+
@Test
53+
void test_create_Functionality() {
54+
TestUser user = new TestUser();
55+
user.setName("Fesod");
56+
user.setAge(18);
57+
58+
BeanMap beanMap = BeanMapUtils.create(user);
59+
60+
Assertions.assertNotNull(beanMap);
61+
Assertions.assertEquals("Fesod", beanMap.get("name"));
62+
Assertions.assertEquals(18, beanMap.get("age"));
63+
beanMap.put("name", "Fesod");
64+
Assertions.assertEquals("Fesod", user.getName());
65+
}
66+
67+
@Test
68+
void test_create_NamingPolicy() {
69+
TestUser user = new TestUser();
70+
BeanMap beanMap = BeanMapUtils.create(user);
71+
72+
String generatedClassName = beanMap.getClass().getName();
73+
74+
Assertions.assertTrue(generatedClassName.contains("ByFesodCGLIB"));
75+
}
76+
77+
@Test
78+
void test_NamingPolicy_tag() {
79+
BeanMapUtils.FesodSheetNamingPolicy policy = BeanMapUtils.FesodSheetNamingPolicy.INSTANCE;
80+
81+
Assertions.assertDoesNotThrow(() -> {
82+
java.lang.reflect.Method getTagMethod = policy.getClass().getDeclaredMethod("getTag");
83+
getTagMethod.setAccessible(true);
84+
String tag = (String) getTagMethod.invoke(policy);
85+
Assertions.assertEquals("ByFesodCGLIB", tag);
86+
});
87+
}
88+
89+
@Test
90+
void test_create_null() {
91+
Assertions.assertThrows(NullPointerException.class, () -> {
92+
BeanMapUtils.create(null);
93+
});
94+
}
95+
}

0 commit comments

Comments
 (0)