Код: Выделить всё
@Component
public class SessionStateConverter implements Converter {
@Override
public UserSessionState convert(String source) {
try {
return UserSessionState.valueOf(source.toUpperCase());
} catch (Exception e) {
LOG.debug(String.format("Invalid UserSessionState value was provided: %s", source), e);
return null;
}
}
}
Код: Выделить всё
@RunWith(MockitoJUnitRunner.class)
public class MyTest {
private MockMvc mockMvc;
@Mock
private FormattingConversionService conversionService;
@InjectMocks
private MynController controller;
@Before
public void setup() {
conversionService.addConverter(new SessionStateConverter());
mockMvc = MockMvcBuilders.standaloneSetup(controller).setConversionService(conversionService).build();
}
@Test
public void testSetLoginUserState() throws Exception {
mockMvc.perform(post("/api/user/login"));
}
В режиме отладки я получаю следующую ошибку:
Код: Выделить всё
nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'rest.api.UserSessionState': no matching editors or conversion strategy found
Есть идеи?
Подробнее здесь: https://stackoverflow.com/questions/540 ... -unit-test