-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
291 additions
and
14 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
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
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/io/split/android/client/storage/general/GeneralInfoStorage.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,33 @@ | ||
package io.split.android.client.storage.general; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public interface GeneralInfoStorage { | ||
|
||
long getSplitsUpdateTimestamp(); | ||
|
||
void setSplitsUpdateTimestamp(long timestamp); | ||
|
||
long getChangeNumber(); | ||
|
||
void setChangeNumber(long changeNumber); | ||
|
||
@NonNull | ||
String getSplitsFilterQueryString(); | ||
|
||
void setSplitsFilterQueryString(String queryString); | ||
|
||
String getDatabaseEncryptionMode(); | ||
|
||
void setDatabaseEncryptionMode(String value); | ||
|
||
@Nullable | ||
String getFlagsSpec(); | ||
|
||
void setFlagsSpec(String value); | ||
|
||
long getRolloutCacheLastClearTimestamp(); | ||
|
||
void setRolloutCacheLastClearTimestamp(long timestamp); | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/io/split/android/client/storage/general/GeneralInfoStorageImpl.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,88 @@ | ||
package io.split.android.client.storage.general; | ||
|
||
import static io.split.android.client.utils.Utils.checkNotNull; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import io.split.android.client.storage.db.GeneralInfoDao; | ||
import io.split.android.client.storage.db.GeneralInfoEntity; | ||
|
||
public class GeneralInfoStorageImpl implements GeneralInfoStorage{ | ||
|
||
private static final String ROLLOUT_CACHE_LAST_CLEAR_TIMESTAMP = "rolloutCacheLastClearTimestamp"; | ||
|
||
private final GeneralInfoDao mGeneralInfoDao; | ||
|
||
public GeneralInfoStorageImpl(GeneralInfoDao generalInfoDao) { | ||
mGeneralInfoDao = checkNotNull(generalInfoDao); | ||
} | ||
|
||
@Override | ||
public long getSplitsUpdateTimestamp() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP); | ||
return entity != null ? entity.getLongValue() : 0L; | ||
} | ||
|
||
@Override | ||
public void setSplitsUpdateTimestamp(long timestamp) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_UPDATE_TIMESTAMP, timestamp)); | ||
} | ||
|
||
@Override | ||
public long getChangeNumber() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(GeneralInfoEntity.CHANGE_NUMBER_INFO); | ||
return entity != null ? entity.getLongValue() : -1L; | ||
} | ||
|
||
@Override | ||
public void setChangeNumber(long changeNumber) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.CHANGE_NUMBER_INFO, changeNumber)); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getSplitsFilterQueryString() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(GeneralInfoEntity.SPLITS_FILTER_QUERY_STRING); | ||
return entity != null ? entity.getStringValue() : ""; | ||
} | ||
|
||
@Override | ||
public void setSplitsFilterQueryString(String queryString) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.SPLITS_FILTER_QUERY_STRING, queryString)); | ||
} | ||
|
||
@Override | ||
public String getDatabaseEncryptionMode() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(GeneralInfoEntity.DATABASE_ENCRYPTION_MODE); | ||
return entity != null ? entity.getStringValue() : ""; | ||
} | ||
|
||
@Override | ||
public void setDatabaseEncryptionMode(String value) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.DATABASE_ENCRYPTION_MODE, value)); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public String getFlagsSpec() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(GeneralInfoEntity.FLAGS_SPEC); | ||
return entity != null ? entity.getStringValue() : ""; | ||
} | ||
|
||
@Override | ||
public void setFlagsSpec(String value) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(GeneralInfoEntity.FLAGS_SPEC, value)); | ||
} | ||
|
||
@Override | ||
public long getRolloutCacheLastClearTimestamp() { | ||
GeneralInfoEntity entity = mGeneralInfoDao.getByName(ROLLOUT_CACHE_LAST_CLEAR_TIMESTAMP); | ||
return entity != null ? entity.getLongValue() : 0L; | ||
} | ||
|
||
@Override | ||
public void setRolloutCacheLastClearTimestamp(long timestamp) { | ||
mGeneralInfoDao.update(new GeneralInfoEntity(ROLLOUT_CACHE_LAST_CLEAR_TIMESTAMP, timestamp)); | ||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
src/test/java/io/split/android/client/storage/general/GeneralInfoStorageImplTest.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,169 @@ | ||
package io.split.android.client.storage.general; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import io.split.android.client.storage.db.GeneralInfoDao; | ||
import io.split.android.client.storage.db.GeneralInfoEntity; | ||
|
||
public class GeneralInfoStorageImplTest { | ||
|
||
private GeneralInfoDao mGeneralInfoDao; | ||
private GeneralInfoStorageImpl mGeneralInfoStorage; | ||
|
||
@Before | ||
public void setUp() { | ||
mGeneralInfoDao = mock(GeneralInfoDao.class); | ||
mGeneralInfoStorage = new GeneralInfoStorageImpl(mGeneralInfoDao); | ||
} | ||
|
||
@Test | ||
public void setSplitsUpdateTimestampSetsValueOnDao() { | ||
mGeneralInfoStorage.setSplitsUpdateTimestamp(123L); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("splitsUpdateTimestamp") && entity.getLongValue() == 123L)); | ||
} | ||
|
||
@Test | ||
public void setSplitsUpdateTimestampGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("splitsUpdateTimestamp")).thenReturn(new GeneralInfoEntity("splitsUpdateTimestamp", 123L)); | ||
long splitsUpdateTimestamp = mGeneralInfoStorage.getSplitsUpdateTimestamp(); | ||
|
||
assertEquals(123L, splitsUpdateTimestamp); | ||
verify(mGeneralInfoDao).getByName("splitsUpdateTimestamp"); | ||
} | ||
|
||
@Test | ||
public void setChangeNumberSetsValueOnDao() { | ||
mGeneralInfoStorage.setChangeNumber(123L); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("splitChangesChangeNumber") && entity.getLongValue() == 123L)); | ||
} | ||
|
||
@Test | ||
public void setChangeNumberGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("splitChangesChangeNumber")).thenReturn(new GeneralInfoEntity("splitChangesChangeNumber", 123L)); | ||
long changeNumber = mGeneralInfoStorage.getChangeNumber(); | ||
|
||
assertEquals(123L, changeNumber); | ||
verify(mGeneralInfoDao).getByName("splitChangesChangeNumber"); | ||
} | ||
|
||
@Test | ||
public void getSplitsFilterQueryStringGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("splitsFilterQueryString")).thenReturn(new GeneralInfoEntity("splitsFilterQueryString", "queryString")); | ||
String splitsFilterQueryString = mGeneralInfoStorage.getSplitsFilterQueryString(); | ||
|
||
assertEquals("queryString", splitsFilterQueryString); | ||
verify(mGeneralInfoDao).getByName("splitsFilterQueryString"); | ||
} | ||
|
||
@Test | ||
public void setSplitsFilterQueryStringSetsValueOnDao() { | ||
mGeneralInfoStorage.setSplitsFilterQueryString("queryString"); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("splitsFilterQueryString") && entity.getStringValue().equals("queryString"))); | ||
} | ||
|
||
@Test | ||
public void getDatabaseEncryptionModeGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("databaseEncryptionMode")).thenReturn(new GeneralInfoEntity("databaseEncryptionMode", "value")); | ||
String databaseEncryptionMode = mGeneralInfoStorage.getDatabaseEncryptionMode(); | ||
|
||
assertEquals("value", databaseEncryptionMode); | ||
verify(mGeneralInfoDao).getByName("databaseEncryptionMode"); | ||
} | ||
|
||
@Test | ||
public void setDatabaseEncryptionModeSetsValueOnDao() { | ||
mGeneralInfoStorage.setDatabaseEncryptionMode("value"); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("databaseEncryptionMode") && entity.getStringValue().equals("value"))); | ||
} | ||
|
||
@Test | ||
public void getFlagsSpecGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("flagsSpec")).thenReturn(new GeneralInfoEntity("flagsSpec", "value")); | ||
String flagsSpec = mGeneralInfoStorage.getFlagsSpec(); | ||
|
||
assertEquals("value", flagsSpec); | ||
verify(mGeneralInfoDao).getByName("flagsSpec"); | ||
} | ||
|
||
@Test | ||
public void setFlagsSpecSetsValueOnDao() { | ||
mGeneralInfoStorage.setFlagsSpec("value"); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("flagsSpec") && entity.getStringValue().equals("value"))); | ||
} | ||
|
||
@Test | ||
public void getRolloutCacheLastClearTimestampGetsValueFromDao() { | ||
when(mGeneralInfoDao.getByName("rolloutCacheLastClearTimestamp")).thenReturn(new GeneralInfoEntity("rolloutCacheLastClearTimestamp", 123L)); | ||
long rolloutCacheLastClearTimestamp = mGeneralInfoStorage.getRolloutCacheLastClearTimestamp(); | ||
|
||
assertEquals(123L, rolloutCacheLastClearTimestamp); | ||
verify(mGeneralInfoDao).getByName("rolloutCacheLastClearTimestamp"); | ||
} | ||
|
||
@Test | ||
public void setRolloutCacheLastClearTimestampSetsValueOnDao() { | ||
mGeneralInfoStorage.setRolloutCacheLastClearTimestamp(123L); | ||
|
||
verify(mGeneralInfoDao).update(argThat(entity -> entity.getName().equals("rolloutCacheLastClearTimestamp") && entity.getLongValue() == 123L)); | ||
} | ||
|
||
@Test | ||
public void getChangeNumberReturnsMinusOneIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("splitChangesChangeNumber")).thenReturn(null); | ||
long changeNumber = mGeneralInfoStorage.getChangeNumber(); | ||
|
||
assertEquals(-1L, changeNumber); | ||
} | ||
|
||
@Test | ||
public void getSplitsUpdateTimestampReturnsZeroIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("splitsUpdateTimestamp")).thenReturn(null); | ||
long timestamp = mGeneralInfoStorage.getSplitsUpdateTimestamp(); | ||
|
||
assertEquals(0L, timestamp); | ||
} | ||
|
||
@Test | ||
public void getSplitsFilterQueryStringReturnsEmptyStringIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("splitsFilterQueryString")).thenReturn(null); | ||
String queryString = mGeneralInfoStorage.getSplitsFilterQueryString(); | ||
|
||
assertEquals("", queryString); | ||
} | ||
|
||
@Test | ||
public void getDatabaseEncryptionModeReturnsEmptyStringIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("databaseEncryptionMode")).thenReturn(null); | ||
String value = mGeneralInfoStorage.getDatabaseEncryptionMode(); | ||
|
||
assertEquals("", value); | ||
} | ||
|
||
@Test | ||
public void getFlagsSpecReturnsEmptyStringIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("flagsSpec")).thenReturn(null); | ||
String value = mGeneralInfoStorage.getFlagsSpec(); | ||
|
||
assertEquals("", value); | ||
} | ||
|
||
@Test | ||
public void getRolloutCacheLastClearTimestampReturnsZeroIfEntityIsNull() { | ||
when(mGeneralInfoDao.getByName("rolloutCacheLastClearTimestamp")).thenReturn(null); | ||
long timestamp = mGeneralInfoStorage.getRolloutCacheLastClearTimestamp(); | ||
|
||
assertEquals(0L, timestamp); | ||
} | ||
} |