https://github.com/comcast/resourceprovider-utils
Samples and Test Utilities Library for the ResourceProvider API Generator Gradle Plugin for Android.
https://github.com/comcast/resourceprovider-utils
Last synced: 4 months ago
JSON representation
Samples and Test Utilities Library for the ResourceProvider API Generator Gradle Plugin for Android.
- Host: GitHub
- URL: https://github.com/comcast/resourceprovider-utils
- Owner: Comcast
- License: apache-2.0
- Created: 2017-05-26T15:13:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-07-16T21:34:47.000Z (almost 6 years ago)
- Last Synced: 2026-01-14T17:26:36.943Z (5 months ago)
- Language: Java
- Homepage: https://github.com/Comcast/resourceprovider2
- Size: 30.9 MB
- Stars: 19
- Watchers: 11
- Forks: 8
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Android Resource Provider Test Utilities and Samples
======================
Resource Provider is now a gradle plugin! If you were using the Annotation Processor version, and want to upgrade, check out the new setup instructions [here](https://github.com/Comcast/resourceprovider2#android-resource-provider-2).
======================
Resource Provider is a gradle plugin that generates a class which contains APIs to get Android Resources
Resource Provider allows the presentation layer in your MVP implementation to explicitly control presentation details
without needing access or knowledge of Android's Context or R classes. Resource Provider automatically generates an
API for every string resource in your application, allowing the details of fetching resources to be opaque to
your presenters, maintaining strict separation of concerns. The source for the gradle plugin is available [here](https://github.com/Comcast/resourceprovider2).
This repo contains the testutils library which facilitates unit testing of resourceprovider logic.
The resourceprovider-testutils library contains Answer classes for different types of resources. This library is
used by the ResourceProviderTestUtils class that's generated by the plugin.
This repo also contains sample projects that illustrate how to set up and use the ResourceProvider plugin and the
test utilities for both Android apps and libraries
ResourceProvider provides APIs that mirror the application's string resource names, but in lower camel case and
with the standard underscore delimiter stripped. For example, for the string resource
```xml
This format strings has %1$d args
```
The resourceprovider-compiler will generate the API:
```java
public String getOneArgFormattedString(Object... formatArgs) { ... }
```
For any plural:
```xml
Only 1 day until Friday!
%d days until Friday
```
resourceprovider-compiler will generate the API:
```Java
public String getDaysUntilFridayQuantityString(int quantity, Object... formatArgs) { ... }
```
And for any drawable file
```xml
any_drawable.png ( or any_drawable.xml)
```
The resourceprovider plugin will generate the API:
```java
public Drawable getAnyDrawable() { ... }
```
Mocking ResourceProvider Test Utility APIS
=============================
Resource Provider generates sub-providers for each type of resource, like strings, drawables and colors,
and these can be mocked using extension functions that are generated by the plugin.
To mock each type of resource, in the setup function of a unit test call:
```java
resourceProvider.mock()
```
For example, to mocl a String resource:
```java
resourceProvider.mockStrings()
```
And for a color
```java
resourceProvider.mockColors()
```
After the initial call, any call to get a resource of that type will be answered with a mock version
Setup
======================
For ResourceProvider plugic setup, check the plugin repo readme [here](https://github.com/Comcast/resourceprovider2)
To set up unit testing, add the following lines to your test dependencies:
```xml
testImplementation 'com.xfinity:resourceprovider-testutils:'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
```
(You'll need mockitokotlin2 regardless of whether you're using Java or Kotlin, since the generated
ResourceProviderTestUtils class will depend on that library.)