-
Notifications
You must be signed in to change notification settings - Fork 8
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
Update Functional Tests, use Core TimeUtils date formatter, remove Jetifier #50
Conversation
Update Functional test
…white box code Use Core TimeUtils for data formatter and remove remaining powermock white box code
Update Functional Tests
…oid into functionalTest
Test clean up
remove a commented code
metaDataContents.put(ConsentConstants.EventDataKey.TIME, TimeUtils.getIso8601DateTimeZoneISO8601()); | ||
metaDataContents.put( | ||
ConsentConstants.EventDataKey.TIME, | ||
TimeUtils.getISO8601UTCDateWithMilliseconds(new Date(timeStamp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Core TimeUtils here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be addressed with the latest update
code/edgeconsent/src/test/java/com/adobe/marketing/mobile/edge/consent/ConsentsTest.java
Show resolved
Hide resolved
…tions() Fix functional tests, add wait time and remove extra resetTestExpectations()
Codecov Report
@@ Coverage Diff @@
## dev-v2.0.0 #50 +/- ##
==============================================
+ Coverage 75.88% 84.77% +8.89%
==============================================
Files 11 4 -7
Lines 398 256 -142
Branches 44 30 -14
==============================================
- Hits 302 217 -85
+ Misses 67 23 -44
+ Partials 29 16 -13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Use Jitpack Assurance and Remove Jetifier
@@ -31,6 +29,8 @@ static final class EventDataKey { | |||
private EventDataKey() {} | |||
} | |||
|
|||
private ConsentConstants() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you move constructor to line 20.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved constructor for ConsentConstants
above static final class
definitions!
private final ConsentManager consentManager; | ||
|
||
// package private vars | ||
ConsentManager consentManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest injecting this variable via constructor and retain its final nature while making it testable. That way you can mock this directly in your test as well as eliminate the whitebox mock.
protected ConsentExtension(final ExtensionApi extensionApi) {
this(
extensionApi,
ServiceProvider
.getInstance()
.getDataStoreService()
.getNamedCollection(ConsentConstants.DataStoreKey.DATASTORE_NAME)
);
}
@VisibleForTesting
ConsentExtension(final ExtensionApi extensionApi, final NamedCollection namedCollection) {
this(extensionApi, new ConsentManager(namedCollection))
}
protected ConsentExtension(final ExtensionApi extensionApi, final ConsentManager consentManager) {
super(extensionApi);
this.consentManager = consentManager;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Prashanth! Refactored this with the suggested implementation and updated the related test cases
… injection Update test helper method that sets up persistence using new constructor Update ConsentConstants constructor position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @prudrabhat! I noticed during the implementation of the refactor for ConsentExtension
constructor, when giving protected
status even without the @VisibleForTesting
annotation, it is still accessible to the test cases. So I defined the constructor like this:
protected ConsentExtension(final ExtensionApi extensionApi, final NamedCollection namedCollection)
Also, I wasn't able to fully remove the setupExistingConsents
helper function in ConsentExtensionTest
because it handles the alternate test case setup flow where the mocked NamedCollection
needs to have its getString
API mocked with the provided jsonString
to simulate the situation where there are consents already in persistence.
I noticed in the existing ConsentExtension
logic that this fetch from persistence by the ConsentManager
is only done once on initialization, so having this helper method to set the API mock with the required consents value and reinstantiate the ConsentExtension
to trigger the read from persistence using the mocked NamedCollection
was helpful to keep all the test cases which require this logical flow working. What do you think?
I also noticed that there is a similar case in ConsentManager
where the property Consents defaultConsents
is being accessed directly by test cases in order to perform the required assertions; is this also something we want to refactor in a similar way to the mutable package private consentManager
?
@@ -31,6 +29,8 @@ static final class EventDataKey { | |||
private EventDataKey() {} | |||
} | |||
|
|||
private ConsentConstants() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved constructor for ConsentConstants
above static final class
definitions!
private final ConsentManager consentManager; | ||
|
||
// package private vars | ||
ConsentManager consentManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Prashanth! Refactored this with the suggested implementation and updated the related test cases
* @param configuration the initial configuration update that needs to be applied | ||
* @throws InterruptedException if the wait time for extension registration has elapsed | ||
*/ | ||
public static void registerExtensions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Move to TestHelper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved function and registration timeout constant to TestHelper, and refactored all usages!
* @param source the source of the event. | ||
* @param count the number of events expected to be received. | ||
*/ | ||
public static void setExpectedEvent(final String type, final String source, final int count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the ability to set an "expected" event was removed from the MonitorExtension. If this functionality isn't needed, then can you remove the expectedEvents
variable and any handling of checking for or returning expected events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed expectedEvents
property and all associated logic!
|
||
import static org.junit.Assert.fail; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import com.adobe.marketing.mobile.edge.consent.ConsentTestConstants; | ||
import java.util.ArrayList; | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the TestPersistenceHelper class needed anymore? Can the test cases use a mocked DataStoreService instead of reading the persisted values from shared preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If separating test cases from the actual SharedPreferences
is something we want to pursue, is that something we could cover in a separate task? I feel that the scope is a bit large seeing that many different test cases interact with SharedPreferences
by updating/reading values and we want to make sure to properly handle all those cases and also test the integration of Consent with the actual SharedPreferences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, totally fine to take this up in a separate PR.
@@ -49,14 +50,27 @@ protected ConsentExtension(final ExtensionApi extensionApi) { | |||
} | |||
|
|||
/** | |||
* Constructor used for testing. | |||
* Convenience constructor that instantiates a new {@link ConsentManager} using the passed {@link NamedCollection}. | |||
* <br><br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a single <p>
tag to add a line break in JavaDoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Updated to use the <p>
tag
private Consents defaultConsents; // holds on to default consents obtained from configuration response | ||
|
||
// package private vars | ||
Consents defaultConsents; // holds on to default consents obtained from configuration response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this package-private for testing or production? Can @VisbleForTesting
be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's package-private for testing purposes! I've added the @VisibleForTesting
annotation as suggested
/** | ||
* Sets up existing consents values in persistence by setting up a mocked return value for the | ||
* mocked {@link NamedCollection} using the passed JSON consents {@link String}. | ||
* <br><br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use <p>
to add line break in JavaDocs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @kevinlind! I've addressed the feedback with the latest updates, with one outstanding question on the refactor of TestPersistenceHelper
* @param configuration the initial configuration update that needs to be applied | ||
* @throws InterruptedException if the wait time for extension registration has elapsed | ||
*/ | ||
public static void registerExtensions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved function and registration timeout constant to TestHelper, and refactored all usages!
* @param source the source of the event. | ||
* @param count the number of events expected to be received. | ||
*/ | ||
public static void setExpectedEvent(final String type, final String source, final int count) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed expectedEvents
property and all associated logic!
private Consents defaultConsents; // holds on to default consents obtained from configuration response | ||
|
||
// package private vars | ||
Consents defaultConsents; // holds on to default consents obtained from configuration response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's package-private for testing purposes! I've added the @VisibleForTesting
annotation as suggested
@@ -49,14 +50,27 @@ protected ConsentExtension(final ExtensionApi extensionApi) { | |||
} | |||
|
|||
/** | |||
* Constructor used for testing. | |||
* Convenience constructor that instantiates a new {@link ConsentManager} using the passed {@link NamedCollection}. | |||
* <br><br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Updated to use the <p>
tag
|
||
import static org.junit.Assert.fail; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import com.adobe.marketing.mobile.edge.consent.ConsentTestConstants; | ||
import java.util.ArrayList; | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If separating test cases from the actual SharedPreferences
is something we want to pursue, is that something we could cover in a separate task? I feel that the scope is a bit large seeing that many different test cases interact with SharedPreferences
by updating/reading values and we want to make sure to properly handle all those cases and also test the integration of Consent with the actual SharedPreferences
metaDataContents.put(ConsentConstants.EventDataKey.TIME, TimeUtils.getIso8601DateTimeZoneISO8601()); | ||
metaDataContents.put( | ||
ConsentConstants.EventDataKey.TIME, | ||
TimeUtils.getISO8601UTCDateWithMilliseconds(new Date(timeStamp)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be addressed with the latest update
Update Functional Tests:
Updated to use Core TimeUtils date format.
Update the remaining powermock code and dependencies.
Remove Jetifier.
Description
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: