ensembler icon indicating copy to clipboard operation
ensembler copied to clipboard

Some unit tests fail for non-english locale

Open Suigi opened this issue 3 years ago • 1 comments

The following unit tests fail on my local machine (which is located in Austria):

  • membersInDifferentTimeZonesGetCustomizedEnsembleScheduledEmail
  • memberWithEmailWhenEnsembleScheduledThenCustomEmailSentToMember
  • memberWithEmailAcceptsThenEmailSentToMemberWithEnsembleDetails

Here's an example of one of the assertion errors:

java.lang.AssertionError: 
Expecting actual:
  ["Ensembler: New Ensemble Scheduled for 2021-12-17 at 1:00pm (GMT-08:00)",
    "Ensembler: New Ensemble Scheduled for 2021-12-17 at 4:00pm (GMT-05:00)"]
to contain exactly (and in same order):
  ["Ensembler: New Ensemble Scheduled for 2021-12-17 at 1:00PM (PST)",
    "Ensembler: New Ensemble Scheduled for 2021-12-17 at 4:00PM (EST)"]
but some elements were not found:
  ["Ensembler: New Ensemble Scheduled for 2021-12-17 at 1:00PM (PST)",
    "Ensembler: New Ensemble Scheduled for 2021-12-17 at 4:00PM (EST)"]
and others were not expected:
  ["Ensembler: New Ensemble Scheduled for 2021-12-17 at 1:00pm (GMT-08:00)",
    "Ensembler: New Ensemble Scheduled for 2021-12-17 at 4:00pm (GMT-05:00)"]


	at com.jitterted.mobreg.adapter.out.email.EmailToSendEnsembleScheduledNotifierTest.membersInDifferentTimeZonesGetCustomizedEnsembleScheduledEmail

Possible fix

The tests pass if I change the DateTimeFormatter setup in EmailNotifier to contain a specific locale:

private static final DateTimeFormatter LONG_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("LLLL d, uuuu 'at' h:mma (zzz)", Locale.ENGLISH);
private static final DateTimeFormatter SHORT_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd 'at' h:mma (zzz)", Locale.ENGLISH);

However, I don't know how you would like to approach this. I suppose, you might want to hard-code English for now?

Suigi avatar Jan 29 '22 00:01 Suigi

Thanks! The locale effect on the time zone is interesting. I suppose when I add "locale" to a Member's profile, I should add another test for times with time zones outside the USA along with those locales.

For now, hard-coding the Locale makes sense, which would be Locale.US in my case.

tedyoung avatar Jan 29 '22 23:01 tedyoung