@Before public void setup() { mockAccountDao = mock(AccountDao.class); mockFormDao = mock(FormDao.class); mockFormFieldDao = mock(FormFieldDao.class); mockAccountService = mock(AccountService.class); account = new Account(); account.setId(1L); form = new Form(); form.setAccount(account); form.setFields(new ArrayList<FormField>()); field = new FormField(); field.setForm(form); form.getFields().add(field); when(mockAccountDao.findByUsernameOrEmail("user")).thenReturn(account); when(mockFormDao.findById(1L)).thenReturn(form); when(mockFormFieldDao.findById(1L)).thenReturn(field); formService = new FormService(); formService.setAccountDao(mockAccountDao); formService.setMapper(mapper); formService.setFormDao(mockFormDao); formService.setFormFieldDao(mockFormFieldDao); formService.setAccountService(mockAccountService); }