Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK:309-Switching to the new Date and Time API #226

Merged
merged 5 commits into from
Jun 28, 2023

Conversation

wikumChamith
Copy link
Contributor


if (lastReport != null) {
return (currentDate.getTime() - lastReport.getTime()) / (60 * 60 * 1000 * 24) % 60 > 7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some tests for things like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkayiwa this method is private, Should I write tests for this:

public void sendReport(Wizard wizard) throws MojoExecutionException {
or use reflection?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the method that calls it public? If yes, does it have a test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets called by the following method.

public void sendReport(Wizard wizard) throws MojoExecutionException {

This method does not have any tests. It sends a report to Google Forms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create some tests for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just making the method public would be easier 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not sound ideal. In that case, i would rather go for the hacky reflection. 😊

@wikumChamith
Copy link
Contributor Author

@dkayiwa I made a few changes to the code and added the tests. Is this alright?

@@ -37,4 +42,20 @@ public void shouldSetStatsEnabledMode(){
assertThat(sdkStatistics.getStatsEnabled(), is(true));
}

@Test
public void testCheckIfOneWeekApart_LessThanOneWeekApart() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What i had in mind was tests for the original method checkIfOneWeekFromLastReport such that they still pass even after the method internal implementation details are changed.

if (lastReport != null) {
return (currentDate.getTime() - lastReport.getTime()) / (60 * 60 * 1000 * 24) % 60 > 7;
} else {
public boolean checkIfOneWeekApart(LocalDate lastDate) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look right to make this method public only for the sake of tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we completely avoid creating this new method?

@wikumChamith
Copy link
Contributor Author

@dkayiwa I changed the tests with reflection.


/**
*
*/
public class SdkStatisticsTest {

private static final String DATE_FORMAT = "dd-M-yyyy";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of this constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to format the dates for statsLastReported property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change the code like this if you want.
private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-M-yyyy");

@dkayiwa
Copy link
Member

dkayiwa commented Jun 28, 2023

I changed the tests with reflection.

I see quite a number of repeated lines in your tests.

@wikumChamith
Copy link
Contributor Author

I changed the tests with reflection.

I see quite a number of repeated lines in your tests.

@dkayiwa I refactored the tests.

@dkayiwa dkayiwa merged commit c7db8a1 into openmrs:master Jun 28, 2023
2 checks passed
@wikumChamith
Copy link
Contributor Author

@dkayiwa I didn't squash the commits. Is that alright??

@dkayiwa
Copy link
Member

dkayiwa commented Jun 28, 2023

I didn't squash the commits. Is that alright??

No need to do so because i squash on merge.

wikumChamith added a commit to wikumChamith/openmrs-sdk that referenced this pull request Jun 29, 2023
* SDK:309-Switching to the new Date and Time API

* SDK-308: Switching to the new Date and Time API

* SDK-309: Adding tests

* SDK-309: Changing tests

* SDK-309: Refactoring tests
wikumChamith added a commit to wikumChamith/openmrs-sdk that referenced this pull request Jun 29, 2023
* SDK:309-Switching to the new Date and Time API

* SDK-308: Switching to the new Date and Time API

* SDK-309: Adding tests

* SDK-309: Changing tests

* SDK-309: Refactoring tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants