Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static com.google.common.truth.Truth.assertThat;
      4 import static org.junit.Assert.assertFalse;
      5 import static org.junit.Assert.assertTrue;
      6 
      7 import android.content.SyncResult;
      8 import androidx.test.ext.junit.runners.AndroidJUnit4;
      9 import org.junit.Test;
     10 import org.junit.runner.RunWith;
     11 
     12 @RunWith(AndroidJUnit4.class)
     13 public class ShadowSyncResultTest {
     14 
     15   @Test
     16   public void testConstructor() throws Exception {
     17     SyncResult result = new SyncResult();
     18     assertThat(result.stats).isNotNull();
     19   }
     20 
     21   @Test
     22   public void hasSoftError() throws Exception {
     23     SyncResult result = new SyncResult();
     24     assertFalse(result.hasSoftError());
     25     result.stats.numIoExceptions++;
     26     assertTrue(result.hasSoftError());
     27     assertTrue(result.hasError());
     28   }
     29 
     30   @Test
     31   public void hasHardError() throws Exception {
     32     SyncResult result = new SyncResult();
     33     assertFalse(result.hasHardError());
     34     result.stats.numAuthExceptions++;
     35     assertTrue(result.hasHardError());
     36     assertTrue(result.hasError());
     37   }
     38 
     39   @Test
     40   public void testMadeSomeProgress() throws Exception {
     41     SyncResult result = new SyncResult();
     42     assertFalse(result.madeSomeProgress());
     43     result.stats.numInserts++;
     44     assertTrue(result.madeSomeProgress());
     45   }
     46 
     47   @Test
     48   public void testClear() throws Exception {
     49     SyncResult result = new SyncResult();
     50     result.moreRecordsToGet = true;
     51     result.stats.numInserts++;
     52     result.clear();
     53     assertFalse(result.moreRecordsToGet);
     54     assertThat(result.stats.numInserts).isEqualTo(0L);
     55   }
     56 }
     57