OrnidroidIOServiceImpl implements IOrnidroidIOService { public void checkOrnidroidHome(final String ornidroidHome) throws OrnidroidException { final File fileOrnidroidHome = new File(ornidroidHome); if (!fileOrnidroidHome.exists()) { checkAndCreateDirectory(fileOrnidroidHome); } checkAndCreateDirectory(new File(ornidroidHome + File.separator + BasicConstants.IMAGES_DIRECTORY)); checkAndCreateDirectory(new File(ornidroidHome + File.separator + BasicConstants.AUDIO_DIRECTORY)); } OrnidroidIOServiceImpl(); void addCustomMediaFile(final String birdDirectory,
			final OrnidroidFileType fileType, final String selectedFileName,
			final File selectedFile, final String comment); void checkAndCreateDirectory(final File fileDirectory); void checkOrnidroidHome(final String ornidroidHome); void downloadMediaFiles(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); List<String> filesToUpdate(final String mediaHomeDirectory,
			final Bird bird, final OrnidroidFileType fileType); void loadMediaFiles(final String fileDirectory, final Bird bird,
			final OrnidroidFileType fileType); void removeCustomMediaFile(final OrnidroidFile ornidroidFile); @Override void resetExistingDirectory(File directoryToReset); void downloadZipPackage(String zipname, String mediaHomeDirectory); boolean isEnoughFreeSpace(OrnidroidFileType fileType); ZipPackage getZipname(OrnidroidFileType fileType); int getZipDownloadProgressPercent(OrnidroidFileType fileType,
			int folderSizeBeforeDownload); int getInstallProgressPercent(OrnidroidFileType fileType);  }
@Test public void testCheckOrnidroidHomeExistingAndEmptyDirectory() throws OrnidroidException { final File ornidroidHome = new File(TEST_DIRECTORY); Assert.assertTrue(ornidroidHome.exists()); final File ornidroidHomeImages = new File(TEST_DIRECTORY + File.separator + BasicConstants.IMAGES_DIRECTORY); Assert.assertFalse(ornidroidHomeImages.exists()); final File ornidroidHomeAudio = new File(TEST_DIRECTORY + File.separator + BasicConstants.AUDIO_DIRECTORY); Assert.assertFalse(ornidroidHomeAudio.exists()); this.ornidroidIOService.checkOrnidroidHome(TEST_DIRECTORY); Assert.assertTrue(ornidroidHomeImages.exists()); Assert.assertTrue(ornidroidHomeAudio.exists()); }
@Test public void testCheckOrnidroidHomeExistingAndExistingSubdirectories() throws OrnidroidException { testCheckOrnidroidHomeExistingAndEmptyDirectory(); final File ornidroidHomeImages = new File(TEST_DIRECTORY + File.separator + BasicConstants.IMAGES_DIRECTORY); final File ornidroidHomeAudio = new File(TEST_DIRECTORY + File.separator + BasicConstants.AUDIO_DIRECTORY); this.ornidroidIOService.checkOrnidroidHome(TEST_DIRECTORY); Assert.assertTrue(ornidroidHomeImages.exists()); Assert.assertTrue(ornidroidHomeAudio.exists()); }
@Test public void testCheckOrnidroidHomeNonExistingDirectory() throws OrnidroidException { final String ornidroidHomePath = TEST_DIRECTORY + File.separator + "unexistingDirectory"; final File ornidroidHome = new File(ornidroidHomePath); Assert.assertFalse(ornidroidHome.exists()); final File ornidroidHomeImages = new File(ornidroidHomePath + File.separator + BasicConstants.IMAGES_DIRECTORY); Assert.assertFalse(ornidroidHomeImages.exists()); final File ornidroidHomeAudio = new File(ornidroidHomePath + File.separator + BasicConstants.AUDIO_DIRECTORY); Assert.assertFalse(ornidroidHomeAudio.exists()); this.ornidroidIOService.checkOrnidroidHome(ornidroidHomePath); Assert.assertTrue(ornidroidHome.exists()); Assert.assertTrue(ornidroidHomeImages.exists()); Assert.assertTrue(ornidroidHomeAudio.exists()); }
@Test public void testCheckOrnidroidHomeNoRightsToWrite() { final File ornidroidHome = new File(TEST_DIRECTORY); ornidroidHome.setReadOnly(); try { this.ornidroidIOService.checkOrnidroidHome(TEST_DIRECTORY); Assert.fail("an exception should have occurred"); } catch (final OrnidroidException e) { Assert.assertTrue("ok, normal exception", true); } }