Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. *
  6. * Software distributed under the License is distributed on an "AS IS"
  7. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  8. * License for the specific language governing rights and limitations
  9. * under the License.
  10. *
  11. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  12. */
  13. package org.openmrs.validator;
  14.  
  15. import org.junit.Assert;
  16. import org.junit.Test;
  17. import org.openmrs.notification.Alert;
  18. import org.springframework.validation.BindException;
  19. import org.springframework.validation.Errors;
  20.  
  21. /**
  22. * Tests methods on the {@link AlertValidator} class.
  23. *
  24. * @since 1.10
  25. */
  26. public class AlertValidatorTest {
  27. /**
  28. * @see AlertValidator#validate(Object,Errors)
  29. * @verifies fail validation if Alert Text is null or empty or whitespace
  30. */
  31. @Test
  32. public void validate_shouldFailValidationIfAlertTextIsNullOrEmptyOrWhitespace()
  33. throws Exception {
  34. Alert alert = new Alert();
  35. alert.setText(null);
  36.  
  37. Errors errors = new BindException(alert, "alert");
  38. new AlertValidator().validate(alert, errors);
  39. Assert.assertTrue(errors.hasFieldErrors("text"));
  40.  
  41. alert.setText("");
  42. errors = new BindException(alert, "alert");
  43. new AlertValidator().validate(alert, errors);
  44. Assert.assertTrue(errors.hasFieldErrors("text"));
  45.  
  46. alert.setText(" ");
  47. errors = new BindException(alert, "alert");
  48. new AlertValidator().validate(alert, errors);
  49. Assert.assertTrue(errors.hasFieldErrors("text"));
  50. }
  51.  
  52. /**
  53. * Test for all the values being set
  54. * @see AlertValidator#validate(Object,Errors)
  55. * @verifies pass validation if all required values are set
  56. */
  57. @Test
  58. public void validate_shouldPassValidationIfAllRequiredValuesAreSet()
  59. throws Exception {
  60. Alert alert = new Alert();
  61. alert.setText("Alert Text");
  62.  
  63. Errors errors = new BindException(alert, "alert");
  64. new AlertValidator().validate(alert, errors);
  65. Assert.assertFalse(errors.hasErrors());
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement