我的代码中基于带有 randomUUID 的 Spring IntegrationenrichHeader有以下定义:
@Bean
public Consumer<HeaderEnricherSpec> uriHeaderEnricher() {
return new Consumer<HeaderEnricherSpec>() {
private final String TIMESTAMP = "Timestamp";
private final String MESSAGE_ID = "MessageId";
@Override
public void accept(HeaderEnricherSpec t) {
t.headerFunction(MarklogicMessageHandler.URI,
m -> "/event/" +
format(m.getHeaders().get(TIMESTAMP)) + "/" +
m.getHeaders().get(MESSAGE_ID) +
".xml");
}
private String format(Object object) {
if (!(object instanceof String)) {
return "";
}
String string = (String) object;
return string.substring(0, 10).replaceAll("-", "/");
}
};
}
我有点受阻,尽管对此代码的单元测试会是什么样子。有什么建议么?