Skip to content

Commit

Permalink
Improve unit test code coverage. Remove deprecated data getSingle() m…
Browse files Browse the repository at this point in the history
…ethod.
  • Loading branch information
patloew committed Oct 30, 2016
1 parent f552cec commit 094cb0c
Show file tree
Hide file tree
Showing 31 changed files with 1,646 additions and 151 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reactive Wearable API Library for Android

[![Build Status](https://travis-ci.org/patloew/RxWear.svg?branch=master)](https://travis-ci.org/patloew/RxWear) [ ![Download](https://api.bintray.com/packages/patloew/maven/RxWear/images/download.svg) ](https://bintray.com/patloew/maven/RxWear/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RxWear-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3271) [![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=9)
[![Build Status](https://travis-ci.org/patloew/RxWear.svg?branch=master)](https://travis-ci.org/patloew/RxWear) [![codecov](https://codecov.io/gh/patloew/RxWear/branch/master/graph/badge.svg)](https://codecov.io/gh/patloew/RxWear) [ ![Download](https://api.bintray.com/packages/patloew/maven/RxWear/images/download.svg) ](https://bintray.com/patloew/maven/RxWear/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RxWear-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3271) [![API](https://img.shields.io/badge/API-9%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=9)

This library wraps the Wearable API in [RxJava](https://github.com/ReactiveX/RxJava) Observables and Singles. No more managing GoogleApiClients! Also, there are some helper classes, which ease communication between phone and wear app.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* limitations under the License. */
class CapabilityAddLocalSingle extends BaseSingle<Status> {

private final String capability;
final String capability;

CapabilityAddLocalSingle(RxWear rxWear, String capability, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* limitations under the License. */
class CapabilityGetAllSingle extends BaseSingle<Map<String, CapabilityInfo>> {

private final int nodeFilter;
final int nodeFilter;

CapabilityGetAllSingle(RxWear rxWear, int nodeFilter, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* limitations under the License. */
class CapabilityGetSingle extends BaseSingle<CapabilityInfo> {

private final String capability;
private final int nodeFilter;
final String capability;
final int nodeFilter;

CapabilityGetSingle(RxWear rxWear, String capability, int nodeFilter, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
* limitations under the License. */
class CapabilityListenerObservable extends BaseObservable<CapabilityInfo> {

private final String capability;
private final Uri uri;
private final Integer filterType;
final String capability;
final Uri uri;
final Integer filterType;

private CapabilityApi.CapabilityListener listener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* limitations under the License. */
class CapabilityRemoveLocalSingle extends BaseSingle<Status> {

private final String capability;
final String capability;

CapabilityRemoveLocalSingle(RxWear rxWear, String capability, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* limitations under the License. */
class ChannelCloseSingle extends BaseSingle<Status> {

private final Channel channel;
private final Integer errorCode;
final Channel channel;
final Integer errorCode;

ChannelCloseSingle(RxWear rxWear, Channel channel, Integer errorCode, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* limitations under the License. */
class ChannelGetInputStreamSingle extends BaseSingle<InputStream> {

private final Channel channel;
final Channel channel;

ChannelGetInputStreamSingle(RxWear rxWear, Channel channel, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* limitations under the License. */
class ChannelGetOutputStreamSingle extends BaseSingle<OutputStream> {

private final Channel channel;
final Channel channel;

ChannelGetOutputStreamSingle(RxWear rxWear, Channel channel, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* limitations under the License. */
class ChannelListenerObservable extends BaseObservable<ChannelEvent> {

private final Channel channel;
final Channel channel;
private ChannelApi.ChannelListener listener;

ChannelListenerObservable(RxWear rxWear, Channel channel, Long timeout, TimeUnit timeUnit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* limitations under the License. */
class ChannelOpenSingle extends BaseSingle<Channel> {

private final String nodeId;
private final String path;
final String nodeId;
final String path;

ChannelOpenSingle(RxWear rxWear, String nodeId, String path, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* limitations under the License. */
class ChannelReceiveFileSingle extends BaseSingle<Status> {

private final Channel channel;
private final Uri uri;
private final boolean append;
final Channel channel;
final Uri uri;
final boolean append;

ChannelReceiveFileSingle(RxWear rxWear, Channel channel, Uri uri, boolean append, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
* limitations under the License. */
class ChannelSendFileSingle extends BaseSingle<Status> {

private final Channel channel;
private final Uri uri;
private final Long startOffset;
private final Long length;
final Channel channel;
final Uri uri;
final Long startOffset;
final Long length;

ChannelSendFileSingle(RxWear rxWear, Channel channel, Uri uri, Long startOffset, Long length, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
64 changes: 18 additions & 46 deletions library/src/main/java/com/patloew/rxwear/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
import com.google.android.gms.wearable.PutDataMapRequest;
import com.google.android.gms.wearable.PutDataRequest;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Single;

import static com.patloew.rxwear.IOUtil.closeSilently;

/* Copyright 2016 Patrick Löwenstein
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -46,6 +42,11 @@ public class Data {
this.rxWear = rxWear;
}


Uri.Builder getUriBuilder() {
return new Uri.Builder();
}

// listen

public Observable<DataEvent> listen() {
Expand All @@ -65,11 +66,11 @@ public Observable<DataEvent> listen(@NonNull Uri uri, int filterType, long timeo
}

public Observable<DataEvent> listen(@NonNull String path, int filterType) {
return listenInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, null, null);
return listenInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, null, null);
}

public Observable<DataEvent> listen(@NonNull String path, int filterType, long timeout, @NonNull TimeUnit timeUnit) {
return listenInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, timeout, timeUnit);
return listenInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, timeout, timeUnit);
}

private Observable<DataEvent> listenInternal(Uri uri, Integer filterType, Long timeout, TimeUnit timeUnit) {
Expand Down Expand Up @@ -116,29 +117,10 @@ public Single<DataItem> put(@NonNull PutDataMapRequest putDataMapRequest, long t
return putInternal(putDataMapRequest.asPutDataRequest(), timeout, timeUnit);
}

private Single<DataItem> putInternal(PutDataRequest putDataRequest, Long timeout, TimeUnit timeUnit) {
Single<DataItem> putInternal(PutDataRequest putDataRequest, Long timeout, TimeUnit timeUnit) {
return Single.create(new DataPutItemSingle(rxWear, putDataRequest, timeout, timeUnit));
}


// getSingle

@Deprecated
// use get() instead
public Single<DataItem> getSingle(@NonNull Uri uri) {
return getSingleInternal(uri, null, null);
}

@Deprecated
// use get() instead
public Single<DataItem> getSingle(@NonNull Uri uri, long timeout, @NonNull TimeUnit timeUnit) {
return getSingleInternal(uri, timeout, timeUnit);
}

private Single<DataItem> getSingleInternal(Uri uri, Long timeout, TimeUnit timeUnit) {
return Single.create(new DataGetItemSingle(rxWear, uri, timeout, timeUnit));
}

// get

public Observable<DataItem> get(@NonNull Uri uri, int filterType) {
Expand All @@ -150,11 +132,11 @@ public Observable<DataItem> get(@NonNull Uri uri, int filterType, long timeout,
}

public Observable<DataItem> get(@NonNull String path, int filterType) {
return getInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, null, null);
return getInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, null, null);
}

public Observable<DataItem> get(@NonNull String path, int filterType, long timeout, @NonNull TimeUnit timeUnit) {
return getInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, timeout, timeUnit);
return getInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), filterType, timeout, timeUnit);
}

public Observable<DataItem> get(@NonNull Uri uri) {
Expand All @@ -166,11 +148,11 @@ public Observable<DataItem> get(@NonNull Uri uri, long timeout, @NonNull TimeUni
}

public Observable<DataItem> get(@NonNull String path) {
return getInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), null, null, null);
return getInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), null, null, null);
}

public Observable<DataItem> get(@NonNull String path, long timeout, @NonNull TimeUnit timeUnit) {
return getInternal(new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), null, timeout, timeUnit);
return getInternal(getUriBuilder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(path).build(), null, timeout, timeUnit);
}

public Observable<DataItem> get() {
Expand Down Expand Up @@ -229,8 +211,8 @@ public PutSerializable putSerializable(Serializable serializable) {
*/
public class PutSerializable {

private final Serializable serializable;
private boolean urgent = false;
final Serializable serializable;
boolean urgent = false;

PutSerializable(Serializable serializable) {
this.serializable = serializable;
Expand Down Expand Up @@ -260,21 +242,11 @@ public Single<DataItem> to(String path) {
}

private Single<DataItem> createPutSerializableSingle(PutDataRequest request) {
ObjectOutputStream oos = null;

try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(serializable);
oos.flush();
request.setData(baos.toByteArray());
request.setData(IOUtil.writeObjectToByteArray(serializable));
return putInternal(request, null, null);

} catch(IOException e) {
return Single.error(e);

} finally {
closeSilently(oos);
}
}
}
Expand All @@ -295,7 +267,7 @@ public class PutDataMap {

PutDataMap() { }

private boolean urgent = false;
boolean urgent = false;

public PutDataMap urgent() {
urgent = true;
Expand All @@ -307,7 +279,7 @@ public RxFitPutDataMapRequest withDataMapItem(DataMapItem source) {
}

public RxFitPutDataMapRequest withAutoAppendedId(String pathPrefix) {
return new RxFitPutDataMapRequest( null, null, pathPrefix, urgent);
return new RxFitPutDataMapRequest(null, null, pathPrefix, urgent);
}

public RxFitPutDataMapRequest to(String path) {
Expand All @@ -317,7 +289,7 @@ public RxFitPutDataMapRequest to(String path) {


public class RxFitPutDataMapRequest {
private final PutDataMapRequest request;
final PutDataMapRequest request;

private RxFitPutDataMapRequest(String path, DataMapItem dataMapItem, String pathPrefix, boolean urgent) {
if(path != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* limitations under the License. */
class DataDeleteItemsSingle extends BaseSingle<Integer> {

private final Uri uri;
private final Integer filterType;
final Uri uri;
final Integer filterType;

DataDeleteItemsSingle(RxWear rxWear, Uri uri, Integer filterType, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* limitations under the License. */
class DataGetFdForAssetSingle extends BaseSingle<DataApi.GetFdForAssetResult> {

private final DataItemAsset dataItemAsset;
private final Asset asset;
final DataItemAsset dataItemAsset;
final Asset asset;

DataGetFdForAssetSingle(RxWear rxWear, DataItemAsset dataItemAsset, Asset asset, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
42 changes: 0 additions & 42 deletions library/src/main/java/com/patloew/rxwear/DataGetItemSingle.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* limitations under the License. */
class DataGetItemsObservable extends BaseObservable<DataItem> {

private final Uri uri;
private final Integer filterType;
final Uri uri;
final Integer filterType;

DataGetItemsObservable(RxWear rxWear, Uri uri, Integer filterType, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* limitations under the License. */
class DataListenerObservable extends BaseObservable<DataEvent> {

private final Uri uri;
private final Integer filterType;
final Uri uri;
final Integer filterType;

private DataApi.DataListener listener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* limitations under the License. */
class DataPutItemSingle extends BaseSingle<DataItem> {

private final PutDataRequest putDataRequest;
final PutDataRequest putDataRequest;

DataPutItemSingle(RxWear rxWear, PutDataRequest putDataRequest, Long timeout, TimeUnit timeUnit) {
super(rxWear, timeout, timeUnit);
Expand Down
Loading

0 comments on commit 094cb0c

Please sign in to comment.