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());
    }
}

@@ -1,8 +1,608 @@
+/*%0A * Copyright 2016 Victor Albertos%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 
@@ -875,18 +875,16 @@
  %7B%0A%0A
-  
   @Rule%0A
     
@@ -879,18 +879,16 @@
   @Rule%0A
-  
   public
@@ -944,26 +944,24 @@
 older();%0A%0A  
- 
- 
 @Test(expect
@@ -990,34 +990,32 @@
 xception.class)%0A
-  
   public void Ca
@@ -1033,36 +1033,32 @@
 ry_Null() %7B%0A    
-  
-  
 new RxCache.Buil
@@ -1055,36 +1055,32 @@
 Cache.Builder()%0A
-    
         .persist
@@ -1112,33 +1112,29 @@
 nstance());%0A
-  
   %7D%0A%0A
-  
   @Test(expe
@@ -1165,34 +1165,32 @@
 xception.class)%0A
-  
   public void Jo
@@ -1201,28 +1201,24 @@
 ot_Null() %7B%0A
-    
     new RxCa
@@ -1235,32 +1235,24 @@
 r()%0A        
-     
-   
 .persistence
@@ -1286,27 +1286,23 @@
  null);%0A
-  
   %7D%0A%0A  
- 
- 
 @Test(ex
@@ -1335,34 +1335,32 @@
 xception.class)%0A
-  
   public void Ca
@@ -1383,36 +1383,32 @@
 t_Exist() %7B%0A    
-  
-  
 File cacheDir = 
@@ -1463,28 +1463,24 @@
 t_folder%22);%0A
-    
     new RxCa
@@ -1497,32 +1497,24 @@
 r()%0A        
-     
-   
 .persistence
@@ -1554,19 +1554,15 @@
 ));%0A
-  
   %7D%0A%0A  
- 
- 
 @Tes
@@ -1607,18 +1607,16 @@
 .class)%0A
-  
   public
@@ -1658,20 +1658,16 @@
 ) %7B%0A    
-  
-  
 File cac
@@ -1730,28 +1730,24 @@
 t_folder%22);%0A
-    
     if (!cac
@@ -1762,38 +1762,32 @@
 dirs()) %7B%0A      
-     
- 
 throw new Illega
@@ -1840,34 +1840,26 @@
 tory%22);%0A    
-    %7D%0A    
+%7D%0A
     if (!cac
@@ -1899,22 +1899,16 @@
 %7B%0A      
-  
-    
 throw ne
@@ -1969,22 +1969,14 @@
     
-    %7D%0A   
+%7D%0A
     
- 
 new 
@@ -1993,24 +1993,16 @@
 ilder()%0A
-        
         
@@ -2050,16 +2050,14 @@
 nce());%0A
-  
   %7D%0A%7D%0A

Reformat style and add license to class RxCacheBuilderValidationTest