Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.logging.log4j.core.time.Instant;
import org.apache.logging.log4j.core.time.MutableInstant;
import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.internal.instant.InstantPatternFormatter;
import org.apache.logging.log4j.util.Strings;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -67,9 +68,15 @@ public long getTimeMillis() {
private static final String[] ISO8601_FORMAT_OPTIONS = {ISO8601};

private final boolean threadLocalsEnabled;
private final boolean legacyFormatterEnabled;

DatePatternConverterTestBase(final boolean threadLocalsEnabled) {
this(threadLocalsEnabled, false);
}

DatePatternConverterTestBase(final boolean threadLocalsEnabled, final boolean legacyFormatterEnabled) {
this.threadLocalsEnabled = threadLocalsEnabled;
this.legacyFormatterEnabled = legacyFormatterEnabled;
}

private static Date date(final int year, final int month, final int date) {
Expand All @@ -84,6 +91,11 @@ void testThreadLocalsConstant() {
assertEquals(Constants.ENABLE_THREADLOCALS, threadLocalsEnabled);
}

@Test
void testInstantFormatterConstant() {
assertEquals(InstantPatternFormatter.LEGACY_FORMATTERS_ENABLED, legacyFormatterEnabled);
}

@Test
void testFormatDateStringBuilderDefaultPattern() {
assertDatePattern(null, date(2001, 1, 1), "2001-02-01 14:15:16,123");
Expand Down Expand Up @@ -163,6 +175,7 @@ void testFormatAmericanPatterns() {
assertDatePattern("dd/MM/yyyy HH:mm:ss.SSSSSS", date, "11/03/2011 14:15:16.123000");
assertDatePattern("dd/MM/yy HH:mm:ss.SSS", date, "11/03/11 14:15:16.123");
assertDatePattern("dd/MM/yy HH:mm:ss.SSSSSS", date, "11/03/11 14:15:16.123000");
assertDatePattern("EEE, dd MMM yyyy HH:mm:ss zzz", date, "Fri, 11 Mar 2011 14:15:16 PST");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test case, much appreciated! 💯

}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.pattern;

import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.apache.logging.log4j.test.junit.UsingTestProperties;

@SetTestProperty.SetTestProperties(value = {
@SetTestProperty(key = "log4j2.enable.threadlocals", value = "false"),
@SetTestProperty(key = "log4j2.instantFormatter", value = "legacy")
})
@UsingTestProperties
class DatePatternConverterWithLegacyInstantFormatterTest extends DatePatternConverterTestBase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't think we want to introduce more tests for the legacy formatter, since it is deprecated and will not change any more. @vy, what do you think?


DatePatternConverterWithLegacyInstantFormatterTest() {
super(false, true);
}
}
Loading