Skip to content

Commit

Permalink
Add insertOrUpdate list with tests - fix other test and memoryDao for…
Browse files Browse the repository at this point in the history
… delete(list)
  • Loading branch information
tspoke committed Sep 13, 2017
1 parent abd7d3c commit 04c3384
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ public Flowable<Optional<List<TestModel>>> getAll(Filter filter, SortingMode sor
return Flowable.just(Optional.wrap(copy));
}

@Override
public Flowable<Optional<List<TestModel>>> getAll(final List<TestModel> items) {
List<TestModel> output = new ArrayList<>();
for(TestModel toFind : items){
for(TestModel tm : models){
if(tm.getId() == toFind.getId()){
output.add(tm);
}
}
}

return Flowable.just(Optional.wrap(output));
}

@Override
public Flowable<Optional<TestModel>> getOne(Filter filter, SortingMode sortingMode) {
if(sortingMode != null && sortingMode.sort == SortType.DESCENDING){
Expand Down Expand Up @@ -72,14 +86,14 @@ public Flowable<Optional<List<TestModel>>> insertOrUpdate(final List<TestModel>
}

@Override
public Flowable<Integer> delete(List<TestModel> items) {
public Flowable<Integer> delete(final List<TestModel> items) {
List<TestModel> output = new ArrayList<>();

int found = 0;
for (TestModel tm : models) {
boolean foundInDeleteList = false;
for(TestModel model : items) {
if(tm.getId() != model.getId()) {
if(tm.getId() == model.getId()) {
foundInDeleteList = true;
found++;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class TestModel{
private int id;
private String name;
private boolean available;
private boolean available = false;

public TestModel(int id) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public Flowable<Optional<List<TestModel>>> getAll(Filter filter, SortingMode sor
return Flowable.just(Optional.wrap(list)).delay(1, TimeUnit.SECONDS);
}

@Override
public Flowable<Optional<List<TestModel>>> getAll(final List<TestModel> items) {
return getAll(null, null).map(new Function<Optional<List<TestModel>>, Optional<List<TestModel>>>() {
@Override
public Optional<List<TestModel>> apply(Optional<List<TestModel>> fullList) throws Exception {
List<TestModel> output = new ArrayList<>();
for(TestModel toFind : items){
for(TestModel tm : fullList.get()){
if(tm.getId() == toFind.getId()){
output.add(tm);
}
}
}
return Optional.wrap(output);
}
});
}

@Override
public Flowable<Optional<TestModel>> getOne(TestModel item) {
return getOne(new Filter("id", item.getId()), null);
Expand Down Expand Up @@ -126,5 +144,13 @@ public Flowable<Optional<TestModel>> insertOrUpdate(TestModel item) {
}
return Flowable.just(Optional.wrap(item)).delay(1, TimeUnit.SECONDS);
}

@Override
public Flowable<Optional<List<TestModel>>> insertOrUpdate(final List<TestModel> items) {
if(shouldThrowError){
return Flowable.error(new Exception("insertOrUpdate.error"));
}
return Flowable.just(Optional.wrap(items)).delay(1, TimeUnit.SECONDS);
}
}
}
Loading

0 comments on commit 04c3384

Please sign in to comment.