Spring mockMvc.perform(post.. problem z danymi

0

Witam,
czy ktoś z Was może mi wyjaśnić, dlaczego metoda

mockMvc.perform(post("/validate")
        .contentType(MediaType.APPLICATION_JSON)
        .content(new Gson().toJson(peselTest)))
.andExpect(model().attribute("numbersList", peselTest));

jako "danych źródłowych"(Actual) używa obiektu klasy Pesel utworzonego przez konstruktor w tej klasie a nie np. nowego obiektu utworzonego w klasie testowej, albo chociaż @Bean z klasy konfiguracyjnej, natomiast jako expected widzi już cokolwiek innego?

java.lang.AssertionError: Model attribute 'numbersList' expected:<Pesel(numbersList=[2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2], weights=[1, 3, 7, 9, 1, 3, 7, 9, 1, 3], result=null, control_number=2, serial_number=null, sex=null, year=0, month=0, day=0, birthday=null)> but was:<Pesel(numbersList=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], weights=[1, 3, 7, 9, 1, 3, 7, 9, 1, 3], result=poprawny, control_number=2, serial_number=222, sex=Kobieta, year=2022, month=2, day=22, birthday=22.02.2022)>

Expected :Pesel(numbersList=[2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2], weights=[1, 3, 7, 9, 1, 3, 7, 9, 1, 3], result=null, control_number=2, serial_number=null, sex=null, year=0, month=0, day=0, birthday=null)

Actual   :Pesel(numbersList=[2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], weights=[1, 3, 7, 9, 1, 3, 7, 9, 1, 3], result=poprawny, control_number=2, serial_number=222, sex=Kobieta, year=2022, month=2, day=22, birthday=22.02.2022)
1

Zamiast zastanawiać się dlaczego magia nie działa, może lepiej po prostu zdeserializuj sobie http response i porównaj sobie normalnie javowe obiekty? Albo bez deserializacji, z mniejszą magią - jsonPath też da radę.

1 użytkowników online, w tym zalogowanych: 0, gości: 1