jeudi 12 octobre 2017

Is there any way to test an anonymous inner class using junit?

I have the following class that I would like to test. Having to test an anonymous inner class is proving to be very difficult. Any help would be appreciated.

@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;
        }

    };
}

}

Aucun commentaire:

Enregistrer un commentaire