/*
 * This file is part of the DITA Open Toolkit project hosted on
 * Sourceforge.net. See the accompanying license.txt file for
 * applicable licenses.
 */

/*
 * (c) Copyright IBM Corp. 2011 All Rights Reserved.
 */
package org.dita.dost.log;

import static org.junit.Assert.*;

import java.io.File;
import java.util.Properties;

import org.junit.Before;
import org.junit.Test;

public class MessageUtilsTest {

    private final File resourceDir = new File("test-stub", MessageUtilsTest.class.getSimpleName());

    @Before
    public void setUp() throws Exception {
        final File f = new File(resourceDir, "messages.xml");
        MessageUtils.loadMessages(f.getAbsolutePath());
    }

    @Test
    public void testLoadDefaultMessages() {
        MessageUtils.loadDefaultMessages();
    }

    @Test
    public void testLoadMessages() {
        final File f = new File(resourceDir, "messages.xml");
        MessageUtils.loadMessages(f.getAbsolutePath());
    }

    @Test
    public void testGetMessageString() {
        final MessageBean exp = new MessageBean();
        exp.setId("XXX123F");
        exp.setType("FATAL");
        exp.setReason("Fatal reason.");
        exp.setResponse("Fatal response.");
        assertEquals(exp.toString(), MessageUtils.getMessage("XXX123F").toString());
    }

    @Test
    public void testGetMessageStringProperties() {
        final Properties props = new Properties();
        props.put("%1", "foo");
        props.put("%2", "bar baz");
        final MessageBean exp = new MessageBean();
        exp.setId("XXX234E");
        exp.setType("ERROR");
        exp.setReason("Error foo reason bar baz.");
        exp.setResponse("Error foo response bar baz.");
        assertEquals(exp.toString(), MessageUtils.getMessage("XXX234E", props).toString());
    }

    @Test
    public void testGetMessageStringMissing() {
        final Properties props = new Properties();
        props.put("%1", "foo");
        final MessageBean exp = new MessageBean();
        exp.setId("XXX234E");
        exp.setType("ERROR");
        exp.setReason("Error foo reason %2.");
        exp.setResponse("Error foo response %2.");
        assertEquals(exp.toString(), MessageUtils.getMessage("XXX234E", props).toString());
    }

    @Test
    public void testGetMessageStringExtra() {
        final Properties props = new Properties();
        props.put("%1", "foo");
        props.put("%2", "bar baz");
        props.put("%3", "qux");
        final MessageBean exp = new MessageBean();
        exp.setId("XXX234E");
        exp.setType("ERROR");
        exp.setReason("Error foo reason bar baz.");
        exp.setResponse("Error foo response bar baz.");
        assertEquals(exp.toString(), MessageUtils.getMessage("XXX234E", props).toString());
    }

}

@@ -348,16 +348,50 @@
 t.Before
+Class;%0Aimport org.junit.AfterClass
 ;%0Aimport
@@ -453,16 +453,23 @@
 private 
+static 
 final Fi
@@ -560,16 +560,21 @@
  @Before
+Class
 %0A    pub
@@ -573,24 +573,31 @@
 %0A    public 
+static 
 void setUp()
@@ -2828,10 +2828,204 @@
 %0A    %7D%0A%0A
+    @AfterClass%0A    public static void tearDown() throws Exception %7B%0A        final File f = new File(%22resource/messages.xml%22);%0A        MessageUtils.loadMessages(f.getAbsolutePath());%0A    %7D%0A    %0A
 %7D%0A

Fix MessageUtils unit test clean-up - ID: 3346094