@@ -54,15 +54,15 @@ public class ConfigDefTest {
54
54
@ Test
55
55
public void testBasicTypes () {
56
56
ConfigDef def = new ConfigDef ().define ("a" , Type .INT , 5 , Range .between (0 , 14 ), Importance .HIGH , "docs" )
57
- .define ("b" , Type .LONG , Importance .HIGH , "docs" )
58
- .define ("c" , Type .STRING , "hello" , Importance .HIGH , "docs" )
59
- .define ("d" , Type .LIST , Importance .HIGH , "docs" )
60
- .define ("e" , Type .DOUBLE , Importance .HIGH , "docs" )
61
- .define ("f" , Type .CLASS , Importance .HIGH , "docs" )
62
- .define ("g" , Type .BOOLEAN , Importance .HIGH , "docs" )
63
- .define ("h" , Type .BOOLEAN , Importance .HIGH , "docs" )
64
- .define ("i" , Type .BOOLEAN , Importance .HIGH , "docs" )
65
- .define ("j" , Type .PASSWORD , Importance .HIGH , "docs" );
57
+ .define ("b" , Type .LONG , Importance .HIGH , "docs" )
58
+ .define ("c" , Type .STRING , "hello" , Importance .HIGH , "docs" )
59
+ .define ("d" , Type .LIST , Importance .HIGH , "docs" )
60
+ .define ("e" , Type .DOUBLE , Importance .HIGH , "docs" )
61
+ .define ("f" , Type .CLASS , Importance .HIGH , "docs" )
62
+ .define ("g" , Type .BOOLEAN , Importance .HIGH , "docs" )
63
+ .define ("h" , Type .BOOLEAN , Importance .HIGH , "docs" )
64
+ .define ("i" , Type .BOOLEAN , Importance .HIGH , "docs" )
65
+ .define ("j" , Type .PASSWORD , Importance .HIGH , "docs" );
66
66
67
67
Properties props = new Properties ();
68
68
props .put ("a" , "1 " );
@@ -116,7 +116,7 @@ public void testParsingEmptyDefaultValueForStringFieldShouldSucceed() {
116
116
@ Test
117
117
public void testDefinedTwice () {
118
118
assertThrows (ConfigException .class , () -> new ConfigDef ().define ("a" , Type .STRING ,
119
- Importance .HIGH , "docs" ).define ("a" , Type .INT , Importance .HIGH , "docs" ));
119
+ Importance .HIGH , "docs" ).define ("a" , Type .INT , Importance .HIGH , "docs" ));
120
120
}
121
121
122
122
@ Test
@@ -147,13 +147,13 @@ private void testBadInputs(Type type, Object... values) {
147
147
@ Test
148
148
public void testInvalidDefaultRange () {
149
149
assertThrows (ConfigException .class , () -> new ConfigDef ().define ("name" , Type .INT , -1 ,
150
- Range .between (0 , 10 ), Importance .HIGH , "docs" ));
150
+ Range .between (0 , 10 ), Importance .HIGH , "docs" ));
151
151
}
152
152
153
153
@ Test
154
154
public void testInvalidDefaultString () {
155
155
assertThrows (ConfigException .class , () -> new ConfigDef ().define ("name" , Type .STRING , "bad" ,
156
- ValidString .in ("valid" , "values" ), Importance .HIGH , "docs" ));
156
+ ValidString .in ("valid" , "values" ), Importance .HIGH , "docs" ));
157
157
}
158
158
159
159
@ Test
@@ -169,10 +169,11 @@ public void testValidators() {
169
169
testValidators (Type .STRING , ValidString .in ("good" , "values" , "default" ), "default" ,
170
170
new Object []{"good" , "values" , "default" }, new Object []{"bad" , "inputs" , "DEFAULT" , null });
171
171
testValidators (Type .STRING , CaseInsensitiveValidString .in ("good" , "values" , "default" ), "default" ,
172
- new Object []{"gOOd" , "VALUES" , "default" }, new Object []{"Bad" , "iNPUts" , null });
173
- testValidators (Type .LIST , ConfigDef .ValidList .in ("1" , "2" , "3" ), "1" , new Object []{"1" , "2" , "3" }, new Object []{"4" , "5" , "6" });
174
- testValidators (Type .STRING , new ConfigDef .NonNullValidator (), "a" , new Object []{"abb" }, new Object [] {null });
175
- testValidators (Type .STRING , ConfigDef .CompositeValidator .of (new ConfigDef .NonNullValidator (), ValidString .in ("a" , "b" )), "a" , new Object []{"a" , "b" }, new Object [] {null , -1 , "c" });
172
+ new Object []{"gOOd" , "VALUES" , "default" }, new Object []{"Bad" , "iNPUts" , null });
173
+ testValidators (Type .LIST , ConfigDef .ValidList .inWithEmptyCheck (true , "1" , "2" , "3" ), "1" , new Object []{"1" , "2" , "3" }, new Object []{"4" , "5" , "6" });
174
+ testValidators (Type .LIST , ConfigDef .ValidList .inWithEmptyCheck (false , "1" , "2" , "3" ), "1" , new Object []{"1" , "2" , "3" }, new Object []{"" });
175
+ testValidators (Type .STRING , new ConfigDef .NonNullValidator (), "a" , new Object []{"abb" }, new Object []{null });
176
+ testValidators (Type .STRING , ConfigDef .CompositeValidator .of (new ConfigDef .NonNullValidator (), ValidString .in ("a" , "b" )), "a" , new Object []{"a" , "b" }, new Object []{null , -1 , "c" });
176
177
testValidators (Type .STRING , new ConfigDef .NonEmptyStringWithoutControlChars (), "defaultname" ,
177
178
new Object []{"test" , "name" , "test/test" , "test\u1234 " , "\u1324 name\\ " , "/+%>&):??<&()?-" , "+1" , "\uD83D \uDE01 " , "\uF3B1 " , " test \n \r " , "\n hello \t " },
178
179
new Object []{"nontrailing\n notallowed" , "as\u0001 cii control char" , "tes\r t" , "test\b test" , "1\t 2" , "" });
@@ -203,7 +204,7 @@ public void testNullDefaultWithValidator() {
203
204
204
205
ConfigDef def = new ConfigDef ();
205
206
def .define (key , Type .STRING , ConfigDef .NO_DEFAULT_VALUE ,
206
- ValidString .in ("ONE" , "TWO" , "THREE" ), Importance .HIGH , "docs" );
207
+ ValidString .in ("ONE" , "TWO" , "THREE" ), Importance .HIGH , "docs" );
207
208
208
209
Properties props = new Properties ();
209
210
props .put (key , "ONE" );
@@ -215,17 +216,17 @@ public void testNullDefaultWithValidator() {
215
216
public void testGroupInference () {
216
217
List <String > expected1 = Arrays .asList ("group1" , "group2" );
217
218
ConfigDef def1 = new ConfigDef ()
218
- .define ("a" , Type .INT , Importance .HIGH , "docs" , "group1" , 1 , Width .SHORT , "a" )
219
- .define ("b" , Type .INT , Importance .HIGH , "docs" , "group2" , 1 , Width .SHORT , "b" )
220
- .define ("c" , Type .INT , Importance .HIGH , "docs" , "group1" , 2 , Width .SHORT , "c" );
219
+ .define ("a" , Type .INT , Importance .HIGH , "docs" , "group1" , 1 , Width .SHORT , "a" )
220
+ .define ("b" , Type .INT , Importance .HIGH , "docs" , "group2" , 1 , Width .SHORT , "b" )
221
+ .define ("c" , Type .INT , Importance .HIGH , "docs" , "group1" , 2 , Width .SHORT , "c" );
221
222
222
223
assertEquals (expected1 , def1 .groups ());
223
224
224
225
List <String > expected2 = Arrays .asList ("group2" , "group1" );
225
226
ConfigDef def2 = new ConfigDef ()
226
- .define ("a" , Type .INT , Importance .HIGH , "docs" , "group2" , 1 , Width .SHORT , "a" )
227
- .define ("b" , Type .INT , Importance .HIGH , "docs" , "group2" , 2 , Width .SHORT , "b" )
228
- .define ("c" , Type .INT , Importance .HIGH , "docs" , "group1" , 2 , Width .SHORT , "c" );
227
+ .define ("a" , Type .INT , Importance .HIGH , "docs" , "group2" , 1 , Width .SHORT , "a" )
228
+ .define ("b" , Type .INT , Importance .HIGH , "docs" , "group2" , 2 , Width .SHORT , "b" )
229
+ .define ("c" , Type .INT , Importance .HIGH , "docs" , "group1" , 2 , Width .SHORT , "c" );
229
230
230
231
assertEquals (expected2 , def2 .groups ());
231
232
}
@@ -251,10 +252,10 @@ public void testParseForValidate() {
251
252
expected .put ("d" , configD );
252
253
253
254
ConfigDef def = new ConfigDef ()
254
- .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" ), new IntegerRecommender (false ))
255
- .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
256
- .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ))
257
- .define ("d" , Type .INT , Importance .HIGH , "docs" , "group" , 4 , Width .SHORT , "d" , singletonList ("b" ), new IntegerRecommender (false ));
255
+ .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" ), new IntegerRecommender (false ))
256
+ .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
257
+ .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ))
258
+ .define ("d" , Type .INT , Importance .HIGH , "docs" , "group" , 4 , Width .SHORT , "d" , singletonList ("b" ), new IntegerRecommender (false ));
258
259
259
260
Map <String , String > props = new HashMap <>();
260
261
props .put ("a" , "1" );
@@ -289,10 +290,10 @@ public void testValidate() {
289
290
expected .put ("d" , configD );
290
291
291
292
ConfigDef def = new ConfigDef ()
292
- .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" ), new IntegerRecommender (false ))
293
- .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
294
- .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ))
295
- .define ("d" , Type .INT , Importance .HIGH , "docs" , "group" , 4 , Width .SHORT , "d" , singletonList ("b" ), new IntegerRecommender (false ));
293
+ .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" ), new IntegerRecommender (false ))
294
+ .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
295
+ .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ))
296
+ .define ("d" , Type .INT , Importance .HIGH , "docs" , "group" , 4 , Width .SHORT , "d" , singletonList ("b" ), new IntegerRecommender (false ));
296
297
297
298
Map <String , String > props = new HashMap <>();
298
299
props .put ("a" , "1" );
@@ -325,15 +326,15 @@ public void testValidateMissingConfigKey() {
325
326
expected .put ("d" , configD );
326
327
327
328
ConfigDef def = new ConfigDef ()
328
- .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" , "d" ), new IntegerRecommender (false ))
329
- .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
330
- .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ));
329
+ .define ("a" , Type .INT , Importance .HIGH , "docs" , "group" , 1 , Width .SHORT , "a" , Arrays .asList ("b" , "c" , "d" ), new IntegerRecommender (false ))
330
+ .define ("b" , Type .INT , Importance .HIGH , "docs" , "group" , 2 , Width .SHORT , "b" , new IntegerRecommender (true ))
331
+ .define ("c" , Type .INT , Importance .HIGH , "docs" , "group" , 3 , Width .SHORT , "c" , new IntegerRecommender (true ));
331
332
332
333
Map <String , String > props = new HashMap <>();
333
334
props .put ("a" , "1" );
334
335
335
336
List <ConfigValue > configs = def .validate (props );
336
- for (ConfigValue config : configs ) {
337
+ for (ConfigValue config : configs ) {
337
338
String name = config .name ();
338
339
ConfigValue expectedConfig = expected .get (name );
339
340
assertEquals (expectedConfig , config );
@@ -352,7 +353,7 @@ public void testValidateCannotParse() {
352
353
props .put ("a" , "non_integer" );
353
354
354
355
List <ConfigValue > configs = def .validate (props );
355
- for (ConfigValue config : configs ) {
356
+ for (ConfigValue config : configs ) {
356
357
String name = config .name ();
357
358
ConfigValue expectedConfig = expected .get (name );
358
359
assertEquals (expectedConfig , config );
@@ -505,32 +506,32 @@ public void toRst() {
505
506
506
507
final String expectedRst =
507
508
"``opt2``\n " +
508
- " docs2\n " +
509
- "\n " +
510
- " * Type: int\n " +
511
- " * Importance: medium\n " +
512
- "\n " +
513
- "``opt1``\n " +
514
- " docs1\n " +
515
- "\n " +
516
- " * Type: string\n " +
517
- " * Default: a\n " +
518
- " * Valid Values: [a, b, c]\n " +
519
- " * Importance: high\n " +
520
- "\n " +
521
- "``opt3``\n " +
522
- " docs3\n " +
523
- "\n " +
524
- " * Type: list\n " +
525
- " * Default: a,b\n " +
526
- " * Importance: low\n " +
527
- "\n " +
528
- "``opt4``\n " +
529
- "\n " +
530
- " * Type: boolean\n " +
531
- " * Default: false\n " +
532
- " * Importance: low\n " +
533
- "\n " ;
509
+ " docs2\n " +
510
+ "\n " +
511
+ " * Type: int\n " +
512
+ " * Importance: medium\n " +
513
+ "\n " +
514
+ "``opt1``\n " +
515
+ " docs1\n " +
516
+ "\n " +
517
+ " * Type: string\n " +
518
+ " * Default: a\n " +
519
+ " * Valid Values: [a, b, c]\n " +
520
+ " * Importance: high\n " +
521
+ "\n " +
522
+ "``opt3``\n " +
523
+ " docs3\n " +
524
+ "\n " +
525
+ " * Type: list\n " +
526
+ " * Default: a,b\n " +
527
+ " * Importance: low\n " +
528
+ "\n " +
529
+ "``opt4``\n " +
530
+ "\n " +
531
+ " * Type: boolean\n " +
532
+ " * Default: false\n " +
533
+ " * Importance: low\n " +
534
+ "\n " ;
534
535
535
536
assertEquals (expectedRst , def .toRst ());
536
537
}
@@ -550,48 +551,48 @@ public void toEnrichedRst() {
550
551
551
552
final String expectedRst =
552
553
"``poor.opt``\n " +
553
- " Doc doc doc doc.\n " +
554
- "\n " +
555
- " * Type: string\n " +
556
- " * Default: foo\n " +
557
- " * Importance: high\n " +
558
- "\n " +
559
- "Group One\n " +
560
- "^^^^^^^^^\n " +
561
- "\n " +
562
- "``opt1.of.group1``\n " +
563
- " Doc doc.\n " +
564
- "\n " +
565
- " * Type: string\n " +
566
- " * Default: a\n " +
567
- " * Valid Values: [a, b, c]\n " +
568
- " * Importance: high\n " +
569
- "\n " +
570
- "``opt2.of.group1``\n " +
571
- " Doc doc doc.\n " +
572
- "\n " +
573
- " * Type: int\n " +
574
- " * Importance: medium\n " +
575
- " * Dependents: ``some.option1``, ``some.option2``\n " +
576
- "\n " +
577
- "Group Two\n " +
578
- "^^^^^^^^^\n " +
579
- "\n " +
580
- "``opt1.of.group2``\n " +
581
- " Doc doc doc doc doc.\n " +
582
- "\n " +
583
- " * Type: boolean\n " +
584
- " * Default: false\n " +
585
- " * Importance: high\n " +
586
- " * Dependents: ``some.option``\n " +
587
- "\n " +
588
- "``opt2.of.group2``\n " +
589
- " Doc doc doc doc.\n " +
590
- "\n " +
591
- " * Type: boolean\n " +
592
- " * Default: false\n " +
593
- " * Importance: high\n " +
594
- "\n " ;
554
+ " Doc doc doc doc.\n " +
555
+ "\n " +
556
+ " * Type: string\n " +
557
+ " * Default: foo\n " +
558
+ " * Importance: high\n " +
559
+ "\n " +
560
+ "Group One\n " +
561
+ "^^^^^^^^^\n " +
562
+ "\n " +
563
+ "``opt1.of.group1``\n " +
564
+ " Doc doc.\n " +
565
+ "\n " +
566
+ " * Type: string\n " +
567
+ " * Default: a\n " +
568
+ " * Valid Values: [a, b, c]\n " +
569
+ " * Importance: high\n " +
570
+ "\n " +
571
+ "``opt2.of.group1``\n " +
572
+ " Doc doc doc.\n " +
573
+ "\n " +
574
+ " * Type: int\n " +
575
+ " * Importance: medium\n " +
576
+ " * Dependents: ``some.option1``, ``some.option2``\n " +
577
+ "\n " +
578
+ "Group Two\n " +
579
+ "^^^^^^^^^\n " +
580
+ "\n " +
581
+ "``opt1.of.group2``\n " +
582
+ " Doc doc doc doc doc.\n " +
583
+ "\n " +
584
+ " * Type: boolean\n " +
585
+ " * Default: false\n " +
586
+ " * Importance: high\n " +
587
+ " * Dependents: ``some.option``\n " +
588
+ "\n " +
589
+ "``opt2.of.group2``\n " +
590
+ " Doc doc doc doc.\n " +
591
+ "\n " +
592
+ " * Type: boolean\n " +
593
+ " * Default: false\n " +
594
+ " * Importance: high\n " +
595
+ "\n " ;
595
596
596
597
assertEquals (expectedRst , def .toEnrichedRst ());
597
598
}
@@ -729,34 +730,34 @@ public void testNiceTimeUnits() {
729
730
@ Test
730
731
public void testThrowsExceptionWhenListSizeExceedsLimit () {
731
732
final ConfigException exception = assertThrows (ConfigException .class , () -> new ConfigDef ().define ("lst" ,
732
- Type .LIST ,
733
- asList ("a" , "b" ),
734
- ListSize .atMostOfSize (1 ),
735
- Importance .HIGH ,
736
- "lst doc" ));
733
+ Type .LIST ,
734
+ asList ("a" , "b" ),
735
+ ListSize .atMostOfSize (1 ),
736
+ Importance .HIGH ,
737
+ "lst doc" ));
737
738
assertEquals ("Invalid value [a, b] for configuration lst: exceeds maximum list size of [1]." ,
738
- exception .getMessage ());
739
+ exception .getMessage ());
739
740
}
740
741
741
742
@ Test
742
743
public void testNoExceptionIsThrownWhenListSizeEqualsTheLimit () {
743
744
final List <String > lst = asList ("a" , "b" , "c" );
744
745
assertDoesNotThrow (() -> new ConfigDef ().define ("lst" ,
745
- Type .LIST ,
746
- lst ,
747
- ListSize .atMostOfSize (lst .size ()),
748
- Importance .HIGH ,
749
- "lst doc" ));
746
+ Type .LIST ,
747
+ lst ,
748
+ ListSize .atMostOfSize (lst .size ()),
749
+ Importance .HIGH ,
750
+ "lst doc" ));
750
751
}
751
752
752
753
@ Test
753
754
public void testNoExceptionIsThrownWhenListSizeIsBelowTheLimit () {
754
755
assertDoesNotThrow (() -> new ConfigDef ().define ("lst" ,
755
- Type .LIST ,
756
- asList ("a" , "b" ),
757
- ListSize .atMostOfSize (3 ),
758
- Importance .HIGH ,
759
- "lst doc" ));
756
+ Type .LIST ,
757
+ asList ("a" , "b" ),
758
+ ListSize .atMostOfSize (3 ),
759
+ Importance .HIGH ,
760
+ "lst doc" ));
760
761
}
761
762
762
763
@ Test
0 commit comments