### Question:
AuditRequestBodyAdvice extends RequestBodyAdviceAdapter { @Override public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) { if (body instanceof Consents) { Consents consents = (Consents) body; MDC.put("iban", getIbans(consents).toString()); MDC.put("consentModel", getModel(consents)); } else { logger.warn("Unexpected body type {} for create consent", body.getClass()); } return body; }  @Override boolean supports(MethodParameter methodParameter,
                            Type targetType,
                            Class<? extends HttpMessageConverter<?>> converterType); @Override Object afterBodyRead(Object body,
                                HttpInputMessage inputMessage,
                                MethodParameter parameter,
                                Type targetType,
                                Class<? extends HttpMessageConverter<?>> converterType);  }### Answer:
@Test void afterBodyReadConsentModelGlobal() { Consents consents = new Consents(); AccountAccess access = new AccountAccess(); access.setAllPsd2(AccountAccess.AllPsd2.ALLACCOUNTS); consents.setAccess(access); advice.afterBodyRead(consents, null, null, null, null); assertThat(MDC.get("consentModel")).contains("global"); }
@Test void afterBodyReadConsentModelUnknown() { advice.afterBodyRead(new Consents(), null, null, null, null); assertThat(MDC.get("consentModel")).contains("unknown"); }
@Test void afterBodyReadDifferentObject() { MDC.clear(); advice.afterBodyRead(new Object(), null, null, null, null); assertThat(MDC.get("ibans")).isNull(); assertThat(MDC.get("consentModel")).isNull(); }
@Test void afterBodyReadGetIbanAndDetailsConsent() { String iban1 = "account-iban"; String iban2 = "balance-iban"; String iban3 = "trx-iban"; Consents consents = new Consents(); consents.setAccess(buildAccess(iban1, iban2, iban3)); advice.afterBodyRead(consents, null, null, null, null); String ibans = MDC.get("iban"); assertThat(ibans) .contains(iban1) .contains(iban2) .contains(iban3); assertThat(MDC.get("consentModel")).isEqualTo("detailed"); }
@Test void afterBodyReadConsentModelBankOffered() { Consents consents = new Consents(); consents.setAccess(new AccountAccess()); advice.afterBodyRead(consents, null, null, null, null); assertThat(MDC.get("consentModel")).contains("bank-offered"); }