Skip to content

Commit

Permalink
LDEV-4278 fixed lsweek unit tests to check java version (#2189)
Browse files Browse the repository at this point in the history
* LDEV-4278 updated unit test to pass for different java versions

* LDEV-4278 updated comments and added another test
  • Loading branch information
mattdyer authored Jul 21, 2023
1 parent cb02ccb commit 303ff0b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions test/functions/lsWeek.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
describe( title="Testcase for lsWeek()", body=function() {
it(title="checking lsWeek() with locale argument", body = function( currentSpec ) {
var date = createDateTime(2022,01,17,12,0,0,0,"UTC");
// in Arabic (Yemen) Saturday is the first day of the week
expect(lsWeek(date=date, locale="Arabic (Yemen)")).tobe(3);
// in Catalan Monday is the first day of the week
expect(lsWeek(date=date, locale="Catalan")).tobe(3);

if(getJavaVersion()<=8){
// in Arabic (Yemen) Saturday is the first day of the week
expect(lsWeek(date=date, locale="Arabic (Yemen)")).tobe(3);
// in Catalan Monday is the first day of the week
expect(lsWeek(date=date, locale="Catalan")).tobe(3);
}else{
// after Java 8 in Arabic (Yemen) Sunday is the first day of the week
expect(lsWeek(date=date, locale="Arabic (Yemen)")).tobe(4);
// after Java 8 in Catalan Sunday is the first day of the week
expect(lsWeek(date=date, locale="Catalan")).tobe(4);
// Testing Iraq because it still has Saturday as the first day of the week after Java 8
expect(lsWeek(date =date, locale="ar_IQ")).toBe(3);
}
// in English (Canada) Sunday is the first day of the week
expect(lsWeek(date=date, locale="English (Canada)")).tobe(4);
});
Expand All @@ -21,4 +31,13 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {
});
});
}

private function getJavaVersion() {
var raw=server.java.version;
var arr=listToArray(raw,'.');
if(arr[1]==1) // version 1-9
return arr[2];
return arr[1];
}

}

0 comments on commit 303ff0b

Please sign in to comment.