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.common;
|
11
|
|
12
|
import java.util.regex.Pattern;
|
13
|
|
14
|
import org.apache.log4j.Level;
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.After;
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
/**
|
22
|
* @author a.mueller
|
23
|
* @since 22.01.2008
|
24
|
*
|
25
|
*/
|
26
|
public class CdmUtilsTest {
|
27
|
private static final Logger logger = Logger.getLogger(CdmUtilsTest.class);
|
28
|
|
29
|
|
30
|
@Before
|
31
|
public void setUp() throws Exception {
|
32
|
}
|
33
|
|
34
|
@After
|
35
|
public void tearDown() throws Exception {
|
36
|
}
|
37
|
|
38
|
/************************** TESTS ****************************************/
|
39
|
|
40
|
@Test
|
41
|
public void testFindLibrary() {
|
42
|
if (logger.isEnabledFor(Level.DEBUG)) {logger.debug(CdmUtils.findLibrary(CdmUtils.class));}
|
43
|
|
44
|
String library = CdmUtils.findLibrary(CdmUtils.class);
|
45
|
String endOfLibrary = "target/classes/eu/etaxonomy/cdm/common/CdmUtils.class";
|
46
|
String libraryContains = "/cdmlib-commons/";
|
47
|
|
48
|
Assert.assertTrue(library.endsWith(endOfLibrary));
|
49
|
Assert.assertTrue(library.contains(libraryContains));
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* This is a default test for fast running any simple test. It can be overriden and ignored whenever needed.
|
54
|
*/
|
55
|
@Test
|
56
|
public void testAny(){
|
57
|
String str = "Noms vernaculaires:";
|
58
|
if (! str.matches("Nom(s)? vernaculaire(s)?\\:")){
|
59
|
System.out.println("NO");
|
60
|
}
|
61
|
}
|
62
|
|
63
|
@Test
|
64
|
public void testEqualsIgnoreWS(){
|
65
|
String str1 = null;
|
66
|
String str2 = null;
|
67
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
68
|
|
69
|
str2 = "Any ";
|
70
|
Assert.assertFalse(CdmUtils.equalsIgnoreWS(str1, str2));
|
71
|
|
72
|
str1 = "Any ";
|
73
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
74
|
|
75
|
str1 = "An y eer";
|
76
|
str2 = "A nye er";
|
77
|
Assert.assertTrue(CdmUtils.equalsIgnoreWS(str1, str2));
|
78
|
|
79
|
str1 = "An y eer";
|
80
|
str2 = "A nyfffe er";
|
81
|
Assert.assertFalse(CdmUtils.equalsIgnoreWS(str1, str2));
|
82
|
|
83
|
}
|
84
|
|
85
|
@Test
|
86
|
public void testquoteRegExWithWildcard(){
|
87
|
String regExBase = ".(*$[ms^";
|
88
|
String regEx = CdmUtils.quoteRegExWithWildcard(regExBase);
|
89
|
Assert.assertEquals("\\Q.(\\E.*\\Q$[ms^\\E", regEx);
|
90
|
boolean matches = ".(*$[ms^".matches(regEx);
|
91
|
Assert.assertTrue(matches);
|
92
|
matches = ".(aaaaaa$[ms^".matches(regEx);
|
93
|
Assert.assertTrue(matches);
|
94
|
matches = "b(aaaaaa$[ms^".matches(regEx);
|
95
|
Assert.assertFalse(matches);
|
96
|
|
97
|
regEx = CdmUtils.quoteRegExWithWildcard("*abc*");
|
98
|
Assert.assertEquals(".*\\Qabc\\E.*", regEx);
|
99
|
Assert.assertTrue("abc".matches(regEx));
|
100
|
Assert.assertTrue("a80/(--e*wabc?äe".matches(regEx));
|
101
|
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* This test can be used for functional testing of any task but should
|
106
|
* never be committed when failing.
|
107
|
*/
|
108
|
@Test
|
109
|
public void testSomething(){
|
110
|
String str = ".(*$[ms^";
|
111
|
String patQuote = Pattern.quote("str");
|
112
|
// System.out.println(patQuote);
|
113
|
// String matchQuote = Matcher.quoteReplacement(str);
|
114
|
// System.out.println(matchQuote);
|
115
|
// System.out.println(CdmUtils.quoteRegExWithWildcard(str));
|
116
|
}
|
117
|
|
118
|
|
119
|
|
120
|
|
121
|
|
122
|
}
|