Skip to content

Commit

Permalink
Add test for support BackpressureStrategy specification
Browse files Browse the repository at this point in the history
  • Loading branch information
wakwak3125 committed Jan 3, 2018
1 parent 5e28f4a commit 5b3a91e
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.tools.JavaFileObject;

import info.izumin.android.droidux.processor.fixture.Source;
import io.reactivex.BackpressureStrategy;

import static com.google.common.truth.Truth.assert_;
import static com.google.testing.compile.JavaFileObjects.forSourceLines;
Expand Down Expand Up @@ -39,6 +40,15 @@ public void singleReducer() {
);
}

@Test
public void singleReducer_with_BackpressureStrategySpecification() {
assertJavaSource(
forSourceLines("RootStore", Source.CounterWithBackpressureStrategy.TARGET),
forSourceLines("DroiduxRootStore_CounterStoreImpl", Source.StoreImpl.COUNTER),
forSourceLines("DroiduxRootStore", Source.CounterWithBackpressureStrategy.GENERATED_STORE)
);
}

@Test
public void singleReducerBindable() {
assertJavaSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,111 @@ public static class Counter {
};
}

public static class CounterWithBackpressureStrategy {
public static final String[] TARGET = {
"package info.izumin.android.droidux.sample;",
"import info.izumin.android.droidux.annotation.Store;",
"import info.izumin.android.droidux.Action;",
"import info.izumin.android.droidux.BaseStore;",
"import info.izumin.android.droidux.processor.fixture.Counter;",
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import io.reactivex.BackpressureStrategy;",
"import io.reactivex.Flowable;",
"@Store({CounterReducer.class})",
"public interface RootStore extends BaseStore {",
" Counter counter();",
" Flowable<Counter> observeCounter();",
" Flowable<Counter> observeCounter(BackpressureStrategy strategy);",
"}"
};

public static final String[] GENERATED_STORE = {
"package info.izumin.android.droidux.sample;",
"",
"import android.databinding.BaseObservable;",
"import info.izumin.android.droidux.Action;",
"import info.izumin.android.droidux.Dispatcher;",
"import info.izumin.android.droidux.Middleware;",
"import info.izumin.android.droidux.exception.NotInitializedException;",
"import info.izumin.android.droidux.processor.fixture.Counter;",
"import info.izumin.android.droidux.processor.fixture.CounterReducer;",
"import io.reactivex.BackpressureStrategy;",
"import io.reactivex.Flowable;",
"import java.util.ArrayList;",
"import java.util.List;",
"",
"public final class DroiduxRootStore extends BaseObservable implements RootStore {",
" private final DroiduxRootStore_CounterStoreImpl counterStoreImpl;",
" private final Dispatcher dispatcher;",
"",
" protected DroiduxRootStore(final Builder builder) {",
" counterStoreImpl= new DroiduxRootStore_CounterStoreImpl(builder.counter, builder.counterReducer);",
" dispatcher = new Dispatcher(builder.middlewares, counterStoreImpl);",
" for (Middleware middleware : builder.middlewares) {",
" middleware.onAttach(this, dispatcher);",
" }",
" }",
"",
" public static Builder builder() {",
" return new Builder();",
" }",
"",
" @Override",
" public Counter counter() {",
" return counterStoreImpl.getState();",
" }",
"",
" @Override",
" public Flowable<Counter> observeCounter() {",
" return counterStoreImpl.observe();",
" }",
"",
"",
" @Override",
" public Flowable<Counter> observeCounter(BackpressureStrategy strategy) {",
" return counterStoreImpl.observe(strategy);",
" }",
"",
" @Override",
" public Flowable<Action> dispatch(Action action) {",
" return dispatcher.dispatch(action)",
" }",
"",
" public static final class Builder {",
" private final List<Middleware> middlewares;",
" private CounterReducer counterReducer;",
" private Counter counter;",
"",
" private Builder() {",
" middlewares = new ArrayList<>();",
" }",
"",
" public Builder addMiddleware(Middleware middleware) {",
" middlewares.add(middleware);",
" return this;",
" }",
"",
" public Builder setReducer(CounterReducer counterReducer) {",
" this.counterReducer = counterReducer;",
" return this;",
" }",
"",
" public Builder setReducer(CounterReducer counterReducer, Counter counter) {",
" this.counter = counter;",
" return setReducer(counterReducer);",
" }",
"",
" public DroiduxRootStore build() {",
" if (counterReducer == null) {",
" throw new NotInitializedException(\"CounterReducer has not been initialized.\");",
" }",
" return new DroiduxRootStore(this);",
" }",
" }",
"}"
};
}

public static class BindableCounter {
public static final String[] TARGET = {
"package info.izumin.android.droidux.sample;",
Expand Down

0 comments on commit 5b3a91e

Please sign in to comment.