// Path: purefm/src/main/java/com/docd/purefm/utils/StatFsCompat.java
// public final class StatFsCompat {
// 
//     /**
//      * StatFs instance
//      */
//     @NonNull
//     private final StatFs mStatFs;
// 
//     /**
//      * Construct a new StatFs for looking at the stats of the filesystem at
//      * {@code path}. Upon construction, the stat of the file system will be
//      * performed, and the values retrieved available from the methods on this
//      * class.
//      *
//      * @param path path in the desired file system to stat.
//      */
//     public StatFsCompat(@NonNull final String path) {
//         this.mStatFs = new StatFs(path);
//     }
// 
//     /**
//      * The number of blocks that are free on the file system and available to
//      * applications. This corresponds to the Unix {@code statvfs.f_bavail} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getAvailableBlocksLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getAvailableBlocksLong();
//         } else {
//             return mStatFs.getAvailableBlocks();
//         }
//     }
// 
//     /**
//      * The total number of blocks on the file system. This corresponds to the
//      * Unix {@code statvfs.f_blocks} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getBlockCountLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getBlockCountLong();
//         } else {
//             return mStatFs.getBlockCount();
//         }
//     }
// 
//     /**
//      * The size, in bytes, of a block on the file system. This corresponds to
//      * the Unix {@code statvfs.f_bsize} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getBlockSizeLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getBlockSizeLong();
//         } else {
//             return mStatFs.getBlockSize();
//         }
//     }
// 
//     /**
//      * The total number of blocks that are free on the file system, including
//      * reserved blocks (that are not available to normal applications). This
//      * corresponds to the Unix {@code statvfs.f_bfree} field. Most applications
//      * will want to use {@link #getAvailableBlocksLong()} instead.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getFreeBlocksLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getFreeBlocksLong();
//         } else {
//             return mStatFs.getFreeBlocks();
//         }
//     }
// 
//     /**
//      * The number of bytes that are free on the file system and available to
//      * applications.
//      */
//     @SuppressLint("NewApi")
//     public long getAvailableBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getAvailableBytes();
//         } else {
//             return getAvailableBlocksLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * The number of bytes that are free on the file system, including reserved
//      * blocks (that are not available to normal applications). Most applications
//      * will want to use {@link #getAvailableBytes()} instead.
//      */
//     @SuppressLint("NewApi")
//     public long getFreeBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getFreeBytes();
//         } else {
//             return getFreeBlocksLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * The total number of bytes supported by the file system.
//      */
//     public long getTotalBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getTotalBytes();
//         } else {
//             return getBlockCountLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * Perform a restat of the file system referenced by this object. This is
//      * the same as re-constructing the object with the same file system path,
//      * and the new stat values are available upon return.
//      */
//     public void restat(@NonNull final String path) {
//         mStatFs.restat(path);
//     }
// }


import android.annotation.TargetApi;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.test.AndroidTestCase;
import com.docd.purefm.utils.StatFsCompat;
import android.support.annotation.NonNull;
/*
 * Copyright 2014 Yaroslav Mytkalyk
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.docd.purefm.test;




/**
 * Tests {@link com.docd.purefm.utils.StatFsCompat}
 *
 * @author Doctoror
 */
public final class StatFsCompatTest extends AndroidTestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        final String state = Environment.getExternalStorageState();
        if (!state.equals(Environment.MEDIA_MOUNTED) && !state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
            throw new RuntimeException("Make sure the external storage is mounted before running this test");
        }
    }

    @Override
    protected void runTest() throws Throwable {
        super.runTest();
        final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
        final StatFs statFs = new StatFs(path);
// Path: purefm/src/main/java/com/docd/purefm/utils/StatFsCompat.java
// public final class StatFsCompat {
// 
//     /**
//      * StatFs instance
//      */
//     @NonNull
//     private final StatFs mStatFs;
// 
//     /**
//      * Construct a new StatFs for looking at the stats of the filesystem at
//      * {@code path}. Upon construction, the stat of the file system will be
//      * performed, and the values retrieved available from the methods on this
//      * class.
//      *
//      * @param path path in the desired file system to stat.
//      */
//     public StatFsCompat(@NonNull final String path) {
//         this.mStatFs = new StatFs(path);
//     }
// 
//     /**
//      * The number of blocks that are free on the file system and available to
//      * applications. This corresponds to the Unix {@code statvfs.f_bavail} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getAvailableBlocksLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getAvailableBlocksLong();
//         } else {
//             return mStatFs.getAvailableBlocks();
//         }
//     }
// 
//     /**
//      * The total number of blocks on the file system. This corresponds to the
//      * Unix {@code statvfs.f_blocks} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getBlockCountLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getBlockCountLong();
//         } else {
//             return mStatFs.getBlockCount();
//         }
//     }
// 
//     /**
//      * The size, in bytes, of a block on the file system. This corresponds to
//      * the Unix {@code statvfs.f_bsize} field.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getBlockSizeLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getBlockSizeLong();
//         } else {
//             return mStatFs.getBlockSize();
//         }
//     }
// 
//     /**
//      * The total number of blocks that are free on the file system, including
//      * reserved blocks (that are not available to normal applications). This
//      * corresponds to the Unix {@code statvfs.f_bfree} field. Most applications
//      * will want to use {@link #getAvailableBlocksLong()} instead.
//      */
//     @SuppressLint("NewApi")
//     @SuppressWarnings("deprecation")
//     public long getFreeBlocksLong() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getFreeBlocksLong();
//         } else {
//             return mStatFs.getFreeBlocks();
//         }
//     }
// 
//     /**
//      * The number of bytes that are free on the file system and available to
//      * applications.
//      */
//     @SuppressLint("NewApi")
//     public long getAvailableBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getAvailableBytes();
//         } else {
//             return getAvailableBlocksLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * The number of bytes that are free on the file system, including reserved
//      * blocks (that are not available to normal applications). Most applications
//      * will want to use {@link #getAvailableBytes()} instead.
//      */
//     @SuppressLint("NewApi")
//     public long getFreeBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getFreeBytes();
//         } else {
//             return getFreeBlocksLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * The total number of bytes supported by the file system.
//      */
//     public long getTotalBytes() {
//         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
//             return mStatFs.getTotalBytes();
//         } else {
//             return getBlockCountLong() * getBlockSizeLong();
//         }
//     }
// 
//     /**
//      * Perform a restat of the file system referenced by this object. This is
//      * the same as re-constructing the object with the same file system path,
//      * and the new stat values are available upon return.
//      */
//     public void restat(@NonNull final String path) {
//         mStatFs.restat(path);
//     }
// }


// Path: purefm/src/androidTest/java/com/docd/purefm/test/StatFsCompatTest.java
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.test.AndroidTestCase;
import com.docd.purefm.utils.StatFsCompat;
import android.support.annotation.NonNull;

/*
 * Copyright 2014 Yaroslav Mytkalyk
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.docd.purefm.test;




/**
 * Tests {@link com.docd.purefm.utils.StatFsCompat}
 *
 * @author Doctoror
 */
public final class StatFsCompatTest extends AndroidTestCase {

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        final String state = Environment.getExternalStorageState();
        if (!state.equals(Environment.MEDIA_MOUNTED) && !state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
            throw new RuntimeException("Make sure the external storage is mounted before running this test");
        }
    }

    @Override
    protected void runTest() throws Throwable {
        super.runTest();
        final String path = Environment.getExternalStorageDirectory().getAbsolutePath();
        final StatFs statFs = new StatFs(path);
        final StatFsCompat statFsCompat = new StatFsCompat(path);