<commit_before>describe('xml', function () {

  var xmlString = '<tests><test id="1"/></tests>',
      DOMParser, ActiveXObject, win;

  beforeEach(module('xml'));

  beforeEach(inject(function ($window) {
    win = $window;
    DOMParser = win.DOMParser;
    ActiveXObject = win.ActiveXObject;
  }));

  afterEach(function () {
    win.DOMParser = DOMParser;
    win.ActiveXObject = ActiveXObject;
  });

  describe('xmlFilter', function () {

    var filter, parser;

    beforeEach(inject(function (xmlParser, xmlFilter) {
      filter = xmlFilter;
      parser = xmlParser;
    }));

    it('will use the xmlParser.parse() method', function () {
      spyOn(parser, 'parse');
      filter(xmlString);
      expect(parser.parse).toHaveBeenCalledWith(xmlString);
    });

    it('will return a ng.element object', function () {
      var returnValue;
      spyOn(angular, 'element').andReturn('ng.xml.element');
      returnValue = filter(xmlString);
      expect(returnValue).toBe('ng.xml.element');
      angular.element.andCallThrough();
    });

    it('should integrate as expected', function () {
      var xml = filter(xmlString);
      expect(xml.find('test').length).toBe(1);
    });

  });

  describe('XMLParser', function () {

    describe('DOMParser', function () {

      var DOMParser;

      beforeEach(function () {
        DOMParser = jasmine.createSpy('DOMParser');
        DOMParser.prototype = jasmine.createSpyObj('prototype', ['parseFromString']);
        win.DOMParser = DOMParser;
        win.ActiveXObject = null;
      });

      it('will use the DOMParser class when it is available', inject(function (xmlParser) {
        expect(DOMParser).toHaveBeenCalled();
        xmlParser.parse(xmlString);
        expect(DOMParser.prototype.parseFromString).toHaveBeenCalled();
      }));

    });

    describe('ActiveXObject', function () {

      var ActiveXObject;

      beforeEach(function () {
        ActiveXObject = jasmine.createSpy('ActiveXObject');
        ActiveXObject.prototype = jasmine.createSpyObj('prototype', ['loadXML']);
        win.ActiveXObject = ActiveXObject;
        win.DOMParser = null;
      });

      describe('successful parsing', function () {

        beforeEach(function () {
          ActiveXObject.prototype.parseError = {errorCode: 0};
        });

        it('will use the ActiveXObject class when DOMParser is not available', inject(function (xmlParser) {
          expect(ActiveXObject).toHaveBeenCalled();
          xmlParser.parse(xmlString);
          expect(ActiveXObject.prototype.loadXML).toHaveBeenCalled();
        }));

      });

      describe('unsuccessful parsing', function () {

        beforeEach(function () {
          ActiveXObject.prototype.parseError = {errorCode: 1, reason: 'mung'};
        });

        it('will throw an error when there is a badly formed XML string', inject(function (xmlParser) {
          expect(function () {
            xmlParser.parse(xmlString);
          }).toThrow();
        }));

      });

    });

  });

  describe('httpInterceptor', function () {

    var responseHeaders = jasmine.createSpy().andReturn('application/xml'),
        $xmlHttpInterceptor;

    beforeEach(inject(function (xmlHttpInterceptor) {
      $xmlHttpInterceptor = xmlHttpInterceptor;
      spyOn(angular, 'element').andCallThrough();
    }));

    it('will check for the content-type', function () {
      $xmlHttpInterceptor.response({
        data: xmlString,
        headers: responseHeaders
      });
      expect(responseHeaders).toHaveBeenCalledWith('content-type');
    });

    it('will return a ng.element object', function () {
      $xmlHttpInterceptor.response({
        data: xmlString,
        headers: responseHeaders
      });
      expect(angular.element).toHaveBeenCalled();
    });

    it('will only act on a XML response', function () {
      responseHeaders.andReturn('text/html');
      $xmlHttpInterceptor.response({
        data: xmlString,
        headers: responseHeaders
      });
      expect(angular.element).not.toHaveBeenCalled();
    });

  });

});
<commit_msg>When testing the interceptor we should really test if the filter has been called.<commit_after>describe('xml', function () {

  var xmlString = '<tests><test id="1"/></tests>',
      DOMParser, ActiveXObject, win;

  beforeEach(module('xml'));

  describe('manual parsing', function () {

    beforeEach(inject(function ($window) {
      win = $window;
      DOMParser = win.DOMParser;
      ActiveXObject = win.ActiveXObject;
    }));

    afterEach(function () {
      win.DOMParser = DOMParser;
      win.ActiveXObject = ActiveXObject;
    });

    describe('xmlFilter', function () {

      var filter, parser;

      beforeEach(inject(function (xmlParser, xmlFilter) {
        filter = xmlFilter;
        parser = xmlParser;
      }));

      it('will use the xmlParser.parse() method', function () {
        spyOn(parser, 'parse');
        filter(xmlString);
        expect(parser.parse).toHaveBeenCalledWith(xmlString);
      });

      it('will return a ng.element object', function () {
        var returnValue;
        spyOn(angular, 'element').andReturn('ng.xml.element');
        returnValue = filter(xmlString);
        expect(returnValue).toBe('ng.xml.element');
        angular.element.andCallThrough();
      });

      it('should integrate as expected', function () {
        var xml = filter(xmlString);
        expect(xml.find('test').length).toBe(1);
      });

    });

    describe('XMLParser', function () {

      describe('DOMParser', function () {

        var DOMParser;

        beforeEach(function () {
          DOMParser = jasmine.createSpy('DOMParser');
          DOMParser.prototype = jasmine.createSpyObj('prototype', ['parseFromString']);
          win.DOMParser = DOMParser;
          win.ActiveXObject = null;
        });

        it('will use the DOMParser class when it is available', inject(function (xmlParser) {
          expect(DOMParser).toHaveBeenCalled();
          xmlParser.parse(xmlString);
          expect(DOMParser.prototype.parseFromString).toHaveBeenCalled();
        }));

      });

      describe('ActiveXObject', function () {

        var ActiveXObject;

        beforeEach(function () {
          ActiveXObject = jasmine.createSpy('ActiveXObject');
          ActiveXObject.prototype = jasmine.createSpyObj('prototype', ['loadXML']);
          win.ActiveXObject = ActiveXObject;
          win.DOMParser = null;
        });

        describe('successful parsing', function () {

          beforeEach(function () {
            ActiveXObject.prototype.parseError = {errorCode: 0};
          });

          it('will use the ActiveXObject class when DOMParser is not available', inject(function (xmlParser) {
            expect(ActiveXObject).toHaveBeenCalled();
            xmlParser.parse(xmlString);
            expect(ActiveXObject.prototype.loadXML).toHaveBeenCalled();
          }));

        });

        describe('unsuccessful parsing', function () {

          beforeEach(function () {
            ActiveXObject.prototype.parseError = {errorCode: 1, reason: 'mung'};
          });

          it('will throw an error when there is a badly formed XML string', inject(function (xmlParser) {
            expect(function () {
              xmlParser.parse(xmlString);
            }).toThrow();
          }));

        });

      });

    });

  });

  describe('automatic parsing', function () {

    describe('httpInterceptor', function () {

      var responseHeaders, xmlFilter, $xmlHttpInterceptor;

      beforeEach(module(function ($provide) {
        responseHeaders = jasmine.createSpy('response.headers').andReturn('application/xml');
        xmlFilter = jasmine.createSpy('xmlFilter');
        $provide.value('xmlFilter', xmlFilter);
      }));

      beforeEach(inject(function (xmlHttpInterceptor) {
        $xmlHttpInterceptor = xmlHttpInterceptor;
      }));

      function respond() {
        $xmlHttpInterceptor.response({
          data: xmlString,
          headers: responseHeaders
        });
      }

      it('will check for the content-type', function () {
        respond();
        expect(responseHeaders).toHaveBeenCalledWith('content-type');
      });

      it('will return a ng.element object', function () {
        respond();
        expect(xmlFilter).toHaveBeenCalled();
      });

      it('will only act on a XML response', function () {
        responseHeaders.andReturn('text/html');
        respond();
        expect(xmlFilter).not.toHaveBeenCalled();
      });

    });

  });

});

{'fraction_non_alphanumeric': 0.13646976418398318, 'fraction_numerical': 0.0009339248190520663, 'mean_word_length': 2.6501917341286747, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 77}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '879374', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2290, 'n_words': 442}