Я пытаюсь протестировать метод в своем коде и использую SessionFactory.
@Autowired
private EntityManagerFactory entityManagerFactory;
public Optoinal<Long> method(){
// some code ...
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
return anOptipnalLongValue();
}
Я хочу протестировать этот метод, но я застрял в SessionFactory. В моем TestClass я издевался над EntityManagerFactory, но я не знаю, что SessionFactory
вернуть?
when(entityManagerFactory.unwrap(SessionFactory.class)).thenReturn(SessionFactory.class); // the return here is not correct.
Я получаю эту ошибку: Не удается разрешить метод 'thenReturn (java .lang.Class)'
Буду признателен за любые предложения по исправлению. this.
UpdateSolution: Я также издевался над фабрикой сессий и ожидал, что это будет возвращаемое значение
private SessionFactory session;
@Before
public void init() {
session = mock(SessionFactory.class);
}
@Test
public void test() {
// some code ...
when(entityManagerFactory.unwrap(SessionFactory.class)).thenReturn(session);
}