1package com.xtremelabs.robolectric.shadows; 2 3import com.xtremelabs.robolectric.internal.Implementation; 4import com.xtremelabs.robolectric.internal.Implements; 5 6import android.os.StatFs; 7 8import java.io.File; 9import java.util.HashMap; 10import java.util.Map; 11 12@Implements(StatFs.class) 13public class ShadowStatFs { 14 public static final int BLOCK_SIZE = 4096; 15 private static final Stats DEFAULT_STATS = new Stats(0, 0, 0); 16 private static Map<String, Stats> stats = new HashMap<String, Stats>(); 17 private Stats stat; 18 19 public void __constructor__(String path) { 20 restat(path); 21 } 22 23 @Implementation 24 public int getBlockSize() { 25 return BLOCK_SIZE; 26 } 27 28 @Implementation 29 public int getBlockCount() { 30 return stat.blockCount; 31 } 32 33 @Implementation 34 public int getFreeBlocks() { 35 return stat.freeBlocks; 36 } 37 38 @Implementation 39 public int getAvailableBlocks() { 40 return stat.availableBlocks; 41 } 42 43 @Implementation 44 public void restat(String path) { 45 stat = stats.get(path); 46 if (stat == null) { 47 stat = DEFAULT_STATS; 48 } 49 } 50 51 public static void registerStats(File path, int blockCount, int freeBlocks, int availableBlocks) { 52 registerStats(path.getAbsolutePath(), blockCount, freeBlocks, availableBlocks); 53 } 54 55 public static void registerStats(String path, int blockCount, int freeBlocks, int availableBlocks) { 56 stats.put(path, new Stats(blockCount, freeBlocks, availableBlocks)); 57 } 58 59 public static void reset() { 60 stats.clear(); 61 } 62 63 private static class Stats { 64 Stats(int blockCount, int freeBlocks, int availableBlocks) { 65 this.blockCount = blockCount; 66 this.freeBlocks = freeBlocks; 67 this.availableBlocks = availableBlocks; 68 } 69 int blockCount, freeBlocks, availableBlocks; 70 } 71}