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.factory.test;
16  
17  import java.util.List;
18  
19  import org.testng.annotations.DataProvider;
20  import org.testng.annotations.Test;
21  
22  import net.sourceforge.acelogger.factory.FormatterFactory;
23  import net.sourceforge.acelogger.formatter.Formatter;
24  import net.sourceforge.acelogger.test.DataProviderHelper;
25  
26  import static org.testng.Assert.assertTrue;
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 FormatterFactoryTest {
37  
38  	@DataProvider(name = "getRegisteredFormattersDataProvider")
39  	public Object[][] getRegisteredFormattersDataProvider() {
40  		return DataProviderHelper.loadData();
41  	}
42  
43  	@Test(dataProvider = "getRegisteredFormattersDataProvider")
44  	public void testGetRegisteredFormatters(List<Formatter> formatters) {
45  		List<Formatter> expected = FormatterFactory.getRegisteredFormatters();
46  		expected.addAll(formatters);
47  		for (Formatter currentFormatter : formatters) {
48  			FormatterFactory.registerFormatter(currentFormatter);
49  		}
50  		List<Formatter> registered = FormatterFactory.getRegisteredFormatters();
51  		assertTrue(registered.containsAll(expected) && registered.size() == expected.size());
52  	}
53  
54  	@Test
55  	public void testSetNullFormatter() {
56  		List<Formatter> previouslyRegistered = FormatterFactory.getRegisteredFormatters();
57  		Formatter register = FormatterFactory.registerFormatter(null);
58  		List<Formatter> currentlyRegistered = FormatterFactory.getRegisteredFormatters();
59  		assertTrue(register.equals(FormatterFactory.getDefaultFormatter())
60  				&& currentlyRegistered.containsAll(previouslyRegistered)
61  				&& currentlyRegistered.size() == previouslyRegistered.size());
62  	}
63  
64  }