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

Add to RawQuery affectsTables and observesTables that take collection #698

Merged
merged 1 commit into from Oct 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,6 +3,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -243,6 +244,29 @@ public CompleteBuilder affectsTables(@NonNull String... tables) {
return this;
}

/**
* Optional: Specifies set of tables which will be affected by this query.
* They will be used to notify observers of that tables.
* <p>
* Default value is {@code null}.
*
* @param tables set of tables which will be affected by this query.
* @return builder.
* @see RawQuery#affectsTables()
*/
@NonNull
public CompleteBuilder affectsTables(@NonNull Collection<String> tables) {
if (affectsTables == null) {
affectsTables = new HashSet<String>(tables.size());
} else {
affectsTables.clear();
}

affectsTables.addAll(tables);

return this;
}

/**
* Optional: Specifies set of tables that should be observed by this query.
* They will be used to re-execute query if one of the tables will be changed.
Expand All @@ -266,6 +290,29 @@ public CompleteBuilder observesTables(@NonNull String... tables) {
return this;
}

/**
* Optional: Specifies set of tables that should be observed by this query.
* They will be used to re-execute query if one of the tables will be changed.
* <p>
* Default values is {@code null}.
*
* @param tables set of tables that should be observed by this query.
* @return builder.
* @see RawQuery#observesTables()
*/
@NonNull
public CompleteBuilder observesTables(@NonNull Collection<String> tables) {
if (observesTables == null) {
observesTables = new HashSet<String>(tables.size());
} else {
observesTables.clear();
}

observesTables.addAll(tables);

return this;
}

/**
* Builds immutable instance of {@link RawQuery}.
*
Expand Down
Expand Up @@ -5,10 +5,13 @@

import org.junit.Test;

import java.util.HashSet;

import nl.jqno.equalsverifier.EqualsVerifier;

import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;

Expand Down Expand Up @@ -72,25 +75,91 @@ public void affectsTablesShouldNotBeNull() {
}

@Test
public void shouldRewriteAffectsTablesOnSecondCall() {
public void affectsTablesShouldRewriteCollectionWithVarargOnSecondCall() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.affectsTables(new HashSet<String>((singletonList("first_call_collection"))))
.affectsTables("second_call_vararg")
.build();

assertThat(rawQuery.affectsTables()).isEqualTo(singleton("second_call_vararg"));
}

@Test
public void affectsTablesShouldRewriteVarargWithCollectionOnSecondCall() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.affectsTables("first_call_vararg")
.affectsTables(new HashSet<String>((singletonList("second_call_collection"))))
.build();

assertThat(rawQuery.affectsTables()).isEqualTo(singleton("second_call_collection"));
}

@Test
public void affectsTablesShouldRewriteOnSecondCallVararg() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.affectsTables("first_call_vararg")
.affectsTables("second_call_vararg")
.build();

assertThat(rawQuery.affectsTables()).isEqualTo(singleton("second_call_vararg"));
}

@Test
public void affectsTablesShouldRewriteOnSecondCallCollection() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.affectsTables(new HashSet<String>((singletonList("first_call_collection"))))
.affectsTables(new HashSet<String>((singletonList("second_call_collection"))))
.build();

assertThat(rawQuery.affectsTables()).isEqualTo(singleton("second_call_collection"));
}

@Test
public void observesTablesShouldRewriteCollectionWithVarargOnSecondCall() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.observesTables(new HashSet<String>((singletonList("first_call_collection"))))
.observesTables("second_call_vararg")
.build();

assertThat(rawQuery.observesTables()).isEqualTo(singleton("second_call_vararg"));
}

@Test
public void observesTablesShouldRewriteVarargWithCollectionOnSecondCall() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.observesTables("first_call_vararg")
.observesTables(new HashSet<String>((singletonList("second_call_collection"))))
.build();

assertThat(rawQuery.observesTables()).isEqualTo(singleton("second_call_collection"));
}

@Test
public void observesTablesShouldRewriteOnSecondCallVararg() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.affectsTables("first_call")
.affectsTables("second_call")
.observesTables("first_call_vararg")
.observesTables("second_call_vararg")
.build();

assertThat(rawQuery.affectsTables()).isEqualTo(singleton("second_call"));
assertThat(rawQuery.observesTables()).isEqualTo(singleton("second_call_vararg"));
}

@Test
public void shouldRewriteObservesTablesOnSecondCall() {
public void observesTablesShouldRewriteOnSecondCallCollection() {
RawQuery rawQuery = RawQuery.builder()
.query("test_query")
.observesTables("first_call")
.observesTables("second_call")
.observesTables(new HashSet<String>((singletonList("first_call_collection"))))
.observesTables(new HashSet<String>((singletonList("second_call_collection"))))
.build();

assertThat(rawQuery.observesTables()).isEqualTo(singleton("second_call"));
assertThat(rawQuery.observesTables()).isEqualTo(singleton("second_call_collection"));
}

@Test
Expand Down