1
1
package org .scm4j .commons .regexconfig ;
2
2
3
- import static org .junit .Assert .assertEquals ;
4
- import static org .junit .Assert .assertTrue ;
5
- import static org .junit .Assert .fail ;
6
-
7
- import java .io .IOException ;
8
-
9
3
import org .junit .Before ;
10
4
import org .junit .Test ;
11
- import org .scm4j .commons .EConfig ;
5
+
6
+ import static org .junit .Assert .*;
12
7
13
8
public class RegexConfigTest {
14
9
@@ -17,16 +12,19 @@ public class RegexConfigTest {
17
12
private String mapping = this .getClass ().getResource ("mapping.yml" ).toString ();
18
13
private String seq = this .getClass ().getResource ("sequence.yml" ).toString ();
19
14
private String empty = this .getClass ().getResource ("empty.yml" ).toString ();
20
- private String wrongContent = this .getClass ().getResource ("wrong-content.yml" ).toString ();
21
15
private String seqBOM = this .getClass ().getResource ("sequence-bom.yml" ).toString ();
16
+ private String nonOmap = this .getClass ().getResource ("non-omap.yml" ).toString ();
17
+ private String wrongContent = this .getClass ().getResource ("wrong-content.yml" ).toString ();
18
+ private String emptyContent = this .getClass ().getResource ("empty-content.yml" ).toString ();
19
+ private String wrongContentInternal = this .getClass ().getResource ("wrong-internal-content.yml" ).toString ();
22
20
23
21
@ Before
24
22
public void setUp () {
25
23
config = new RegexConfig ();
26
24
}
27
25
28
26
@ Test
29
- public void testGetPropByName () throws IOException {
27
+ public void testGetPropByName () {
30
28
config .loadFromYamlUrls (seqOmap , seqBOM + ";" + seq + ";" + mapping );
31
29
assertEquals ("value1and2" , config .getPropByName ("node1" , "prop1and2" , null ));
32
30
assertEquals ("value1and2" , config .getPropByName ("node2" , "prop1and2" , null ));
@@ -42,30 +40,64 @@ public void testGetPropByName() throws IOException {
42
40
}
43
41
44
42
@ Test
45
- public void testGetPlaceholderedStringByName () throws IOException {
43
+ public void testGetPlaceholderedStringByName () {
46
44
config .loadFromYamlUrls (seqOmap , seqBOM + ";" + seq );
47
45
assertEquals ("value4_placeholder" , config .getPlaceholderedStringByName ("node4placeholder" , "prop4" , null ));
48
46
assertEquals ("unexisting_node" , config .getPlaceholderedStringByName ("unexisting_node" , "placeholderedProp" , null ));
49
47
}
50
48
51
49
@ Test
52
- public void testEmptyConfig () throws IOException {
50
+ public void testEmptyConfig () {
53
51
config .loadFromYamlUrls (empty );
54
52
assertTrue (config .isEmpty ());
55
53
}
56
54
57
55
@ Test
58
- public void testEmptyUrls () throws IOException {
56
+ public void testEmptyContent () {
57
+ config .loadFromYamlUrls (emptyContent );
58
+ assertTrue (config .isEmpty ());
59
+ }
60
+
61
+ @ Test
62
+ public void testEmptyUrls () {
59
63
config .loadFromYamlUrls ("" );
60
64
assertTrue (config .isEmpty ());
61
65
}
62
66
63
67
@ Test
64
- public void testWrongContent () throws IOException {
68
+ public void testNonSequenceContent () {
69
+ try {
70
+ config .loadFromYamlUrls (nonOmap );
71
+ fail ();
72
+ } catch (EConfigWrongFormat e ) {
73
+ }
74
+ }
75
+
76
+ @ Test
77
+ public void testConfigReadFailed () {
78
+ try {
79
+ config .loadFromYamlUrls ("wrong location" );
80
+ fail ();
81
+ } catch (RuntimeException e ) {
82
+ }
83
+ }
84
+
85
+ @ Test
86
+ public void testWrongContent () {
65
87
try {
66
88
config .loadFromYamlUrls (wrongContent );
67
89
fail ();
68
- } catch (EConfig e ) {
90
+ } catch (EConfigParseFailed e ) {
91
+ }
92
+ }
93
+
94
+ @ Test
95
+ public void testWrongInternalContent () {
96
+ config .loadFromYamlUrls (wrongContentInternal );
97
+ try {
98
+ config .getPropByName ("node1" , "prop1" , "" );
99
+ fail ();
100
+ } catch (EConfigWrongFormat e ) {
69
101
}
70
102
}
71
103
}
0 commit comments