Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'toString' method for some Emitters #5995

Merged
merged 7 commits into from
May 6, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@ public void dispose() {
public boolean isDisposed() {
return DisposableHelper.isDisposed(get());
}

@Override
public String toString() {
return String.format("%s{%s}", getClass().getSimpleName(), super.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public boolean isCancelled() {
public FlowableEmitter<T> serialize() {
return this;
}

@Override
public String toString() {
return emitter.toString();
}
}

abstract static class BaseEmitter<T>
Expand Down Expand Up @@ -338,6 +343,11 @@ public final long requested() {
public final FlowableEmitter<T> serialize() {
return new SerializedEmitter<T>(this);
}

@Override
public String toString() {
return String.format("%s{%s}", getClass().getSimpleName(), super.toString());
}
}

static final class MissingEmitter<T> extends BaseEmitter<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,10 @@ public void dispose() {
public boolean isDisposed() {
return DisposableHelper.isDisposed(get());
}

@Override
public String toString() {
return String.format("%s{%s}", getClass().getSimpleName(), super.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public void dispose() {
public boolean isDisposed() {
return DisposableHelper.isDisposed(get());
}

@Override
public String toString() {
return String.format("%s{%s}", getClass().getSimpleName(), super.toString());
}
}

/**
Expand Down Expand Up @@ -279,6 +284,11 @@ public boolean isDisposed() {
public ObservableEmitter<T> serialize() {
return this;
}

@Override
public String toString() {
return emitter.toString();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ public void dispose() {
public boolean isDisposed() {
return DisposableHelper.isDisposed(get());
}

@Override
public String toString() {
return String.format("%s{%s}", getClass().getSimpleName(), super.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,14 @@ public void subscribe(CompletableEmitter e) throws Exception {
RxJavaPlugins.reset();
}
}

@Test
public void emitterHasToString() {
Completable.create(new CompletableOnSubscribe() {
@Override
public void subscribe(CompletableEmitter emitter) throws Exception {
assertTrue(emitter.toString().contains(CompletableCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import static org.junit.Assert.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.reactivestreams.*;
Expand Down Expand Up @@ -931,4 +933,26 @@ public void subscribe(FlowableEmitter<Object> e) throws Exception {
}
}
}

@Test
public void emittersHasToString() {
Map<BackpressureStrategy, Class<? extends FlowableEmitter>> emitterMap =
new HashMap<BackpressureStrategy, Class<? extends FlowableEmitter>>();

emitterMap.put(BackpressureStrategy.MISSING, FlowableCreate.MissingEmitter.class);
emitterMap.put(BackpressureStrategy.ERROR, FlowableCreate.ErrorAsyncEmitter.class);
emitterMap.put(BackpressureStrategy.DROP, FlowableCreate.DropAsyncEmitter.class);
emitterMap.put(BackpressureStrategy.LATEST, FlowableCreate.LatestAsyncEmitter.class);
emitterMap.put(BackpressureStrategy.BUFFER, FlowableCreate.BufferAsyncEmitter.class);

for (final Map.Entry<BackpressureStrategy, Class<? extends FlowableEmitter>> entry : emitterMap.entrySet()) {
Flowable.create(new FlowableOnSubscribe<Object>() {
@Override
public void subscribe(FlowableEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(entry.getValue().getSimpleName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails, the test still passes because the error is turned into onError. Please add the .assertEmpty() after test(). In addition, please do the test for the serialized emitter as well.

assertTrue(emitter.serialize().toString().contains(entry.getValue().getSimpleName()));
}
}, entry.getKey()).test().assertEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,14 @@ public void subscribe(MaybeEmitter<Object> e) throws Exception {
RxJavaPlugins.reset();
}
}

@Test
public void emitterHasToString() {
Maybe.create(new MaybeOnSubscribe<Object>() {
@Override
public void subscribe(MaybeEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(MaybeCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,15 @@ public void subscribe(ObservableEmitter<Object> e) throws Exception {
RxJavaPlugins.reset();
}
}

@Test
public void emitterHasToString() {
Observable.create(new ObservableOnSubscribe<Object>() {
@Override
public void subscribe(ObservableEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(ObservableCreate.CreateEmitter.class.getSimpleName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the serialized test here as well.

assertTrue(emitter.serialize().toString().contains(ObservableCreate.CreateEmitter.class.getSimpleName()));
}
}).test().assertEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,14 @@ public void subscribe(SingleEmitter<Object> e) throws Exception {
RxJavaPlugins.reset();
}
}

@Test
public void emitterHasToString() {
Single.create(new SingleOnSubscribe<Object>() {
@Override
public void subscribe(SingleEmitter<Object> emitter) throws Exception {
assertTrue(emitter.toString().contains(SingleCreate.Emitter.class.getSimpleName()));
}
}).test().assertEmpty();
}
}