use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.
the class ProvidersDynamicsKeysRxCacheTest method Pagination.
@Test
public void Pagination() {
TestObserver<List<io.rx_cache2.internal.Mock>> testObserver;
List<io.rx_cache2.internal.Mock> mocksPage1 = createMocks(SIZE);
String mockPage1Value = mocksPage1.get(0).getMessage();
testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage1), new DynamicKey(1)).test();
testObserver.awaitTerminalEvent();
List<io.rx_cache2.internal.Mock> mocksPage2 = createMocks(SIZE);
String mockPage2Value = mocksPage2.get(0).getMessage();
testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage2), new DynamicKey(2)).test();
testObserver.awaitTerminalEvent();
List<io.rx_cache2.internal.Mock> mocksPage3 = createMocks(SIZE);
String mockPage3Value = mocksPage3.get(0).getMessage();
testObserver = providersRxCache.getMocksPaginate(Observable.just(mocksPage3), new DynamicKey(3)).test();
testObserver.awaitTerminalEvent();
testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(1)).test();
testObserver.awaitTerminalEvent();
assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage1Value));
testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(2)).test();
testObserver.awaitTerminalEvent();
assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage2Value));
testObserver = providersRxCache.getMocksPaginate(ProviderHelper.<List<io.rx_cache2.internal.Mock>>withoutLoader(), new DynamicKey(3)).test();
testObserver.awaitTerminalEvent();
assertThat(testObserver.values().get(0).get(0).getMessage(), is(mockPage3Value));
}
use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.
the class ProxyTranslatorTest method When_Get_Page_Get_Pages.
@Test
public void When_Get_Page_Get_Pages() throws NoSuchMethodException {
Object[] dataMethodPaginate = { Observable.just(new Object[] {}), new DynamicKey(1) };
Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksPaginate", Observable.class, DynamicKey.class);
ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodPaginate);
assertThat(configProvider.getDynamicKey(), is("1"));
}
use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.
the class ProxyTranslatorTest method When_Evict_Cache_Dynamic_Key_Evict.
@Test
public void When_Evict_Cache_Dynamic_Key_Evict() throws NoSuchMethodException {
final String dynamicKey = "aDynamicKey";
Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMocksDynamicKeyEvictPage", Observable.class, DynamicKey.class, EvictDynamicKey.class);
Object[] dataMethodEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(true) };
ConfigProvider configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodEvict);
EvictDynamicKey evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
assertThat(configProvider.getDynamicKey(), is(dynamicKey));
assertThat(evictDynamicKey.evict(), is(true));
Object[] dataMethodNoEvict = { Observable.just(new Object[] {}), new DynamicKey(dynamicKey), new EvictDynamicKey(false) };
configProvider = proxyTranslatorUT.processMethod(mockMethod, dataMethodNoEvict);
evictDynamicKey = (EvictDynamicKey) configProvider.evictProvider();
assertThat(configProvider.getDynamicKey(), is(dynamicKey));
assertThat(evictDynamicKey.evict(), is(false));
}
use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.
the class ProxyTranslatorTest method When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception.
@Test
public void When_Use_Evict_Dynamic_Key_Providing_Dynamic_Key_Not_Throw_Exception() throws NoSuchMethodException {
Method mockMethod = io.rx_cache2.internal.ProvidersRxCache.class.getDeclaredMethod("getMockEvictDynamicKeyProvidingDynamicKey", Observable.class, DynamicKey.class, EvictDynamicKey.class);
Object[] data = { Observable.just(new Object[] {}), new DynamicKey("1"), new EvictDynamicKey(true) };
proxyTranslatorUT.processMethod(mockMethod, data);
}
use of io.rx_cache2.DynamicKey in project RxCache by VictorAlbertos.
the class ProxyTranslator method getDynamicKey.
private String getDynamicKey(Method method, Object[] objectsMethod) {
DynamicKey dynamicKey = getObjectFromMethodParam(method, DynamicKey.class, objectsMethod);
if (dynamicKey != null)
return dynamicKey.getDynamicKey().toString();
DynamicKeyGroup dynamicKeyGroup = getObjectFromMethodParam(method, DynamicKeyGroup.class, objectsMethod);
if (dynamicKeyGroup != null)
return dynamicKeyGroup.getDynamicKey().toString();
return "";
}
Aggregations