1
2
3
4
5
6
7
8
9
10
11
12
13
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
30
31
32
33
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 }