You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitDateParserBadlyFormattedTest.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2012, Christian Halstrick and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.util;
  11. import static org.junit.Assert.fail;
  12. import java.text.ParseException;
  13. import java.util.Calendar;
  14. import java.util.GregorianCalendar;
  15. import org.eclipse.jgit.junit.MockSystemReader;
  16. import org.junit.After;
  17. import org.junit.Before;
  18. import org.junit.experimental.theories.DataPoints;
  19. import org.junit.experimental.theories.Theories;
  20. import org.junit.experimental.theories.Theory;
  21. import org.junit.runner.RunWith;
  22. /**
  23. * Tests which assert that unparseable Strings lead to ParseExceptions
  24. */
  25. @RunWith(Theories.class)
  26. public class GitDateParserBadlyFormattedTest {
  27. private String dateStr;
  28. @Before
  29. public void setUp() {
  30. MockSystemReader mockSystemReader = new MockSystemReader();
  31. SystemReader.setInstance(mockSystemReader);
  32. }
  33. @After
  34. public void tearDown() {
  35. SystemReader.setInstance(null);
  36. }
  37. public GitDateParserBadlyFormattedTest(String dateStr) {
  38. this.dateStr = dateStr;
  39. }
  40. @DataPoints
  41. public static String[] getDataPoints() {
  42. return new String[] { "", "1970", "3000.3000.3000", "3 yesterday ago",
  43. "now yesterday ago", "yesterdays", "3.day. 2.week.ago",
  44. "day ago", "Gra Feb 21 15:35:00 2007 +0100",
  45. "Sun Feb 21 15:35:00 2007 +0100",
  46. "Wed Feb 21 15:35:00 Grand +0100" };
  47. }
  48. @Theory
  49. public void badlyFormattedWithExplicitRef() {
  50. Calendar ref = new GregorianCalendar(SystemReader.getInstance()
  51. .getTimeZone(), SystemReader.getInstance().getLocale());
  52. try {
  53. GitDateParser.parse(dateStr, ref, SystemReader.getInstance()
  54. .getLocale());
  55. fail("The expected ParseException while parsing '" + dateStr
  56. + "' did not occur.");
  57. } catch (ParseException e) {
  58. // expected
  59. }
  60. }
  61. @Theory
  62. public void badlyFormattedWithoutRef() {
  63. try {
  64. GitDateParser.parse(dateStr, null, SystemReader.getInstance()
  65. .getLocale());
  66. fail("The expected ParseException while parsing '" + dateStr
  67. + "' did not occur.");
  68. } catch (ParseException e) {
  69. // expected
  70. }
  71. }
  72. }