verificationmode_test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2013 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.module('goog.labs.mock.VerificationModeTest');
  15. goog.setTestOnly('goog.labs.mock.VerificationModeTest');
  16. var testSuite = goog.require('goog.testing.testSuite');
  17. var verification = goog.require('goog.labs.mock.verification');
  18. var atLeast = verification.atLeast;
  19. var atMost = verification.atMost;
  20. var never = verification.never;
  21. var times = verification.times;
  22. testSuite({
  23. getTestName: function() { return 'goog.labs.mock.VerificationModeTest'; },
  24. testTimesVerify_expectedEqualsActual_shouldReturnTrue: function() {
  25. assertTrue(times(4).verify(4));
  26. },
  27. testTimesVerify_expectedGreaterThanActual_shouldReturnFalse: function() {
  28. assertFalse(times(4).verify(3));
  29. },
  30. testTimesVerify_expectedLessThanActual_shouldReturnFalse: function() {
  31. assertFalse(times(4).verify(5));
  32. },
  33. testTimesDescribe_shouldReturnCorrectMessage: function() {
  34. assertEquals(4 + ' times', times(4).describe());
  35. },
  36. testNeverVerify_shouldEqualTimesZeroVerify: function() {
  37. assertEquals(times(0).verify(0), never().verify(0));
  38. },
  39. testNeverDescribe_shouldReturnTimesZeroMessage: function() {
  40. assertEquals(times(0).describe(), never().describe());
  41. },
  42. testAtLeastVerify_expectedEqualsActual_shouldReturnTrue: function() {
  43. assertTrue(atLeast(4).verify(4));
  44. },
  45. testAtLeastVerify_expectedLessThanActual_shouldReturnTrue: function() {
  46. assertTrue(atLeast(1).verify(3));
  47. },
  48. testAtLeastVerify_expectedGreaterThanActual_shouldReturnFalse: function() {
  49. assertFalse(atLeast(4).verify(3));
  50. },
  51. testAtLeastDescribe_shouldReturnCorrectMessage: function() {
  52. assertEquals('at least ' + 4 + ' times', atLeast(4).describe());
  53. },
  54. testAtMostVerify_expectedEqualsActual_shouldReturnTrue: function() {
  55. assertTrue(atMost(4).verify(4));
  56. },
  57. testAtMostVerify_expectedGreaterThanActual_shouldReturnTrue: function() {
  58. assertTrue(atMost(4).verify(3));
  59. },
  60. testAtMostVerify_expectedLessThanActual_shouldReturnFalse: function() {
  61. assertFalse(atMost(1).verify(3));
  62. },
  63. testAtMostDescribe_shouldReturnCorrectMessage: function() {
  64. assertEquals('at most ' + 4 + ' times', atMost(4).describe());
  65. }
  66. });