PreferencesResource implements IPreferencesResource { @Override public Response savePreference( String key, String value ) { this.logger.fine( "Request: save preference " + key + " with value " + value ); Response response; try { this.manager.preferencesMngr().save( key, value ); response = Response.ok().build(); } catch( IOException e ) { response = RestServicesUtils.handleError( Status.INTERNAL_SERVER_ERROR, new RestError( ErrorCode.REST_SAVE_ERROR, e, ErrorDetails.name( key )), RestServicesUtils.lang( this.manager )).build(); } return response; } PreferencesResource( Manager manager ); @Override List<Preference> getPreferences( String key ); @Override Response savePreference( String key, String value );  }
@Test public void testSaveException() throws Exception { IPreferencesMngr mock = Mockito.mock( IPreferencesMngr.class ); Mockito.doThrow( new IOException( "For test" )).when( mock ).save( Mockito.anyString(), Mockito.anyString()); this.manager.setPreferencesMngr( mock ); Response resp = this.resource.savePreference( "my-key", "my-value" ); Assert.assertEquals( Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus()); }