test_class.declarator: mockContext
test_class.modifier: private
test_class.original_string: private Context mockContext;
test_class.type: Context
test_class.var_name: mockContext
test_class.declarator: file
test_class.modifier: private
test_class.original_string: private File file;
test_class.type: File
test_class.var_name: file
test_class.declarator: singleWriterMultipleReaderFile
test_class.modifier: private
test_class.original_string: private SingleWriterMultipleReaderFile singleWriterMultipleReaderFile;
test_class.type: SingleWriterMultipleReaderFile
test_class.var_name: singleWriterMultipleReaderFile
test_class.declarator: connection
test_class.modifier: private
test_class.original_string: private HttpURLConnection connection;
test_class.type: HttpURLConnection
test_class.var_name: connection
test_class.declarator: finishAnswer
test_class.modifier: private
test_class.original_string: private CountingAnswer finishAnswer;
test_class.type: CountingAnswer
test_class.var_name: finishAnswer
test_class.declarator: failAnswer
test_class.modifier: private
test_class.original_string: private CountingAnswer failAnswer;
test_class.type: CountingAnswer
test_class.var_name: failAnswer
test_class.declarator: url
test_class.modifier: private
test_class.original_string: private URL url;
test_class.type: URL
test_class.var_name: url
test_class.declarator: realTask
test_class.modifier: private
test_class.original_string: private RuleDatabaseUpdateTask realTask;
test_class.type: RuleDatabaseUpdateTask
test_class.var_name: realTask
test_class.declarator: mockTask
test_class.modifier: private
test_class.original_string: private RuleDatabaseUpdateTask mockTask;
test_class.type: RuleDatabaseUpdateTask
test_class.var_name: mockTask
test_class.declarator: mockResolver
test_class.modifier: private
test_class.original_string: private ContentResolver mockResolver;
test_class.type: ContentResolver
test_class.var_name: mockResolver
test_class.file: app/src/test/java/org/jak_linux/dns66/db/RuleDatabaseItemUpdateRunnableTest.java
test_class.identifier: RuleDatabaseItemUpdateRunnableTest
test_case.body: @Test
      public void testDownloadFile() throws Exception {
          RuleDatabaseItemUpdateRunnable itemUpdateRunnable = new RuleDatabaseItemUpdateRunnable(realTask, mockContext, mock(Configuration.Item.class));
  
          byte[] bar = new byte[]{'h', 'a', 'l', 'l', 'o'};
          final ByteArrayInputStream bis = new ByteArrayInputStream(bar);
          final ByteArrayOutputStream bos = new ByteArrayOutputStream();
  
          FileOutputStream fos = mock(FileOutputStream.class);
          when(fos, "write", any(byte[].class), anyInt(), anyInt()).then(new Answer<Void>() {
              @Override
              public Void answer(InvocationOnMock invocation) throws Throwable {
                  byte[] buffer = invocation.getArgumentAt(0, byte[].class);
                  int off = invocation.getArgumentAt(1, Integer.class);
                  int len = invocation.getArgumentAt(2, Integer.class);
  
                  bos.write(buffer, off, len);
                  return null;
              }
          });
  
          when(connection.getInputStream()).thenReturn(bis);
          when(singleWriterMultipleReaderFile.startWrite()).thenReturn(fos);
          itemUpdateRunnable.downloadFile(file, singleWriterMultipleReaderFile, connection);
  
          assertArrayEquals(bar, bos.toByteArray());
          assertEquals(0, failAnswer.numCalls);
          assertEquals(1, finishAnswer.numCalls);
          bis.reset();
          bos.reset();
  
      }
