title: How to write test cases for singleton XCTest Framework xcode 7
body: <p>I just started to learn to write unit testing using XCTest with xcode 7.2 and I think this Xcode does not support OCMock framework. I know nothing about this frame work .I now only XCTest Framework. Here my question is How to write cases for singleton objects. Here I used some code with Dependency injection making the property and all.</p>
  
  <pre><code>@property (nonatomic, strong) UIApplication *application;
  
  - (UIApplication*)application
  {
     if (!_application)
     {
         _application = [UIApplication sharedApplication];
     }
     return _application;
  }
  
  - (IBAction)pushNotificationsSwitchWasToggled:(id)sender
  {
     UISwitch *toggleSwitch = sender;
     if (toggleSwitch.on)
     {
         [self.application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
     }
     else
     {
         [self.application unregisterForRemoteNotifications];
     }
  }
  </code></pre>
  
  <h2>Test</h2>
  
  <p>If want to test the above method </p>
  
  <pre><code>- (void)testToggleOnRegistersForPushNotifications_On
  {
     //given
  
     SettingsViewController *sut = [[SettingsViewController alloc] init];
     sut.application =[UIApplication sharedApplication];
  //Here only one object is created ? not new right.
     [sut.pushNotificationsSwitch setOn:YES];
  
     //when
     [sut pushNotificationsSwitchWasToggled:sut.pushNotificationsSwitch];
  //here I am expecting code whether registerForRemoteNotificationTypes method is called or not.
  
   }
  </code></pre>
  
  <p>1)Here when we use singleton in any place object is created only one time . In test case I don't want to use real <code>[UIApplication sharedApplication]</code> . I want one dummy or fake object to test.</p>
  
  <p>2)How do we very whether remote notification is registered or not (in general how to very whether method is called or not ?). not with <code>[UIApplication sharedApplication]</code> you can explain me with any singleton example with <code>NSUSerDefault</code> (giving input and comparing result with expected.)</p>