Project

General

Profile

Download (4.4 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.cdm.strategy.parser;
11

    
12
import static org.junit.Assert.*;
13

    
14
import java.util.List;
15

    
16
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
17
import org.junit.After;
18
import org.junit.AfterClass;
19
import org.junit.Before;
20
import org.junit.BeforeClass;
21
import org.junit.Test;
22

    
23
/**
24
 * @author a.mueller
25
 * @since 04.09.2009
26
 * @version 1.0
27
 */
28
public class ParserProblemTest {
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = LogManager.getLogger(ParserProblemTest.class);
31

    
32
	/**
33
	 * @throws java.lang.Exception
34
	 */
35
	@BeforeClass
36
	public static void setUpBeforeClass() throws Exception {
37
	}
38

    
39
	/**
40
	 * @throws java.lang.Exception
41
	 */
42
	@AfterClass
43
	public static void tearDownAfterClass() throws Exception {
44
	}
45

    
46
	/**
47
	 * @throws java.lang.Exception
48
	 */
49
	@Before
50
	public void setUp() throws Exception {
51
	}
52

    
53
	/**
54
	 * @throws java.lang.Exception
55
	 */
56
	@After
57
	public void tearDown() throws Exception {
58
	}
59

    
60
/****** TESTS ******************************************	
61
	
62

    
63
	/**
64
	 * Test method for {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem#warningList(int)}.
65
	 */
66
	@Test
67
	public void testWarningList() {
68
		List<ParserProblem> list = ParserProblem.warningList(5);
69
		assertEquals("list must include 2 warnings", 2, list.size());
70
		assertTrue("Warning list should include warning 0", list.contains(ParserProblem.CheckRank));
71
		assertTrue("Warning list should include warning 2", list.contains(ParserProblem.NameReferenceSeparation));
72
	}
73
	
74
	@Test
75
	public void testAddProblem(){
76
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
77
		int expected = (int)Math.pow(2, ParserProblem.NameReferenceSeparation.ordinal()) ;
78
		assertEquals("Unexpected value for addWarning", expected,warning);
79
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
80
		expected = expected + (int)Math.pow(2, ParserProblem.CheckDetailOrYear.ordinal()) ;
81
		assertEquals("Unexpected value for addWarning", expected,warning);
82
	}
83
	
84
	@Test
85
	public void testRemoveProblem(){
86
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
87
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckRank);
88
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
89
		assertEquals("Number of problems must be 3", 3, ParserProblem.warningList(warning).size());
90
		assertTrue("Check Rank must be a problem", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
91
		
92
		warning = ParserProblem.removeProblem(warning, ParserProblem.CheckRank);
93
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
94
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
95
		
96
		warning = ParserProblem.removeProblem(warning, ParserProblem.CheckRank);
97
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
98
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
99

    
100
		warning = ParserProblem.removeProblem(warning, null);
101
		assertEquals("Number of problems must be 2", 2, ParserProblem.warningList(warning).size());
102
		assertFalse("Check Rank must not be a problem anymore", ParserProblem.warningList(warning).contains(ParserProblem.CheckRank));
103
	}
104
	
105
	@Test
106
	public void testAddProblems(){
107
		assertEquals("Unexpected value for addWarning", 23, ParserProblem.addProblems(21, 6));
108
	}
109
	
110
	@Test
111
	public void testIsError() {
112
		assertTrue("NameReferenceSeparation must be error", ParserProblem.NameReferenceSeparation.isError());
113
	}
114
	
115
	@Test
116
	public void testIsWarning() {
117
		assertTrue("CheckDetail must be warning", ParserProblem.CheckDetailOrYear.isWarning());
118
	}
119
	
120
	@Test
121
	public void testHasError() {
122
		int warning = ParserProblem.addProblem(0, ParserProblem.NameReferenceSeparation);
123
		warning = ParserProblem.addProblem(warning, ParserProblem.CheckDetailOrYear);
124
		assertTrue("warning list with NameReferenceSeparation must have error", ParserProblem.hasError(warning));
125
	}
126

    
127
}
(5-5/6)