@Test @DirtiesContext public void testSavePreference() { Preference pref = new Preference(); pref.setEnabled(true); pref.setPushSenderID(1L); pref.setUsername("userA"); try { getService().savePreference(pref); } catch (Exception e) { fail("Exception thrown when saveDevice tries to insert with null primary key."); } assertFalse("Preference saved without id and should not have.", null == pref.getId()); }