This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from daemontus/dir-existence-check
Add checks for cache dir validity. Closes #57
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
runtime/src/test/java/io/rx_cache/internal/RxCacheBuilderValidationTest.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,49 @@ | ||
package io.rx_cache.internal; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import java.io.File; | ||
import java.security.InvalidParameterException; | ||
|
||
/** | ||
* Created by daemontus on 02/09/16. | ||
*/ | ||
public class RxCacheBuilderValidationTest { | ||
|
||
@Rule | ||
public TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
|
||
@Test(expected = InvalidParameterException.class) | ||
public void Cache_Directory_Null() { | ||
new RxCache.Builder() | ||
.persistence(null, Jolyglot$.newInstance()); | ||
} | ||
|
||
@Test(expected = InvalidParameterException.class) | ||
public void Jolyglot_Null() { | ||
new RxCache.Builder() | ||
.persistence(temporaryFolder.getRoot(), null); | ||
} | ||
|
||
@Test(expected = InvalidParameterException.class) | ||
public void Cache_Directory_Not_Exist() { | ||
File cacheDir = new File(temporaryFolder.getRoot(), "non_existent_folder"); | ||
new RxCache.Builder() | ||
.persistence(cacheDir, Jolyglot$.newInstance()); | ||
} | ||
|
||
@Test(expected = InvalidParameterException.class) | ||
public void Cache_Directory_Not_Writable() { | ||
File cacheDir = new File(temporaryFolder.getRoot(), "non_existent_folder"); | ||
if (!cacheDir.mkdirs()) { | ||
throw new IllegalStateException("Cannot create temporary directory"); | ||
} | ||
if (!cacheDir.setWritable(false, false)) { | ||
throw new IllegalStateException("Cannot modify permissions"); | ||
} | ||
new RxCache.Builder() | ||
.persistence(cacheDir, Jolyglot$.newInstance()); | ||
} | ||
} |