title: how to test a function inside angularjs service
body: <p>This is my simple service which handles navigation on my application. 
  If user clicks on "next" as per the current state he will be redirected to next page. </p>
  
  <pre><code>'use strict';
  
  angular
  .module('myAngularmodule')
  .service('ButtonBarService',
  function ($state, StatesConstants) {
  
      return {
          next: next
      };
  
      function next() {
          switch ($state.current.name) {
              case StatesConstants.LICENSE :
                  $state.go(StatesConstants.APPLICATIONGROUP);
                  break;
              case StatesConstants.APPLICATIONGROUP :
                  $state.go(StatesConstants.ANALYSIS);
                  break;
              default:
                  break;
          }
      }
  
  
  });
  </code></pre>
  
  <p>This is my spec file, when i am trying to test it fails</p>
  
  <pre><code>'use strict';
  
  describe('ButtonBarService', function () {
  
  beforeEach(module('myAngularmodule'));
  var ButtonBarService;
  
  beforeEach(inject(function (_ButtonBarService_) {
      ButtonBarService = _ButtonBarService_;
  
      spyOn(ButtonBarService, 'next');
  
  }));
  
  describe('next()', function () {
  
      it('should retrieve the current user', function () {
          expect(ButtonBarService.next).toHaveBeenCalled();
      });
  
  });
  
  });
  </code></pre>
  
  <p>It fails saying that "Expected spy next to have been called."
  There is no backend thingy in this service, I just generalized it to handle buttonbar things.
  I am quite new to front-end. I have seen answers which have $http, but was not able to understand.</p>