+ Start a Discussion

Testing Public Custom Settings for DML Exception

i have a custom setting that is Public and have to test for DMLException.i am doing one thing creating and inserting as one usere and calling the delete method as secong user which will not have access to This custom settings.i want to know is custom settings available for all profiles because its not throwing any exception my Apex function is 


  public PageReference deleteUserSettings(){

       try{        delete userSettings;       

  userSettings = new GlassUserApiSettings__c(setUpOwnerId = UserInfo.getUserId());


   catch (System.DMLException e){System.debug(e);} 

      return null;    }


and my test code is


static void testDeleteApiSettingsN(){

Profile p = [SELECT Id FROM Profile WHERE Name='Read Only'];
User u2 = new User(Alias = 'newUser', Email='newuser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@orgtest.com');
MirrorSettingsController ctrl = new MirrorSettingsController();
System.runAs(u2) {


i tried it with Stasndard User as well but its deleting not throwing exception. can any one please tell how to make code coverage of this to DMLException .