Java Code Examples for org.apache.lucene.util.LuceneTestCase#expectThrows()

The following examples show how to use org.apache.lucene.util.LuceneTestCase#expectThrows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomPostingsTester.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testFields(Fields fields) throws Exception {
  Iterator<String> iterator = fields.iterator();
  while (iterator.hasNext()) {
    iterator.next();
    try {
      iterator.remove();
      throw new AssertionError("Fields.iterator() allows for removal");
    } catch (UnsupportedOperationException expected) {
      // expected;
    }
  }
  assertFalse(iterator.hasNext());
  LuceneTestCase.expectThrows(NoSuchElementException.class, () -> {
    iterator.next();
  });
}
 
Example 2
Source File: TestByteBuffersDataInput.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSanity() throws IOException {
  ByteBuffersDataOutput out = new ByteBuffersDataOutput();
  ByteBuffersDataInput o1 = out.toDataInput();
  assertEquals(0, o1.size());
  LuceneTestCase.expectThrows(EOFException.class, () -> {
      o1.readByte();
  });

  out.writeByte((byte) 1);

  ByteBuffersDataInput o2 = out.toDataInput();
  assertEquals(1, o2.size());
  assertEquals(0, o2.position());
  assertEquals(0, o1.size());

  assertTrue(o2.ramBytesUsed() > 0);
  assertEquals(1, o2.readByte());
  assertEquals(1, o2.position());
  assertEquals(1, o2.readByte(0));

  LuceneTestCase.expectThrows(EOFException.class, () -> {
      o2.readByte();
  });

  assertEquals(1, o2.position());
}
 
Example 3
Source File: TestByteBuffersDataInput.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSeekEmpty() throws Exception {
  ByteBuffersDataOutput dst = new ByteBuffersDataOutput();
  ByteBuffersDataInput in = dst.toDataInput();
  in.seek(0);

  LuceneTestCase.expectThrows(EOFException.class, () -> {
    in.seek(1);
  });

  in.seek(0);
  LuceneTestCase.expectThrows(EOFException.class, () -> {
    in.readByte();
  });
}
 
Example 4
Source File: TestCoreParser.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void test_DOCTYPE_TermQueryXML() throws ParserException, IOException {
  SAXException saxe = LuceneTestCase.expectThrows(ParserException.class, SAXException.class,
      () -> parse("DOCTYPE_TermQuery.xml"));
  assertTrue(saxe.getMessage().startsWith("External Entity resolving unsupported:"));
}
 
Example 5
Source File: TestCoreParser.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void test_ENTITY_TermQueryXML() throws ParserException, IOException {
  SAXException saxe = LuceneTestCase.expectThrows(ParserException.class, SAXException.class,
      () -> parse("ENTITY_TermQuery.xml"));
  assertTrue(saxe.getMessage().startsWith("External Entity resolving unsupported:"));
}