/*
 Copyright 2016 - 2016 by Jan Dockx

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

module.exports = (function() {
  "use strict";

  var expect = require("chai").expect;
  var ConditionViolation = require("../../src/I/ConditionViolation");
  var util = require("../../src/_private/util");
  var testUtil = require("../_testUtil");
  var conditionErrorTest = require("./ConditionError");

  function expectInvariants(subject) {
    expect(subject).to.be.an.instanceOf(ConditionViolation);
    conditionErrorTest.expectInvariants(subject);
  }

  // describe("I", function() {
    describe("I/ConditionViolation", function() {

      describe("#ConditionViolation.createMessage", function() {
        it("has a function createMessage()", function() {
          expect(ConditionViolation).to.have.property("createMessage").that.is.a("function");
        });
      });

      describe("#ConditionViolation.createMessage()", function() {
        conditionErrorTest.selfCases.forEach(function(self) {
          conditionErrorTest.argsCases.forEach(function(args) {
            it("works when called with " + self + " - " + args, function() {
              var result = ConditionViolation.createMessage(conditionErrorTest.conditionCase, self, args);
              expect(result).to.be.a("string");
              expect(result).to.contain("" + conditionErrorTest.conditionCase);
              expect(result).to.contain("" + self);
              Array.prototype.forEach(function(arg) {
                expect(result).to.contain("" + arg);
              });
            });
          });
        });
      });

      describe("#ConditionViolation()", function() {
        conditionErrorTest.selfCases.forEach(function(self) {
          conditionErrorTest.argsCases.forEach(function(args) {
            it("creates an instance with all toppings for " + self + " - " + args, function() {
              var result = new ConditionViolation(conditionErrorTest.conditionCase, self, args);
              conditionErrorTest.expectConstructorPost(result, conditionErrorTest.conditionCase, self, args);
              expectInvariants(result);
              expect(result.name).to.equal("Contract Condition Violation");
              expect(result.message).to.equal(
                ConditionViolation.createMessage(conditionErrorTest.conditionCase, self, args)
              );
            });
          });
        });
      });

      conditionErrorTest.generatePrototypeMethodsDescriptions(
        function() {
          return new ConditionViolation(conditionErrorTest.conditionCase, null, conditionErrorTest.argsCases[0]);
        },
        testUtil
          .x([conditionErrorTest.conditionCase], conditionErrorTest.selfCases, conditionErrorTest.argsCases)
          .map(function(parameters) {
            return function() {
              return {
                subject: new ConditionViolation(parameters[0], parameters[1], parameters[2]),
                description: parameters.join(" - ")
              };
            };
          })
      );

    });
  // });

  var test = {
    expectInvariants: expectInvariants
  };
  Object.setPrototypeOf(test, conditionErrorTest);
  return test;

})();

@@ -3138,44 +3138,8 @@
  .x(
-%5BconditionErrorTest.conditionCase%5D, 
 cond
@@ -3331,24 +3331,58 @@
 onViolation(
+conditionErrorTest.conditionCase, 
 parameters%5B0
@@ -3401,23 +3401,8 @@
 s%5B1%5D
-, parameters%5B2%5D
 ),%0A 

Optimize cardinal product