test_class.file: app/src/test/java/org/jak_linux/dns66/db/RuleDatabaseTest.java
test_class.identifier: RuleDatabaseTest
test_case.body: @Test
      public void testLoadReader() throws Exception {
          RuleDatabase db = new RuleDatabase();
          db.nextBlockedHosts = db.blockedHosts.get();
  
          Configuration.Item item = new Configuration.Item();
  
          item.location = "<some random file>";
          item.state = Configuration.Item.STATE_IGNORE;
  
          // Ignore. Does nothing
          assertTrue(db.loadReader(item, new StringReader("example.com")));
          assertTrue(db.isEmpty());
          assertFalse(db.isBlocked("example.com"));
  
          // Deny, the host should be blocked now.
          item.state = Configuration.Item.STATE_DENY;
          assertTrue(db.loadReader(item, new StringReader("example.com")));
          assertFalse(db.isEmpty());
          assertTrue(db.isBlocked("example.com"));
  
          // Reallow again, the entry should disappear.
          item.state = Configuration.Item.STATE_ALLOW;
          assertTrue(db.loadReader(item, new StringReader("example.com")));
          assertTrue(db.isEmpty());
          assertFalse(db.isBlocked("example.com"));
  
          // Check multiple lines
          item.state = Configuration.Item.STATE_DENY;
          assertFalse(db.isBlocked("example.com"));
          assertFalse(db.isBlocked("foo.com"));
          assertTrue(db.loadReader(item, new StringReader("example.com\n127.0.0.1 foo.com")));
          assertFalse(db.isEmpty());
          assertTrue(db.isBlocked("example.com"));
          assertTrue(db.isBlocked("foo.com"));
  
          // Interrupted test
          Thread.currentThread().interrupt();
          try {
              db.loadReader(item, new StringReader("example.com"));
              fail("Interrupted thread did not cause reader to be interrupted");
          } catch (InterruptedException e) {
  
          }
  
          // Test with an invalid line before a valid one.
          item.state = Configuration.Item.STATE_DENY;
          assertTrue(db.loadReader(item, new StringReader("invalid line\notherhost.com")));
          assertTrue(db.isBlocked("otherhost.com"));
  
          // Allow again
          item.state = Configuration.Item.STATE_ALLOW;
          assertTrue(db.loadReader(item, new StringReader("invalid line\notherhost.com")));
          assertFalse(db.isBlocked("otherhost.com"));
  
          // Reader can't read, we are aborting.
          Reader reader = Mockito.mock(Reader.class);
          doThrow(new IOException()).when(reader).read((char[]) any());
          doThrow(new IOException()).when(reader).read((char[]) any(), anyInt(), anyInt());
          doThrow(new IOException()).when(reader).read(any(CharBuffer.class));
  
          assertFalse(db.loadReader(item, reader));
      }
