1   /*
2    * This file is part of AceLogger.
3    * 
4    * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU
5    * Lesser General Public License as published by the Free Software Foundation, either version 3 of
6    * the License, or (at your option) any later version.
7    * 
8    * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9    * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10   * Lesser General Public License for more details.
11   * 
12   * You should have received a copy of the GNU Lesser General Public License along with AceLogger.
13   * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
14   */
15  package net.sourceforge.acelogger.formatter.test;
16  
17  import org.testng.annotations.BeforeMethod;
18  import org.testng.annotations.DataProvider;
19  import org.testng.annotations.Test;
20  
21  import net.sourceforge.acelogger.LogEvent;
22  import net.sourceforge.acelogger.formatter.MessageOnlyFormatter;
23  import net.sourceforge.acelogger.level.LogLevel;
24  import net.sourceforge.acelogger.test.DataProviderHelper;
25  
26  import static org.testng.Assert.assertEquals;
27  
28  /**
29   * TODO: Create Doc.
30   * 
31   * @author Zardi (https://sourceforge.net/users/daniel_zardi)
32   * @version 1.0.0
33   * @since 1.0.0
34   */
35  @Test
36  public class MessageOnlyFormatterTest {
37  
38  	private MessageOnlyFormatter formatter;
39  
40  	@BeforeMethod
41  	public void setUp() {
42  		formatter = null;
43  	}
44  
45  	@DataProvider(name = "formatLogCallDataProvider")
46  	public Object[][] formatLogCallDataProvider() {
47  		return DataProviderHelper.loadData();
48  	}
49  
50  	@Test(dataProvider = "formatLogCallDataProvider")
51  	public void testFormatLogCall(LogEvent call, String expectedMessage) {
52  		formatter = new MessageOnlyFormatter("MessageOnlyFormatterTest.testFormatLogCall");
53  		String message = formatter.formatLogCall(call);
54  		assertEquals(message, expectedMessage);
55  	}
56  
57  	@Test
58  	public void testGetIdentifier() {
59  		formatter = new MessageOnlyFormatter("MessageOnlyFormatterTest.testGetIdentifier");
60  		assertEquals(formatter.getIdentifier(), "MessageOnlyFormatterTest.testGetIdentifier");
61  	}
62  
63  	@Test
64  	public void testInvalidPattern() {
65  		formatter = new MessageOnlyFormatter("MessageOnlyFormatterTest.testInvalidPattern");
66  		String message = formatter.formatLogCall(new LogEvent("A malformed message {{0}",
67  				LogLevel.ERROR, "pattern"));
68  		assertEquals(message, "");
69  	}
70  
71  }