test_case.class_method_signature: RuleDatabaseItemUpdateRunnableTest.testDownloadFile()
test_case.full_signature: @Test public void testDownloadFile()
test_case.identifier: testDownloadFile
test_case.invocations: mock mock then when any anyInt anyInt getArgumentAt getArgumentAt getArgumentAt write thenReturn when getInputStream thenReturn when startWrite downloadFile assertArrayEquals toByteArray assertEquals assertEquals reset reset
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testDownloadFile()
focal_class.declarator: CONNECT_TIMEOUT_MILLIS = 30000
focal_class.modifier: private static final
focal_class.original_string: private static final int CONNECT_TIMEOUT_MILLIS = 30000;
focal_class.type: int
focal_class.var_name: CONNECT_TIMEOUT_MILLIS
focal_class.declarator: READ_TIMEOUT_MILLIS = 10000
focal_class.modifier: private static final
focal_class.original_string: private static final int READ_TIMEOUT_MILLIS = 10000;
focal_class.type: int
focal_class.var_name: READ_TIMEOUT_MILLIS
focal_class.declarator: TAG = "RuleDbItemUpdate"
focal_class.modifier: private static final
focal_class.original_string: private static final String TAG = "RuleDbItemUpdate";
focal_class.type: String
focal_class.var_name: TAG
focal_class.declarator: parentTask
focal_class.original_string: RuleDatabaseUpdateTask parentTask;
focal_class.type: RuleDatabaseUpdateTask
focal_class.var_name: parentTask
focal_class.declarator: item
focal_class.original_string: Configuration.Item item;
focal_class.type: Configuration.Item
focal_class.var_name: item
focal_class.declarator: context
focal_class.original_string: Context context;
focal_class.type: Context
focal_class.var_name: context
focal_class.declarator: url
focal_class.modifier: private
focal_class.original_string: private URL url;
focal_class.type: URL
focal_class.var_name: url
focal_class.declarator: file
focal_class.modifier: private
focal_class.original_string: private File file;
focal_class.type: File
focal_class.var_name: file
focal_class.file: app/src/main/java/org/jak_linux/dns66/db/RuleDatabaseItemUpdateRunnable.java
focal_class.identifier: RuleDatabaseItemUpdateRunnable
focal_class.interfaces: implements Runnable
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.RuleDatabaseItemUpdateRunnable(@NonNull RuleDatabaseUpdateTask parentTask, @NonNull Context context, @NonNull Configuration.Item item)
focal_class.full_signature:   RuleDatabaseItemUpdateRunnable(@NonNull RuleDatabaseUpdateTask parentTask, @NonNull Context context, @NonNull Configuration.Item item)
focal_class.identifier: RuleDatabaseItemUpdateRunnable
focal_class.parameters: (@NonNull RuleDatabaseUpdateTask parentTask, @NonNull Context context, @NonNull Configuration.Item item)
focal_class.signature:  RuleDatabaseItemUpdateRunnable(@NonNull RuleDatabaseUpdateTask parentTask, @NonNull Context context, @NonNull Configuration.Item item)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.shouldDownload()
focal_class.full_signature:  boolean shouldDownload()
focal_class.identifier: shouldDownload
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean shouldDownload()
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.run()
focal_class.full_signature: @Override public void run()
focal_class.identifier: run
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void run()
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.parseUri(String uri)
focal_class.full_signature:  Uri parseUri(String uri)
focal_class.identifier: parseUri
focal_class.parameters: (String uri)
focal_class.return: Uri
focal_class.signature: Uri parseUri(String uri)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.getHttpURLConnection(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, URL url)
focal_class.full_signature: @NonNull HttpURLConnection getHttpURLConnection(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, URL url)
focal_class.identifier: getHttpURLConnection
focal_class.modifiers: @NonNull
focal_class.parameters: (File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, URL url)
focal_class.return: HttpURLConnection
focal_class.signature: HttpURLConnection getHttpURLConnection(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, URL url)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.internalOpenHttpConnection(URL url)
focal_class.full_signature:  HttpURLConnection internalOpenHttpConnection(URL url)
focal_class.identifier: internalOpenHttpConnection
focal_class.parameters: (URL url)
focal_class.return: HttpURLConnection
focal_class.signature: HttpURLConnection internalOpenHttpConnection(URL url)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.validateResponse(HttpURLConnection connection)
focal_class.full_signature:  boolean validateResponse(HttpURLConnection connection)
focal_class.identifier: validateResponse
focal_class.parameters: (HttpURLConnection connection)
focal_class.return: boolean
focal_class.signature: boolean validateResponse(HttpURLConnection connection)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_class.full_signature:  void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_class.identifier: downloadFile
focal_class.parameters: (File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_class.return: void
focal_class.signature: void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_class.class_method_signature: RuleDatabaseItemUpdateRunnable.copyStream(InputStream inStream, OutputStream outStream)
focal_class.full_signature:  void copyStream(InputStream inStream, OutputStream outStream)
focal_class.identifier: copyStream
focal_class.parameters: (InputStream inStream, OutputStream outStream)
focal_class.return: void
focal_class.signature: void copyStream(InputStream inStream, OutputStream outStream)
focal_method.body: void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection) throws IOException {
          InputStream inStream = connection.getInputStream();
          FileOutputStream outStream = singleWriterMultipleReaderFile.startWrite();
  
          try {
              copyStream(inStream, outStream);
  
              singleWriterMultipleReaderFile.finishWrite(outStream);
              outStream = null;
              // Write has started, set modification time.
              if (connection.getLastModified() == 0 || !file.setLastModified(connection.getLastModified())) {
                  Log.d(TAG, "downloadFile: Could not set last modified");
              }
          } finally {
              if (outStream != null)
                  singleWriterMultipleReaderFile.failWrite(outStream);
          }
      }
focal_method.class_method_signature: RuleDatabaseItemUpdateRunnable.downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_method.full_signature:  void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_method.identifier: downloadFile
focal_method.invocations: getInputStream startWrite copyStream finishWrite getLastModified setLastModified getLastModified d failWrite
focal_method.parameters: (File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)
focal_method.return: void
focal_method.signature: void downloadFile(File file, SingleWriterMultipleReaderFile singleWriterMultipleReaderFile, HttpURLConnection connection)