GeoUtils { public static File getReferenceLayerFile(Bundle config, StoragePathProvider storagePathProvider) { String path = storagePathProvider.getAbsoluteOfflineMapLayerPath(config.getString(KEY_REFERENCE_LAYER)); return path != null && new File(path).exists() ? new File(path) : null; } private  GeoUtils(); static String formatLocationResultString(Location location); static String capitalizeGps(String locationProvider); static File getReferenceLayerFile(Bundle config, StoragePathProvider storagePathProvider);  }
@Test public void whenPathIsNull_should_getReferenceLayerFileReturnNull() { Bundle config = mock(Bundle.class); StoragePathProvider storagePathProvider = mock(StoragePathProvider.class); when(storagePathProvider.getAbsoluteOfflineMapLayerPath(any())).thenReturn(null); assertNull(GeoUtils.getReferenceLayerFile(config, storagePathProvider)); }
@Test public void whenOfflineLayerFileDoesNotExist_should_getReferenceLayerFileReturnNull() { Bundle config = mock(Bundle.class); StoragePathProvider storagePathProvider = mock(StoragePathProvider.class); when(storagePathProvider.getAbsoluteOfflineMapLayerPath(any())).thenReturn("/storage/emulated/0/odk/layers/MapBox_Demo_Layer/demo_layers.mbtiles"); assertNull(GeoUtils.getReferenceLayerFile(config, storagePathProvider)); }
@Test public void whenOfflineLayerFileExist_should_getReferenceLayerFileReturnThatFile() { File file = new File(new StoragePathProvider().getAbsoluteOfflineMapLayerPath("MapBox_Demo_Layer/demo_layers.mbtiles")); FileUtils.write(file, new byte[] {}); Bundle config = mock(Bundle.class); StoragePathProvider storagePathProvider = mock(StoragePathProvider.class); when(storagePathProvider.getAbsoluteOfflineMapLayerPath(any())).thenReturn(file.getAbsolutePath()); assertNotNull(GeoUtils.getReferenceLayerFile(config, storagePathProvider)); }