test: freeze wechat surface contract
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class WechatSurfaceMapperTest {
|
||||
@Test
|
||||
public void toConversationRow_keepsOnlyWechatFields() throws Exception {
|
||||
Object row = invokeStatic(
|
||||
"toConversationRow",
|
||||
new Class<?>[]{String.class, String.class, String.class, int.class},
|
||||
"项目 A",
|
||||
"最近消息预览",
|
||||
"10:24",
|
||||
3
|
||||
);
|
||||
|
||||
assertEquals("项目 A", readField(row, "title"));
|
||||
assertEquals("最近消息预览", readField(row, "preview"));
|
||||
assertEquals("10:24", readField(row, "timeLabel"));
|
||||
assertEquals(3, readField(row, "unreadCount"));
|
||||
assertEquals(
|
||||
Arrays.asList("title", "preview", "timeLabel", "unreadCount"),
|
||||
Arrays.asList(readDeclaredFieldNames(row.getClass()))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDeviceRow_keepsOnlySimpleSubtitle() throws Exception {
|
||||
Object row = invokeStatic(
|
||||
"toDeviceRow",
|
||||
new Class<?>[]{String.class, boolean.class, String.class},
|
||||
"Mac Studio",
|
||||
true,
|
||||
"17600003315"
|
||||
);
|
||||
|
||||
assertEquals("Mac Studio", readField(row, "title"));
|
||||
assertEquals("在线 · 账号 17600003315", readField(row, "subtitle"));
|
||||
assertEquals(
|
||||
Arrays.asList("title", "subtitle"),
|
||||
Arrays.asList(readDeclaredFieldNames(row.getClass()))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rootMeMenuTitles_matchApprovedSimpleMenu() throws Exception {
|
||||
Object titles = invokeStatic("rootMeMenuTitles", new Class<?>[0]);
|
||||
assertArrayEquals(
|
||||
new String[]{"账号与安全", "AI 账号", "设置", "技能", "关于"},
|
||||
toStringArray(titles)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void projectQuickActions_keepOnlyGoalsAndVersions() throws Exception {
|
||||
Object titles = invokeStatic("projectQuickActions", new Class<?>[0]);
|
||||
assertArrayEquals(
|
||||
new String[]{"项目目标", "版本记录"},
|
||||
toStringArray(titles)
|
||||
);
|
||||
}
|
||||
|
||||
private static Object invokeStatic(String methodName, Class<?>[] parameterTypes, Object... args) throws Exception {
|
||||
Class<?> mapperClass = Class.forName("com.hyzq.boss.WechatSurfaceMapper");
|
||||
Method method = mapperClass.getDeclaredMethod(methodName, parameterTypes);
|
||||
return method.invoke(null, args);
|
||||
}
|
||||
|
||||
private static Object readField(Object target, String fieldName) throws Exception {
|
||||
Field field = target.getClass().getField(fieldName);
|
||||
return field.get(target);
|
||||
}
|
||||
|
||||
private static String[] readDeclaredFieldNames(Class<?> type) {
|
||||
Field[] fields = type.getDeclaredFields();
|
||||
String[] names = new String[fields.length];
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
names[i] = fields[i].getName();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private static String[] toStringArray(Object value) {
|
||||
if (value instanceof String[]) {
|
||||
return (String[]) value;
|
||||
}
|
||||
if (value instanceof List) {
|
||||
List<?> list = (List<?>) value;
|
||||
String[] result = new String[list.size()];
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result[i] = String.valueOf(list.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
throw new IllegalStateException("Unexpected return type: " + value.getClass());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user