HDFSFileObject extends AbstractFileObject { @Override protected FileType doGetType() throws Exception { HadoopFileStatus status = null; try { status = hdfs.getFileStatus( hdfs.getPath( getName().getPath() ) ); } catch ( Exception ex ) { } if ( status == null ) { return FileType.IMAGINARY; } else if ( status.isDir() ) { return FileType.FOLDER; } else { return FileType.FILE; } } HDFSFileObject( final AbstractFileName name, final HDFSFileSystem fileSystem ); @Override void doCreateFolder(); @Override void doDelete();  }
@Test public void testDoGetTypeFile() throws Exception { HadoopFileStatus hadoopFileStatus = mock( HadoopFileStatus.class ); when( hadoopFileSystem.getFileStatus( hadoopFileSystemPath ) ).thenReturn( hadoopFileStatus ); when( hadoopFileStatus.isDir() ).thenReturn( false ); assertEquals( FileType.FILE, hdfsFileObject.doGetType() ); }
@Test public void testDoGetTypeFolder() throws Exception { HadoopFileStatus hadoopFileStatus = mock( HadoopFileStatus.class ); when( hadoopFileSystem.getFileStatus( hadoopFileSystemPath ) ).thenReturn( hadoopFileStatus ); when( hadoopFileStatus.isDir() ).thenReturn( true ); assertEquals( FileType.FOLDER, hdfsFileObject.doGetType() ); }
@Test public void testDoGetTypeImaginary() throws Exception { assertEquals( FileType.IMAGINARY, hdfsFileObject.doGetType() ); }