test_case.class_method_signature: RuleDatabaseTest.testLoadReader()
test_case.full_signature: @Test public void testLoadReader()
test_case.identifier: testLoadReader
test_case.invocations: get assertTrue loadReader assertTrue isEmpty assertFalse isBlocked assertTrue loadReader assertFalse isEmpty assertTrue isBlocked assertTrue loadReader assertTrue isEmpty assertFalse isBlocked assertFalse isBlocked assertFalse isBlocked assertTrue loadReader assertFalse isEmpty assertTrue isBlocked assertTrue isBlocked interrupt currentThread loadReader fail assertTrue loadReader assertTrue isBlocked assertTrue loadReader assertFalse isBlocked mock read when doThrow any read when doThrow any anyInt anyInt read when doThrow any assertFalse loadReader
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testLoadReader()
focal_class.declarator: TAG = "RuleDatabase"
focal_class.modifier: private static final
focal_class.original_string: private static final String TAG = "RuleDatabase";
focal_class.type: String
focal_class.var_name: TAG
focal_class.declarator: instance = new RuleDatabase()
focal_class.modifier: private static final
focal_class.original_string: private static final RuleDatabase instance = new RuleDatabase();
focal_class.type: RuleDatabase
focal_class.var_name: instance
focal_class.declarator: blockedHosts = new AtomicReference<>(new HashSet<String>())
focal_class.modifier: final
focal_class.original_string: final AtomicReference<HashSet<String>> blockedHosts = new AtomicReference<>(new HashSet<String>());
focal_class.type: AtomicReference<HashSet<String>>
focal_class.var_name: blockedHosts
focal_class.declarator: nextBlockedHosts = null
focal_class.original_string: HashSet<String> nextBlockedHosts = null;
focal_class.type: HashSet<String>
focal_class.var_name: nextBlockedHosts
focal_class.file: app/src/main/java/org/jak_linux/dns66/db/RuleDatabase.java
focal_class.identifier: RuleDatabase
focal_class.class_method_signature: RuleDatabase.RuleDatabase()
focal_class.full_signature:   RuleDatabase()
focal_class.identifier: RuleDatabase
focal_class.parameters: ()
focal_class.signature:  RuleDatabase()
focal_class.class_method_signature: RuleDatabase.getInstance()
focal_class.full_signature: public static RuleDatabase getInstance()
focal_class.identifier: getInstance
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: RuleDatabase
focal_class.signature: RuleDatabase getInstance()
focal_class.class_method_signature: RuleDatabase.parseLine(String line)
focal_class.full_signature: @Nullable static String parseLine(String line)
focal_class.identifier: parseLine
focal_class.modifiers: @Nullable static
focal_class.parameters: (String line)
focal_class.return: String
focal_class.signature: String parseLine(String line)
focal_class.class_method_signature: RuleDatabase.isBlocked(String host)
focal_class.full_signature: public boolean isBlocked(String host)
focal_class.identifier: isBlocked
focal_class.modifiers: public
focal_class.parameters: (String host)
focal_class.return: boolean
focal_class.signature: boolean isBlocked(String host)
focal_class.class_method_signature: RuleDatabase.isEmpty()
focal_class.full_signature:  boolean isEmpty()
focal_class.identifier: isEmpty
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean isEmpty()
focal_class.class_method_signature: RuleDatabase.initialize(Context context)
focal_class.full_signature: public synchronized void initialize(Context context)
focal_class.identifier: initialize
focal_class.modifiers: public synchronized
focal_class.parameters: (Context context)
focal_class.return: void
focal_class.signature: void initialize(Context context)
focal_class.class_method_signature: RuleDatabase.loadItem(Context context, Configuration.Item item)
focal_class.full_signature: private void loadItem(Context context, Configuration.Item item)
focal_class.identifier: loadItem
focal_class.modifiers: private
focal_class.parameters: (Context context, Configuration.Item item)
focal_class.return: void
focal_class.signature: void loadItem(Context context, Configuration.Item item)
focal_class.class_method_signature: RuleDatabase.addHost(Configuration.Item item, String host)
focal_class.full_signature: private void addHost(Configuration.Item item, String host)
focal_class.identifier: addHost
focal_class.modifiers: private
focal_class.parameters: (Configuration.Item item, String host)
focal_class.return: void
focal_class.signature: void addHost(Configuration.Item item, String host)
focal_class.class_method_signature: RuleDatabase.loadReader(Configuration.Item item, Reader reader)
focal_class.full_signature:  boolean loadReader(Configuration.Item item, Reader reader)
focal_class.identifier: loadReader
focal_class.parameters: (Configuration.Item item, Reader reader)
focal_class.return: boolean
focal_class.signature: boolean loadReader(Configuration.Item item, Reader reader)
focal_method.body: boolean loadReader(Configuration.Item item, Reader reader) throws InterruptedException {
          int count = 0;
          try {
              Log.d(TAG, "loadBlockedHosts: Reading: " + item.location);
              try (BufferedReader br = new BufferedReader(reader)) {
                  String line;
                  while ((line = br.readLine()) != null) {
                      if (Thread.interrupted())
                          throw new InterruptedException("Interrupted");
                      String host = parseLine(line);
                      if (host != null) {
                          count += 1;
                          addHost(item, host);
                      }
                  }
              }
              Log.d(TAG, "loadBlockedHosts: Loaded " + count + " hosts from " + item.location);
              return true;
          } catch (IOException e) {
              Log.e(TAG, "loadBlockedHosts: Error while reading " + item.location + " after " + count + " items", e);
              return false;
          } finally {
              FileHelper.closeOrWarn(reader, TAG, "loadBlockedHosts: Error closing " + item.location);
          }
      }
focal_method.class_method_signature: RuleDatabase.loadReader(Configuration.Item item, Reader reader)
focal_method.full_signature:  boolean loadReader(Configuration.Item item, Reader reader)
focal_method.identifier: loadReader
focal_method.invocations: d readLine interrupted parseLine addHost d e closeOrWarn
focal_method.parameters: (Configuration.Item item, Reader reader)
focal_method.return: boolean
focal_method.signature: boolean loadReader(Configuration.Item item, Reader reader)