This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new ac799698de Delete more `FastDateParser` tests (LOG4J2-3672, #1848)
ac799698de is described below
commit ac799698de8c0e1d360cd7f0c6858bea0174808b
Author: Volkan Yazıcı <[email protected]>
AuthorDate: Thu Nov 2 18:49:22 2023 +0100
Delete more `FastDateParser` tests (LOG4J2-3672, #1848)
---
.../core/util/datetime/FastDateParserSDFTest.java | 227 ---------------------
.../datetime/FastDateParser_MoreOrLessTest.java | 118 -----------
.../FastDateParser_TimeZoneStrategyTest.java | 71 -------
3 files changed, 416 deletions(-)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParserSDFTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParserSDFTest.java
deleted file mode 100644
index cfecdbf0b2..0000000000
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParserSDFTest.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.util.datetime;
-
-import java.text.ParseException;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-import java.util.stream.Stream;
-
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * Compare FastDateParser with SimpleDateFormat
- *
- * Copied from Apache Commons Lang 3 on 2016-11-16.
- */
-public class FastDateParserSDFTest {
-
- static Stream<Arguments> data() {
- return Stream.of(
- // General Time zone tests
- Arguments.of("z yyyy", "GMT 2010", Locale.UK, true), // no
offset specified, but this is allowed as a
- //
TimeZone name
- Arguments.of("z yyyy", "GMT-123 2010", Locale.UK, false),
- Arguments.of("z yyyy", "GMT-1234 2010", Locale.UK, false),
- Arguments.of("z yyyy", "GMT-12:34 2010", Locale.UK, true),
- Arguments.of("z yyyy", "GMT-1:23 2010", Locale.UK, true),
- // RFC 822 tests
- Arguments.of("z yyyy", "-1234 2010", Locale.UK, true),
- Arguments.of("z yyyy", "-12:34 2010", Locale.UK, false),
- Arguments.of("z yyyy", "-123 2010", Locale.UK, false),
- // year tests
- Arguments.of("MM/dd/yyyy", "01/11/12", Locale.UK, true),
- Arguments.of("MM/dd/yy", "01/11/12", Locale.UK, true),
-
- // LANG-1089
- Arguments.of("HH", "00", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "00", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "00", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "00", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "01", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "01", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "01", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "01", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "11", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "11", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "11", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "11", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "12", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "12", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "12", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "12", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "13", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "13", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "13", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "13", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "23", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "23", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "23", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "23", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "24", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "24", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "24", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "24", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "25", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "25", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "25", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "25", Locale.UK, true), // Hour in day
(1-24), i.e. midnight is 24, not 0
-
- Arguments.of("HH", "48", Locale.UK, true), // Hour in day
(0-23)
- Arguments.of("KK", "48", Locale.UK, true), // Hour in am/pm
(0-11)
- Arguments.of("hh", "48", Locale.UK, true), // Hour in am/pm
(1-12), i.e. midday/midnight is 12, not 0
- Arguments.of("kk", "48", Locale.UK, true) // Hour in day
(1-24), i.e. midnight is 24, not 0
- );
- }
-
- private final TimeZone timeZone = TimeZone.getDefault();
-
-
- private void checkParse(final String formattedDate, String format, String
input, Locale locale, boolean valid) {
- final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
- sdf.setTimeZone(timeZone);
- final DateParser fdf = new FastDateParser(format, timeZone, locale);
- Date expectedTime=null;
- Class<?> sdfE = null;
- try {
- expectedTime = sdf.parse(formattedDate);
- if (!valid) {
- // Error in test data
- throw new RuntimeException("Test data error: expected SDF
parse to fail, but got " + expectedTime);
- }
- } catch (final ParseException e) {
- if (valid) {
- // Error in test data
- throw new RuntimeException("Test data error: expected SDF
parse to succeed, but got " + e);
- }
- sdfE = e.getClass();
- }
- Date actualTime = null;
- Class<?> fdfE = null;
- try {
- actualTime = fdf.parse(formattedDate);
- if (!valid) {
- // failure in test
- fail("Expected FDP parse to fail, but got " + actualTime);
- }
- } catch (final ParseException e) {
- if (valid) {
- // failure in test
- fail("Expected FDP parse to succeed, but got " + e);
- }
- fdfE = e.getClass();
- }
- if (valid) {
- assertEquals(expectedTime, actualTime, locale.toString() + " " +
formattedDate + "\n");
- } else {
- assertEquals(sdfE, fdfE, locale.toString() + " " + formattedDate +
" expected same Exception ");
- }
- }
-
- private void checkParsePosition(final String formattedDate, String format,
String input, Locale locale,
- boolean valid) {
- final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
- sdf.setTimeZone(timeZone);
- final DateParser fdf = new FastDateParser(format, timeZone, locale);
-
- final ParsePosition sdfP = new ParsePosition(0);
- final Date expectedTime = sdf.parse(formattedDate, sdfP);
- final int sdferrorIndex = sdfP.getErrorIndex();
- if (valid) {
- assertEquals(-1, sdferrorIndex, "Expected SDF error index -1 ");
- final int endIndex = sdfP.getIndex();
- final int length = formattedDate.length();
- if (endIndex != length) {
- // Error in test data
- throw new RuntimeException("Test data error: expected SDF
parse to consume entire string; endindex " + endIndex + " != " + length);
- }
- } else {
- final int errorIndex = sdfP.getErrorIndex();
- if (errorIndex == -1) {
- throw new RuntimeException("Test data error: expected SDF
parse to fail, but got " + expectedTime);
- }
- }
-
- final ParsePosition fdfP = new ParsePosition(0);
- final Date actualTime = fdf.parse(formattedDate, fdfP);
- final int fdferrorIndex = fdfP.getErrorIndex();
- if (valid) {
- assertEquals(-1, fdferrorIndex, "Expected FDF error index -1 ");
- final int endIndex = fdfP.getIndex();
- final int length = formattedDate.length();
- assertEquals(length, endIndex, "Expected FDF to parse full string
" + fdfP);
- assertEquals(expectedTime, actualTime, locale.toString() + " " +
formattedDate + "\n");
- } else {
- assertNotEquals(-1, fdferrorIndex, "Test data error: expected FDF
parse to fail, but got " + actualTime);
- assertTrue(sdferrorIndex - fdferrorIndex <= 4,
- "FDF error index (" + fdferrorIndex + ") should
approxiamate SDF index (" + sdferrorIndex + ")");
- }
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testLowerCase(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParse(input.toLowerCase(locale), format, input, locale, valid);
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testLowerCasePP(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParsePosition(input.toLowerCase(locale), format, input, locale,
valid);
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testOriginal(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParse(input, format, input, locale, valid);
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testOriginalPP(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParsePosition(input, format, input, locale, valid);
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testUpperCase(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParse(input.toUpperCase(locale), format, input, locale, valid);
- }
-
- @ParameterizedTest
- @MethodSource("data")
- public void testUpperCasePP(String format, String input, Locale locale,
boolean valid) throws Exception {
- checkParsePosition(input.toUpperCase(locale), format, input, locale,
valid);
- }
-}
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_MoreOrLessTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_MoreOrLessTest.java
deleted file mode 100644
index d6d96e587c..0000000000
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_MoreOrLessTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.util.datetime;
-
-import java.text.ParsePosition;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-/**
- * Copied from Apache Commons Lang 3 on 2016-11-16.
- */
-public class FastDateParser_MoreOrLessTest {
-
- private static final TimeZone NEW_YORK =
TimeZone.getTimeZone("America/New_York");
-
- @Test
- public void testInputHasLessCharacters() {
- final FastDateParser parser = new FastDateParser("MM/dd/yyy",
TimeZone.getDefault(), Locale.getDefault());
- final ParsePosition parsePosition = new ParsePosition(0);
- assertNull(parser.parse("03/23", parsePosition));
- assertEquals(5, parsePosition.getErrorIndex());
- }
-
- @Test
- public void testInputHasMoreCharacters() {
- final FastDateParser parser = new FastDateParser("MM/dd",
TimeZone.getDefault(), Locale.getDefault());
- final ParsePosition parsePosition = new ParsePosition(0);
- final Date date = parser.parse("3/23/61", parsePosition);
- assertEquals(4, parsePosition.getIndex());
-
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- assertEquals(2, calendar.get(Calendar.MONTH));
- assertEquals(23, calendar.get(Calendar.DATE));
- }
-
- @Test
- public void testInputHasPrecedingCharacters() {
- final FastDateParser parser = new FastDateParser("MM/dd",
TimeZone.getDefault(), Locale.getDefault());
- final ParsePosition parsePosition = new ParsePosition(0);
- final Date date = parser.parse("A 3/23/61", parsePosition);
- assertNull(date);
- assertEquals(0, parsePosition.getIndex());
- assertEquals(0, parsePosition.getErrorIndex());
- }
-
- @Test
- public void testInputHasWhitespace() {
- final FastDateParser parser = new FastDateParser("M/d/y",
TimeZone.getDefault(), Locale.getDefault());
- //SimpleDateFormat parser = new SimpleDateFormat("M/d/y");
- final ParsePosition parsePosition = new ParsePosition(0);
- final Date date = parser.parse(" 3/ 23/ 1961", parsePosition);
- assertEquals(12, parsePosition.getIndex());
-
- final Calendar calendar = Calendar.getInstance();
- calendar.setTime(date);
- assertEquals(1961, calendar.get(Calendar.YEAR));
- assertEquals(2, calendar.get(Calendar.MONTH));
- assertEquals(23, calendar.get(Calendar.DATE));
- }
-
- @Test
- public void testInputHasWrongCharacters() {
- final FastDateParser parser = new FastDateParser("MM-dd-yyy",
TimeZone.getDefault(), Locale.getDefault());
- final ParsePosition parsePosition = new ParsePosition(0);
- assertNull(parser.parse("03/23/1961", parsePosition));
- assertEquals(2, parsePosition.getErrorIndex());
- }
-
- @Test
- public void testInputHasWrongDay() {
- final FastDateParser parser = new FastDateParser("EEEE, MM/dd/yyy",
NEW_YORK, Locale.US);
- final String input = "Thursday, 03/23/61";
- final ParsePosition parsePosition = new ParsePosition(0);
- assertNotNull(parser.parse(input, parsePosition));
- assertEquals(input.length(), parsePosition.getIndex());
-
- parsePosition.setIndex(0);
- assertNull(parser.parse("Thorsday, 03/23/61", parsePosition));
- assertEquals(0, parsePosition.getErrorIndex());
- }
-
- @Test
- public void testInputHasWrongTimeZone() {
- final FastDateParser parser = new FastDateParser("mm:ss z", NEW_YORK,
Locale.US);
-
- final String input = "11:23 Pacific Standard Time";
- final ParsePosition parsePosition = new ParsePosition(0);
- assertNotNull(parser.parse(input, parsePosition));
- assertEquals(input.length(), parsePosition.getIndex());
-
- parsePosition.setIndex(0);
- assertNull(parser.parse("11:23 Pacific Standard ", parsePosition));
- assertEquals(6, parsePosition.getErrorIndex());
- }
-}
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_TimeZoneStrategyTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_TimeZoneStrategyTest.java
deleted file mode 100644
index 789d2cb27c..0000000000
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/datetime/FastDateParser_TimeZoneStrategyTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.util.datetime;
-
-import java.text.DateFormatSymbols;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * Copied from Apache Commons Lang 3 on 2016-11-16.
- */
-public class FastDateParser_TimeZoneStrategyTest {
-
- @Test
- public void testLang1219() throws ParseException {
- final FastDateParser parser = new FastDateParser("dd.MM.yyyy HH:mm:ss
z", TimeZone.getDefault(), Locale.GERMAN);
-
- final Date summer = parser.parse("26.10.2014 02:00:00 MESZ");
- final Date standard = parser.parse("26.10.2014 02:00:00 MEZ");
- assertNotEquals(summer.getTime(), standard.getTime());
- }
-
- @Test
- public void testTimeZoneStrategyPattern() {
- for(final Locale locale : Locale.getAvailableLocales()) {
- final FastDateParser parser = new FastDateParser("z",
TimeZone.getDefault(), locale);
- final String[][] zones =
DateFormatSymbols.getInstance(locale).getZoneStrings();
- for(final String[] zone : zones) {
- for(int t = 1; t<zone.length; ++t) {
- final String tzDisplay = zone[t];
- if (tzDisplay == null) {
- break;
- }
- try {
- parser.parse(tzDisplay);
- }
- catch(final Exception ex) {
- fail("'" + tzDisplay + "'"
- + " Locale: '" + locale.getDisplayName() + "'"
- + " TimeZone: " + zone[0]
- + " offset: " + t
- + " defaultLocale: " + Locale.getDefault()
- + " defaultTimeZone: " +
TimeZone.getDefault().getDisplayName()
- );
- }
- }
- }
- }
- }
-}