Let's create a new file named app/src/test/java/com/adkdevelopment/earthquakesurvival/utils/LocationUtilsTest.java to implement comprehensive unit tests for LocationUtils.java.
This comprehensive test file covers all the public methods in LocationUtils.java:
testGetErrorString: Tests the getErrorString method with different error codes, including all specific GeofenceStatusCodes and an unknown code.
testGetTransitionString: Tests the getTransitionString method with different transition types, including both valid Geofence transitions and an unknown transition type.
testGetTransitionDetails: Tests the getTransitionDetails method with mock geofences, verifying that it correctly processes the transition type and geofence IDs.
testGetLocation: Tests the getLocation method with mocked SharedPreferences, ensuring it correctly retrieves and converts the stored latitude and longitude.
testSetLocation: Tests the setLocation method with a mock Location object, verifying that it correctly stores the latitude and longitude in SharedPreferences.
testSetLocationWithNullLocation: Tests the setLocation method with a null Location object, ensuring it doesn't interact with SharedPreferences in this case.
testGetDistance: Tests the getDistance method with different LatLng pairs, including a known distance calculation and a zero distance case.
testGetDistanceWithZeroLatitude: Tests the getDistance method with a zero latitude in the second point, which is a special case in the method's implementation.
These tests cover various scenarios and edge cases, ensuring the correct behavior of the LocationUtils methods. The use of Mockito for mocking Android-specific classes allows for isolated testing of the utility methods without depending on the actual Android framework.
🚀 Here's the PR! #67
Search Results
Response
Let's create a new file named app/src/test/java/com/adkdevelopment/earthquakesurvival/utils/LocationUtilsTest.java to implement comprehensive unit tests for LocationUtils.java.
app/src/test/java/com/adkdevelopment/earthquakesurvival/utils/LocationUtilsTest.java
This comprehensive test file covers all the public methods in LocationUtils.java:
testGetErrorString
: Tests thegetErrorString
method with different error codes, including all specific GeofenceStatusCodes and an unknown code.testGetTransitionString
: Tests thegetTransitionString
method with different transition types, including both valid Geofence transitions and an unknown transition type.testGetTransitionDetails
: Tests thegetTransitionDetails
method with mock geofences, verifying that it correctly processes the transition type and geofence IDs.testGetLocation
: Tests thegetLocation
method with mocked SharedPreferences, ensuring it correctly retrieves and converts the stored latitude and longitude.testSetLocation
: Tests thesetLocation
method with a mock Location object, verifying that it correctly stores the latitude and longitude in SharedPreferences.testSetLocationWithNullLocation
: Tests thesetLocation
method with a null Location object, ensuring it doesn't interact with SharedPreferences in this case.testGetDistance
: Tests thegetDistance
method with different LatLng pairs, including a known distance calculation and a zero distance case.testGetDistanceWithZeroLatitude
: Tests thegetDistance
method with a zero latitude in the second point, which is a special case in the method's implementation.These tests cover various scenarios and edge cases, ensuring the correct behavior of the LocationUtils methods. The use of Mockito for mocking Android-specific classes allows for isolated testing of the utility methods without depending on the actual Android framework.
Continue the conversation with Sweep here: http://localhost:3000/c/5a7192a6-a7a1-4502-b55e-d8c4ae602ed3.
:book: For more information on how to use Sweep, please read our documentation.