0
我有以下我想測試的類。不得不測試一個匿名的內部類是非常困難的。任何幫助,將不勝感激。有沒有什麼方法可以用junit測試一個匿名的內部類?
@Configuration
public class CustomErrorConfiguration {
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes,
boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
errorAttributes.remove("timestamp");
errorAttributes.remove("status");
errorAttributes.remove("exception");
errorAttributes.remove("path");
if (errorAttributes.containsKey("error") && errorAttributes.containsKey("message")) {
Map<String, Object> attr = new HashMap<>();
attr.put("message", errorAttributes.get("message"));
return attr;
}
return errorAttributes;
}
};
}
}
爲什麼你不能在CustomErrorConfiguration裏面創建一個靜態類並測試它? – mlecz