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.filter.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.level.LogLevel;
22  import net.sourceforge.acelogger.level.filter.RangedLevelFilter;
23  import net.sourceforge.acelogger.test.DataProviderHelper;
24  
25  import static org.testng.Assert.assertEquals;
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 RangedLevelFilterTest {
37  
38  	private RangedLevelFilter rangedFilter;
39  
40  	@BeforeMethod
41  	public void setupTest() {
42  		rangedFilter = null;
43  	}
44  
45  	@DataProvider
46  	public Object[][] identifierConstructorDataProvider() {
47  		return DataProviderHelper.loadData();
48  	}
49  
50  	@Test(dataProvider = "identifierConstructorDataProvider")
51  	public void testIdentifierConstructor(LogLevel level, boolean shouldPass) {
52  		rangedFilter = new RangedLevelFilter("RangedLevelFilterTest.testIdentifierConstructor");
53  		assertEquals(rangedFilter.isSuitable(level), shouldPass);
54  	}
55  
56  	@DataProvider
57  	public Object[][] levelConstructorDataProvider() {
58  		return DataProviderHelper.loadData();
59  	}
60  
61  	@Test(dataProvider = "levelConstructorDataProvider")
62  	public void testLevelConstructor(LogLevel minimumLevel, LogLevel maximumLevel, LogLevel level,
63  			boolean shouldPass) {
64  		rangedFilter = new RangedLevelFilter("RangedLevelFilterTest.testLevelConstructor",
65  				minimumLevel, maximumLevel);
66  		assertEquals(rangedFilter.isSuitable(level), shouldPass);
67  	}
68  
69  	@DataProvider
70  	public Object[][] validRangeDataProvider() {
71  		return DataProviderHelper.loadData();
72  	}
73  
74  	@Test(dataProvider = "validRangeDataProvider")
75  	public void testConstructorValidRange(LogLevel minimumLevel, LogLevel maximumLevel) {
76  		rangedFilter = new RangedLevelFilter("RangedLevelFilterTest.testConstructorValidRange",
77  				minimumLevel, maximumLevel);
78  		final boolean succeded = rangedFilter.getMinimumLevel().equals(minimumLevel)
79  				&& rangedFilter.getMaximumLevel().equals(maximumLevel);
80  		assertTrue(succeded);
81  	}
82  
83  	@Test(dataProvider = "validRangeDataProvider")
84  	public void testSetValidRange(LogLevel minimumLevel, LogLevel maximumLevel) {
85  		rangedFilter = new RangedLevelFilter("RangedLevelFilterTest.testSetValidRange");
86  		rangedFilter.setLevelRange(minimumLevel, maximumLevel);
87  		final boolean succeded = rangedFilter.getMinimumLevel().equals(minimumLevel)
88  				&& rangedFilter.getMaximumLevel().equals(maximumLevel);
89  		assertTrue(succeded);
90  	}
91  
92  	/**
93  	 * Tests the {@link RangedLevelFilter} identifier.
94  	 */
95  	@Test
96  	public void testGetIdentifier() {
97  		rangedFilter = new RangedLevelFilter("RangedLevelFilterTest.testGetIdentifier");
98  		assertEquals(rangedFilter.getIdentifier(), "RangedLevelFilterTest.testGetIdentifier");
99  	}
100 
101 }