Search in sources :

Example 1 with FileUtils

use of io.flutter.utils.FileUtils in project flutter-intellij by flutter.

the class JxBrowserManagerTest method testSetUpIfAllFilesExist.

@Test
public void testSetUpIfAllFilesExist() throws FileNotFoundException {
    final JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
    when(mockUtils.getJxBrowserKey()).thenReturn("KEY");
    when(mockUtils.getPlatformFileName()).thenReturn(PLATFORM_FILE_NAME);
    when(mockUtils.getApiFileName()).thenReturn(API_FILE_NAME);
    when(mockUtils.getSwingFileName()).thenReturn(SWING_FILE_NAME);
    final FileUtils mockFileUtils = mock(FileUtils.class);
    when(mockFileUtils.makeDirectory(DOWNLOAD_PATH)).thenReturn(true);
    when(mockFileUtils.fileExists(anyString())).thenReturn(true);
    // If all of the files are already downloaded, we should load the existing files.
    final JxBrowserManager manager = new JxBrowserManager(mockUtils, mockAnalytics, mockFileUtils);
    manager.setUp(mockProject);
    final String[] expectedFileNames = { PLATFORM_FILE_NAME, API_FILE_NAME, SWING_FILE_NAME };
    Assert.assertEquals(JxBrowserStatus.INSTALLED, manager.getStatus());
}
Also used : FileUtils(io.flutter.utils.FileUtils) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with FileUtils

use of io.flutter.utils.FileUtils in project flutter-intellij by flutter.

the class JxBrowserManagerTest method testSetUpIfFilesMissing.

@Test
public void testSetUpIfFilesMissing() throws FileNotFoundException {
    System.out.println("in testSetUpIfFilesMissing");
    final JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
    when(mockUtils.getJxBrowserKey()).thenReturn("KEY");
    when(mockUtils.getPlatformFileName()).thenReturn(PLATFORM_FILE_NAME);
    when(mockUtils.getApiFileName()).thenReturn(API_FILE_NAME);
    when(mockUtils.getSwingFileName()).thenReturn(SWING_FILE_NAME);
    final FileUtils mockFileUtils = mock(FileUtils.class);
    when(mockFileUtils.makeDirectory(DOWNLOAD_PATH)).thenReturn(true);
    when(mockFileUtils.fileExists(PLATFORM_FILE_NAME)).thenReturn(true);
    when(mockFileUtils.fileExists(API_FILE_NAME)).thenReturn(false);
    when(mockFileUtils.fileExists(SWING_FILE_NAME)).thenReturn(true);
    when(mockFileUtils.deleteFile(anyString())).thenReturn(true);
    // If any of our required files do not exist, we want to delete any existing files and start a download of all of the required files.
    final JxBrowserManager manager = new JxBrowserManager(mockUtils, mockAnalytics, mockFileUtils);
    final JxBrowserManager spy = spy(manager);
    final String[] expectedFileNames = { PLATFORM_FILE_NAME, API_FILE_NAME, SWING_FILE_NAME };
    doNothing().when(spy).downloadJxBrowser(mockProject, expectedFileNames);
    System.out.println("using spy");
    spy.setUp(mockProject);
    verify(mockFileUtils, times(1)).deleteFile(DOWNLOAD_PATH + File.separatorChar + PLATFORM_FILE_NAME);
    verify(mockFileUtils, times(1)).deleteFile(DOWNLOAD_PATH + File.separatorChar + API_FILE_NAME);
    verify(mockFileUtils, times(1)).deleteFile(DOWNLOAD_PATH + File.separatorChar + SWING_FILE_NAME);
    verify(spy, times(1)).downloadJxBrowser(mockProject, expectedFileNames);
}
Also used : FileUtils(io.flutter.utils.FileUtils) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with FileUtils

use of io.flutter.utils.FileUtils in project flutter-intellij by flutter.

the class JxBrowserManagerTest method testSetUpIfPlatformFileNotFound.

@Test
public void testSetUpIfPlatformFileNotFound() throws FileNotFoundException {
    final JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
    when(mockUtils.getJxBrowserKey()).thenReturn("KEY");
    when(mockUtils.getPlatformFileName()).thenThrow(new FileNotFoundException());
    final FileUtils mockFileUtils = mock(FileUtils.class);
    when(mockFileUtils.makeDirectory(DOWNLOAD_PATH)).thenReturn(true);
    // If the system platform is not found among JxBrowser files, then the installation should fail.
    final JxBrowserManager manager = new JxBrowserManager(mockUtils, mockAnalytics, mockFileUtils);
    manager.setUp(mockProject);
    Assert.assertEquals(JxBrowserStatus.INSTALLATION_FAILED, manager.getStatus());
}
Also used : FileUtils(io.flutter.utils.FileUtils) FileNotFoundException(java.io.FileNotFoundException) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) Test(org.junit.Test)

Example 4 with FileUtils

use of io.flutter.utils.FileUtils in project flutter-intellij by flutter.

the class JxBrowserManagerTest method testSetUpIfDirectoryFails.

@Test
public void testSetUpIfDirectoryFails() throws FileNotFoundException {
    final JxBrowserUtils mockUtils = mock(JxBrowserUtils.class);
    when(mockUtils.getJxBrowserKey()).thenReturn("KEY");
    final FileUtils mockFileUtils = mock(FileUtils.class);
    when(mockFileUtils.makeDirectory(DOWNLOAD_PATH)).thenReturn(false);
    // If the directory for JxBrowser files cannot be created, the installation should fail.
    final JxBrowserManager manager = new JxBrowserManager(mockUtils, mockAnalytics, mockFileUtils);
    manager.setUp(mockProject);
    Assert.assertEquals(JxBrowserStatus.INSTALLATION_FAILED, manager.getStatus());
}
Also used : FileUtils(io.flutter.utils.FileUtils) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) Test(org.junit.Test)

Aggregations

FileUtils (io.flutter.utils.FileUtils)4 JxBrowserUtils (io.flutter.utils.JxBrowserUtils)4 Test (org.junit.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 FileNotFoundException (java.io.FileNotFoundException)1