FileHelper { public static InputStream openRead(Context context, String filename) throws IOException { try { return context.openFileInput(filename); } catch (FileNotFoundException e) { return context.getAssets().open(filename); } }  static InputStream openRead(Context context, String filename); static OutputStream openWrite(Context context, String filename); static Configuration loadCurrentSettings(Context context); static Configuration loadPreviousSettings(Context context); static Configuration loadDefaultSettings(Context context); static void writeSettings(Context context, Configuration config); static File getItemFile(Context context, Configuration.Item item); static InputStreamReader openItemFile(Context context, Configuration.Item item); static int poll(StructPollfd[] fds, int timeout); static FileDescriptor closeOrWarn(FileDescriptor fd, String tag, String message); static T closeOrWarn(T fd, String tag, String message);  }
@Test public void testOpenRead_existingFile() throws Exception { FileInputStream stream = mock(FileInputStream.class); when(mockContext.openFileInput(anyString())).thenReturn(stream); when(mockAssets.open(anyString())).thenThrow(new IOException()); assertSame(stream, FileHelper.openRead(mockContext, "file")); }
@Test public void testOpenRead_fallbackToAsset() throws Exception { FileInputStream stream = mock(FileInputStream.class); when(mockContext.openFileInput(anyString())).thenThrow(new FileNotFoundException("Test")); when(mockAssets.open(anyString())).thenReturn(stream); assertSame(stream, FileHelper.openRead(mockContext, "file")); }