/*
 * 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.message;

import org.junit.jupiter.api.Test;

import java.util.Locale;
import java.util.ResourceBundle;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Tests {@link LocalizedMessageFactory}.
 */
public class LocalizedMessageFactoryTest {

    @Test
    public void testMessageMarkersDataNo() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("msg1");
        assertEquals("This is test number {0} with string argument {1}.", message.getFormattedMessage());
    }

    @Test
    public void testMessageMarkersNoDataYes() {
        // Logs the following to the console sadly:
        //
        // ERROR StatusLogger Unable to format msg: C:/Program%20Files/Some%20Company/Some%20Product%20Name/
        // java.util.UnknownFormatConversionException: Conversion = 'F'
        //  at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
        //  at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
        //  at java.util.Formatter.parse(Formatter.java:2560)
        //  at java.util.Formatter.format(Formatter.java:2501)
        //  at java.util.Formatter.format(Formatter.java:2455)
        //  at java.lang.String.format(String.java:2981)
        //  at org.apache.logging.log4j.message.StringFormattedMessage.formatMessage(StringFormattedMessage.java:116)
        //  at org.apache.logging.log4j.message.StringFormattedMessage.getFormattedMessage(StringFormattedMessage.java:88)
        //  at org.apache.logging.log4j.message.FormattedMessage.getFormattedMessage(FormattedMessage.java:178)
        //  at org.apache.logging.log4j.message.LocalizedMessage.getFormattedMessage(LocalizedMessage.java:196)
        //  at org.apache.logging.log4j.message.LocalizedMessageFactoryTest.testNoMatchPercentInMessage(LocalizedMessageFactoryTest.java:60)
        //
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("msg1", 1, "two");
        assertEquals("This is test number 1 with string argument two.", message.getFormattedMessage());
    }

    @Test
    public void testNewMessage() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("hello_world");
        assertEquals("Hello world.", message.getFormattedMessage());
    }

    @Test
    public void testNoMatch() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("no match");
        assertEquals("no match", message.getFormattedMessage());
    }

    @Test
    public void testNoMatchPercentInMessage() {
        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle("MF", Locale.US));
        final Message message = localizedMessageFactory.newMessage("C:/Program%20Files/Some%20Company/Some%20Product%20Name/");
        assertEquals("C:/Program%20Files/Some%20Company/Some%20Product%20Name/", message.getFormattedMessage());
    }
}

@@ -1522,24 +1522,1085 @@
 DataYes() %7B%0A
+        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A        final Message message = localizedMessageFactory.newMessage(%22msg1%22, 1, %22two%22);%0A        assertEquals(%22This is test number 1 with string argument two.%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNewMessage() %7B%0A        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A        final Message message = localizedMessageFactory.newMessage(%22hello_world%22);%0A        assertEquals(%22Hello world.%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNoMatch() %7B%0A        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A        final Message message = localizedMessageFactory.newMessage(%22no match%22);%0A        assertEquals(%22no match%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNoMatchPercentInMessage() %7B%0A
         // L
@@ -3995,1069 +3995,8 @@
 ));%0A
-        final Message message = localizedMessageFactory.newMessage(%22msg1%22, 1, %22two%22);%0A        assertEquals(%22This is test number 1 with string argument two.%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNewMessage() %7B%0A        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A        final Message message = localizedMessageFactory.newMessage(%22hello_world%22);%0A        assertEquals(%22Hello world.%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNoMatch() %7B%0A        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A        final Message message = localizedMessageFactory.newMessage(%22no match%22);%0A        assertEquals(%22no match%22, message.getFormattedMessage());%0A    %7D%0A%0A    @Test%0A    public void testNoMatchPercentInMessage() %7B%0A        final LocalizedMessageFactory localizedMessageFactory = new LocalizedMessageFactory(ResourceBundle.getBundle(%22MF%22, Locale.US));%0A
     

Move comment.