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