/**
 * @overview Mock property injector.
 */

/**
 * Inject a mock to a module.
 * @param {object} module - Module to injected.
 * @param {string} key - Injection key.
 * @param {*} injection - Mock property to inject.
 */
exports.inject = function (module, key, injection) {
    exports._stack.push({
        module: module,
        key: key,
        origin: module[key],
        injection: injection
    });
    module[key] = injection;
};

exports.pop = function () {
    return exports._stack.pop();
};
exports.restore = function () {
    var data = exports.pop();
    if (data) {
        data.module[data.key] = data.origin;
    }
};

exports.restoreAll = function () {
    while (exports._stack.length) {
        exports.restore();
    }
};

exports._stack = [];