package Ġcom . github . kon f ko . core . derived Ċ Ċ import Ġcom . github . kon f ko . core . NoSuch Setting Exception Ċ import Ġcom . github . kon f ko . core . structured . Structured Settings Ċ import Ġorg . assertj . core . api . Assertions Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . Test Ċ Ċ /** Ċ Ġ* Ġ@ author Ġmark opi Ċ Ġ*/ Ċ class ĠSub Settings Test Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Required () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsub Ġ= Ġsettings . sub Settings (" dataSource . first ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sub . get < String >(" url ")). isEqualTo (" jdbc : test : localhost / first ") ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . get < String >(" username ")). isEqualTo (" first User ") ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . get < String >(" password ")). isEqualTo (" first Password ") ĊĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsub . get < String >(" something ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . fail (" Property Ġshould Ġnot Ġexist ") ĊĠĠĠĠĠĠĠ Ġ} Ġcatch ( e : ĠNoSuch Setting Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( e ). has Message Containing (" dataSource . first . something ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġcontains () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsub Ġ= Ġsettings . sub Settings (" dataSource . first ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sub . contains (" url ")). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . contains (" connection Timeout ")). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġto Flat Map () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsub Ġ= Ġsettings . sub Settings (" dataSource . second ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sub . to Flat Map ()). isEqualTo ( map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" url " Ġto Ġ" jdbc : test : localhost / second ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" username " Ġto Ġ" second User ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" password " Ġto Ġ" second Password ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" connection Timeout " Ġto Ġ" 2 0 " ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġpresent Single Value Sub Setting () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsub Ġ= Ġsettings . sub Settings (" dataSource . second . connection Timeout ") Ġas ĠSub Settings ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . make Absolute Key (" ")). isEqualTo (" dataSource . second . connection Timeout ") ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . get < Int >(" ")). isEqualTo ( 2 0 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sub . to Flat Map ()). isEqualTo ( map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"" Ġto Ġ" 2 0 " ĊĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . empty ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġabsent Single Value Sub Setting () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsub Ġ= Ġsettings . sub Settings (" dataSource . second . something ") Ġas ĠSub Settings ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . make Absolute Key (" ")). isEqualTo (" dataSource . second . something ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( sub . to Flat Map ()). isEqualTo ( map Of < String , ĠAny >()) ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . find < Int >(" ")). isNull () ĊĠĠĠĠĠĠĠ ĠassertThat ( sub . empty ). isTrue () ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsub . get < String >(" ") ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAssertions . fail (" Property Ġshould Ġnot Ġexist ") ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠNoSuch Setting Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( e ). has Message Containing (" dataSource . second . something ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmult ile vel () Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠdataSource Ġ= Ġsettings . sub Settings (" dataSource ") Ġas ĠSub Settings ĊĠĠĠĠĠĠĠ ĠassertThat ( dataSource . make Absolute Key (" first . url ")). isEqualTo (" dataSource . first . url ") ĊĊĠĠĠĠĠĠĠ Ġval Ġfirst Ġ= ĠdataSource . sub Settings (" first ") Ġas ĠSub Settings ĊĠĠĠĠĠĠĠ ĠassertThat ( first . make Absolute Key (" url ")). isEqualTo (" dataSource . first . url ") ĊĠĠĠĠĠĠĠ ĠassertThat ( first . contains (" username ")). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( first . get < String >(" password ")). isEqualTo (" first Password ") ĊĠĠĠĠĠĠĠ ĠassertThat ( first . to Flat Map ()). isEqualTo ( map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" url " Ġto Ġ" jdbc : test : localhost / first ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" username " Ġto Ġ" first User ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" password " Ġto Ġ" first Password " ĊĠĠĠĠĠĠĠ Ġ)) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġdata Ġ= Ġmap Of ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . first . url " Ġto Ġ" jdbc : test : localhost / first ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . first . username " Ġto Ġ" first User ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . first . password " Ġto Ġ" first Password ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . second . url " Ġto Ġ" jdbc : test : localhost / second ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . second . username " Ġto Ġ" second User ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . second . password " Ġto Ġ" second Password ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" dataSource . second . connection Timeout " Ġto Ġ" 2 0 " ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġprivate Ġval Ġsettings Ġ= ĠStruct ured Settings ( data ) ĊĠĠĠ Ġ} Ċ }