errorhandlingmechanism_test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. goog.provide('goog.storage.mechanism.ErrorHandlingMechanismTest');
  15. goog.setTestOnly('goog.storage.mechanism.ErrorHandlingMechanismTest');
  16. goog.require('goog.storage.mechanism.ErrorHandlingMechanism');
  17. goog.require('goog.testing.jsunit');
  18. goog.require('goog.testing.recordFunction');
  19. var error = new Error();
  20. var submechanism = {
  21. get: function() { throw error; },
  22. set: function() { throw error; },
  23. remove: function() { throw error; }
  24. };
  25. var handler = goog.testing.recordFunction(goog.nullFunction);
  26. var mechanism;
  27. function setUp() {
  28. mechanism =
  29. new goog.storage.mechanism.ErrorHandlingMechanism(submechanism, handler);
  30. }
  31. function tearDown() {
  32. handler.reset();
  33. }
  34. function testSet() {
  35. mechanism.set('foo', 'bar');
  36. assertEquals(1, handler.getCallCount());
  37. assertArrayEquals(
  38. [
  39. error, goog.storage.mechanism.ErrorHandlingMechanism.Operation.SET,
  40. 'foo', 'bar'
  41. ],
  42. handler.getLastCall().getArguments());
  43. }
  44. function testGet() {
  45. mechanism.get('foo');
  46. assertEquals(1, handler.getCallCount());
  47. assertArrayEquals(
  48. [
  49. error, goog.storage.mechanism.ErrorHandlingMechanism.Operation.GET,
  50. 'foo'
  51. ],
  52. handler.getLastCall().getArguments());
  53. }
  54. function testRemove() {
  55. mechanism.remove('foo');
  56. assertEquals(1, handler.getCallCount());
  57. assertArrayEquals(
  58. [
  59. error, goog.storage.mechanism.ErrorHandlingMechanism.Operation.REMOVE,
  60. 'foo'
  61. ],
  62. handler.getLastCall().getArguments());
  63. }