UserSettingsResource extends AbstractJaxRSResource { @GET @Path( "/list" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) @Facet ( name = "Unsupported" ) public ArrayList<Setting> getUserSettings() { try { IUserSettingService settingsService = getUserSettingService(); List<IUserSetting> userSettings = settingsService.getUserSettings(); ArrayList<Setting> settings = new ArrayList<Setting>(); for ( IUserSetting userSetting : userSettings ) { settings.add( new Setting( userSetting.getSettingName(), userSetting.getSettingValue() ) ); } return settings; } catch ( Exception e ) { e.printStackTrace(); } return null; } UserSettingsResource(); @GET @Path( "/list" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) @Facet ( name = "Unsupported" ) ArrayList<Setting> getUserSettings(); @GET @Path( "{setting : .+}" ) @Facet ( name = "Unsupported" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) Response getUserSetting( @PathParam( "setting" ) String setting ); @POST @Path( "{setting : .+}" ) @Facet ( name = "Unsupported" ) @Produces( { APPLICATION_JSON, APPLICATION_XML } ) Response setUserSetting( @PathParam( "setting" ) String setting, String settingValue );  }
@Test public void testGetUserSettings() throws Exception { IUserSetting userSetting = mock( IUserSetting.class ); when( userSetting.getSettingName() ).thenReturn( USER_SETTING_NAME ); when( userSetting.getSettingValue() ).thenReturn( USER_SETTING_VALUE ); List<IUserSetting> userSettings = new ArrayList<>(); userSettings.add( userSetting ); when( userSettingService.getUserSettings() ).thenReturn( userSettings ); when( userSettingsResource.getUserSettings() ).thenCallRealMethod(); ArrayList<Setting> response = userSettingsResource.getUserSettings(); assertNotNull( response ); assertTrue( !response.isEmpty() ); assertTrue( response.get( 0 ).getName().equals( USER_SETTING_NAME ) ); assertTrue( response.get( 0 ).getValue().equals( USER_SETTING_VALUE ) ); }