Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix grouping logic failure when number of items matches the group size (
#163) * Modify the grouping logic to not fail when number of items is exact match of the group size * Filter out empty lists * Change constants to be package local
- Loading branch information
Showing
3 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
reark/src/test/java/io/reark/reark/data/stores/cores/ContentProviderStoreCoreBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package io.reark.reark.data.stores.cores; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.ContentValues; | ||
import android.database.ContentObserver; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import rx.Emitter.BackpressureMode; | ||
import rx.Observable; | ||
|
||
import static io.reark.reark.data.stores.cores.ContentProviderStoreCoreBase.DEFAULT_GROUPING_TIMEOUT_MS; | ||
import static io.reark.reark.data.stores.cores.ContentProviderStoreCoreBase.DEFAULT_GROUP_MAX_SIZE; | ||
|
||
public class ContentProviderStoreCoreBaseTest { | ||
|
||
private ContentProviderStoreCoreBase<Integer> contentStoreCore; | ||
|
||
@Before | ||
public void setup() { | ||
contentStoreCore = new NullContentStore(); | ||
} | ||
|
||
private static Observable<Integer> createSource(int numItems) { | ||
return Observable.fromEmitter(publisher -> { | ||
for (int i = 1; i <= numItems; i++) { | ||
publisher.onNext(i); | ||
} | ||
}, BackpressureMode.BUFFER); | ||
} | ||
|
||
@Test | ||
public void groupOperations_WithNoElements_DoesNotEmit() { | ||
contentStoreCore.groupOperations(Observable.never()) | ||
.test() | ||
.awaitTerminalEvent(2 * DEFAULT_GROUPING_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
.assertNotCompleted() | ||
.assertNoValues(); | ||
} | ||
|
||
@Test | ||
public void groupOperations_WithOneElement_EmitsOneGroup() { | ||
contentStoreCore.groupOperations(createSource(1)) | ||
.test() | ||
.awaitTerminalEvent(2 * DEFAULT_GROUPING_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
.assertNotCompleted() | ||
.assertValueCount(1); | ||
} | ||
|
||
@Test | ||
public void groupOperations_WithGroupMaxSizeElements_EmitsOneGroup() { | ||
contentStoreCore.groupOperations(createSource(DEFAULT_GROUP_MAX_SIZE)) | ||
.test() | ||
.awaitTerminalEvent(2 * DEFAULT_GROUPING_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
.assertNotCompleted() | ||
.assertValueCount(1); | ||
} | ||
|
||
@Test | ||
public void groupOperations_WithOneOverGroupMaxSizeElements_EmitsTwoGroups() { | ||
contentStoreCore.groupOperations(createSource(DEFAULT_GROUP_MAX_SIZE + 1)) | ||
.test() | ||
.awaitTerminalEvent(2 * DEFAULT_GROUPING_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
.assertNotCompleted() | ||
.assertValueCount(2); | ||
} | ||
|
||
@Test | ||
public void groupOperations_WithThreeTimesGroupMaxSizeElements_EmitsThreeGroups() { | ||
contentStoreCore.groupOperations(createSource(3 * DEFAULT_GROUP_MAX_SIZE)) | ||
.test() | ||
.awaitTerminalEvent(2 * DEFAULT_GROUPING_TIMEOUT_MS, TimeUnit.MILLISECONDS) | ||
.assertNotCompleted() | ||
.assertValueCount(3); | ||
} | ||
|
||
@SuppressWarnings({"ReturnOfNull", "ConstantConditions", "ZeroLengthArrayAllocation"}) | ||
private static class NullContentStore extends ContentProviderStoreCoreBase<Integer> { | ||
|
||
NullContentStore() { | ||
super(Mockito.mock(ContentResolver.class)); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected String getAuthority() { | ||
return null; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected ContentObserver getContentObserver() { | ||
return null; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected Uri getContentUri() { | ||
return null; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected String[] getProjection() { | ||
return new String[0]; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected Integer read(@NonNull Cursor cursor) { | ||
return null; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected ContentValues getContentValuesForItem(@NonNull Integer item) { | ||
return null; | ||
} | ||
} | ||
} |