@Test public void onDataChange() throws Exception { PowerMockito.mockStatic(QueryOnDataChange.class); QueryOnDataChange query = PowerMockito.mock(QueryOnDataChange.class); PowerMockito.whenNew(QueryOnDataChange.class).withAnyArguments().thenReturn(query); when(query.with(Mockito.nullable(Array.class))).thenReturn(query); when(query.with(Mockito.nullable(OrderByClause.class))).thenReturn(query); when(query.withArgs(Mockito.any(), Mockito.any())).thenReturn(query); Database database = new Database(); database.inReference("/test").onDataChange(Map.class).subscribe(); PowerMockito.verifyNew(QueryOnDataChange.class); }
@Override @SuppressWarnings("unchecked") public <T, R extends T> ListenerPromise<R> onDataChange(final Class<T> dataType) { checkDatabaseReference(); FilteringStateEnsurer.checkFilteringState(filters, orderByClause, dataType); return ConverterPromise.whenWithConvert(new DatabaseConsumer<ConverterPromise<T, R>>(this) { @Override public void accept(ConverterPromise<T, R> trConverterPromise) { trConverterPromise.with(GdxFIRDatabase.instance().getMapConverter(), dataType); new QueryOnDataChange(Database.this, getDatabasePath()) .with(getFilters()) .with(getOrderByClause()) .with(trConverterPromise) .withArgs(dataType) .execute(); } }); }
Database implements DatabaseDistribution, QueryProvider { @Override @SuppressWarnings("unchecked") public <T, R extends T> ListenerPromise<R> onDataChange(final Class<T> dataType) { checkDatabaseReference(); FilteringStateEnsurer.checkFilteringState(filters, orderByClause, dataType); return ConverterPromise.whenWithConvert(new DatabaseConsumer<ConverterPromise<T, R>>(this) { @Override public void accept(ConverterPromise<T, R> trConverterPromise) { trConverterPromise.with(GdxFIRDatabase.instance().getMapConverter(), dataType); new QueryOnDataChange(Database.this, getDatabasePath()) .with(getFilters()) .with(getOrderByClause()) .with(trConverterPromise) .withArgs(dataType) .execute(); } }); } }
Database implements DatabaseDistribution, QueryProvider { @Override @SuppressWarnings("unchecked") public <T, R extends T> ListenerPromise<R> onDataChange(final Class<T> dataType) { checkDatabaseReference(); FilteringStateEnsurer.checkFilteringState(filters, orderByClause, dataType); return ConverterPromise.whenWithConvert(new DatabaseConsumer<ConverterPromise<T, R>>(this) { @Override public void accept(ConverterPromise<T, R> trConverterPromise) { trConverterPromise.with(GdxFIRDatabase.instance().getMapConverter(), dataType); new QueryOnDataChange(Database.this, getDatabasePath()) .with(getFilters()) .with(getOrderByClause()) .with(trConverterPromise) .withArgs(dataType) .execute(); } }); } Database(); }
Database implements DatabaseDistribution, QueryProvider { @Override @SuppressWarnings("unchecked") public <T, R extends T> ListenerPromise<R> onDataChange(final Class<T> dataType) { checkDatabaseReference(); FilteringStateEnsurer.checkFilteringState(filters, orderByClause, dataType); return ConverterPromise.whenWithConvert(new DatabaseConsumer<ConverterPromise<T, R>>(this) { @Override public void accept(ConverterPromise<T, R> trConverterPromise) { trConverterPromise.with(GdxFIRDatabase.instance().getMapConverter(), dataType); new QueryOnDataChange(Database.this, getDatabasePath()) .with(getFilters()) .with(getOrderByClause()) .with(trConverterPromise) .withArgs(dataType) .execute(); } }); } Database(); @Override ListenerPromise<ConnectionStatus> onConnect(); @Override DatabaseDistribution inReference(String databasePath); @Override Promise<Void> setValue(final Object value); @Override @SuppressWarnings("unchecked") Promise<E> readValue(final Class<T> dataType); @Override @SuppressWarnings("unchecked") ListenerPromise<R> onDataChange(final Class<T> dataType); @Override ListenerPromise<R> onChildChange(final Class<T> dataType, final ChildEventType... eventsType); @Override @SuppressWarnings("unchecked") DatabaseDistribution filter(FilterType filterType, V... filterArguments); @Override DatabaseDistribution orderBy(OrderByMode orderByMode, String argument); @Override DatabaseDistribution orderBy(OrderByMode orderByMode); @Override DatabaseDistribution push(); @Override Promise<Void> removeValue(); @Override Promise<Void> updateChildren(final Map<String, Object> data); @Override @SuppressWarnings("unchecked") Promise<Void> transaction(final Class<T> dataType, final Function<R, R> transaction); @Override void setPersistenceEnabled(boolean enabled); @Override void keepSynced(boolean synced); @Override String getReferencePath(); @Override Array<Filter> getFilters(); @Override OrderByClause getOrderByClause(); @Override void terminateOperation(); }
Database implements DatabaseDistribution, QueryProvider { @Override @SuppressWarnings("unchecked") public <T, R extends T> ListenerPromise<R> onDataChange(final Class<T> dataType) { checkDatabaseReference(); FilteringStateEnsurer.checkFilteringState(filters, orderByClause, dataType); return ConverterPromise.whenWithConvert(new DatabaseConsumer<ConverterPromise<T, R>>(this) { @Override public void accept(ConverterPromise<T, R> trConverterPromise) { trConverterPromise.with(GdxFIRDatabase.instance().getMapConverter(), dataType); new QueryOnDataChange(Database.this, getDatabasePath()) .with(getFilters()) .with(getOrderByClause()) .with(trConverterPromise) .withArgs(dataType) .execute(); } }); } Database(); @Override ListenerPromise<ConnectionStatus> onConnect(); @Override DatabaseDistribution inReference(String databasePath); @Override Promise<Void> setValue(final Object value); @Override @SuppressWarnings("unchecked") Promise<E> readValue(final Class<T> dataType); @Override @SuppressWarnings("unchecked") ListenerPromise<R> onDataChange(final Class<T> dataType); @Override ListenerPromise<R> onChildChange(final Class<T> dataType, final ChildEventType... eventsType); @Override @SuppressWarnings("unchecked") DatabaseDistribution filter(FilterType filterType, V... filterArguments); @Override DatabaseDistribution orderBy(OrderByMode orderByMode, String argument); @Override DatabaseDistribution orderBy(OrderByMode orderByMode); @Override DatabaseDistribution push(); @Override Promise<Void> removeValue(); @Override Promise<Void> updateChildren(final Map<String, Object> data); @Override @SuppressWarnings("unchecked") Promise<Void> transaction(final Class<T> dataType, final Function<R, R> transaction); @Override void setPersistenceEnabled(boolean enabled); @Override void keepSynced(boolean synced); @Override String getReferencePath(); @Override Array<Filter> getFilters(); @Override OrderByClause getOrderByClause(); @Override void terminateOperation();  }