PageRenderTime 61ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/test/java/org/jboss/as/ejb3/timer/schedule/RangeValueTestCase.java

#
Java | 64 lines | 31 code | 5 blank | 28 comment | 2 complexity | b3a65addec1828cd3696ecb2e9ce0ad3 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ejb3.timer.schedule;
  23. import junit.framework.Assert;
  24. import org.jboss.as.ejb3.timerservice.schedule.value.RangeValue;
  25. import org.junit.Test;
  26. /**
  27. * RangeValueTestCase
  28. *
  29. * @author Jaikiran Pai
  30. * @version $Revision: $
  31. */
  32. public class RangeValueTestCase {
  33. @Test
  34. public void testInvalidRange() {
  35. String[] invalidRangeValues =
  36. {null, "", " ", "0.1", "1d", "1.0", "?", "%", "$", "!", "&", "-", "/", ",", ".", "1-", "1-2-3", "1+2", "**",
  37. "*-", "*,1", "1,*", "5/*", "1, 2/2", "---", "-", "--", " -2 -3 -4", "-0", "1--"};
  38. for (String invalidRange : invalidRangeValues) {
  39. boolean accepts = RangeValue.accepts(invalidRange);
  40. Assert.assertFalse("Range value accepted an invalid value: " + invalidRange, accepts);
  41. try {
  42. RangeValue invalidRangeValue = new RangeValue(invalidRange);
  43. Assert.fail("Range value did *not* throw IllegalArgumentException for an invalid range: " + invalidRange);
  44. } catch (IllegalArgumentException iae) {
  45. // expected
  46. }
  47. }
  48. }
  49. @Test
  50. public void testValidRange() {
  51. String[] validRanges =
  52. {"1-8", "-7--1", "7--1", "1st Fri-1st Mon"};
  53. for (String validRange : validRanges) {
  54. boolean accepts = RangeValue.accepts(validRange);
  55. Assert.assertTrue("Valid range value wasn't accepted: " + validRange, accepts);
  56. RangeValue validRangeValue = new RangeValue(validRange);
  57. }
  58. }
  59. }