fakemechanism.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2012 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Provides a fake storage mechanism for testing.
  16. * @author chrishenry@google.com (Chris Henry)
  17. */
  18. goog.provide('goog.testing.storage.FakeMechanism');
  19. goog.setTestOnly('goog.testing.storage.FakeMechanism');
  20. goog.require('goog.storage.mechanism.IterableMechanism');
  21. goog.require('goog.structs.Map');
  22. /**
  23. * Creates a fake iterable mechanism.
  24. *
  25. * @constructor
  26. * @extends {goog.storage.mechanism.IterableMechanism}
  27. * @final
  28. */
  29. goog.testing.storage.FakeMechanism = function() {
  30. /**
  31. * @type {goog.structs.Map}
  32. * @private
  33. */
  34. this.storage_ = new goog.structs.Map();
  35. };
  36. goog.inherits(
  37. goog.testing.storage.FakeMechanism,
  38. goog.storage.mechanism.IterableMechanism);
  39. /** @override */
  40. goog.testing.storage.FakeMechanism.prototype.set = function(key, value) {
  41. this.storage_.set(key, value);
  42. };
  43. /** @override */
  44. goog.testing.storage.FakeMechanism.prototype.get = function(key) {
  45. return /** @type {?string} */ (
  46. this.storage_.get(key, null /* default value */));
  47. };
  48. /** @override */
  49. goog.testing.storage.FakeMechanism.prototype.remove = function(key) {
  50. this.storage_.remove(key);
  51. };
  52. /** @override */
  53. goog.testing.storage.FakeMechanism.prototype.__iterator__ = function(opt_keys) {
  54. return this.storage_.__iterator__(opt_keys);
  55. };