lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vladimir Djuzhev" <>
Subject Problem: final modifier (e.g. Document) prevents Mocked Unit Tests
Date Fri, 01 Aug 2003 13:22:58 GMT

  We are developing a large corporate site, and decided to
  integrate Lucene as search engine. Everything goes fine,
  until we go into writing unit tests. 

  We heavily use Mocks for unit tests. It would be especially
  useful for Lucene since any test performing indexing over
  real data would take unappropriate time.

  For those who do not familiar with the concept, I'll explain
  briefly how the Mocks work: you disconnect object under test
  from all it's links by replacing all links (member objects,
  passing parameters etc) with objects that has the same (sub)type
  as unlinked object, but are really configurable fake of it. Now
  you can test the logic of the object with no interference and
  much faster (orders of magnitute in execution speed! It's valueable
  when you run UTs ten or twenty times a day!). 

    // dozen: unlinked version of Crawler for tests
    public static class MockedCrawler extends Crawler {

        public MockedCrawler(String baseIndexDir, List indexers) {
            super(baseIndexDir, indexers);

        // overwrite real method to return Mock and configure it        
        protected IndexBuilder getIndexBuilder(boolean odd) {
            MockIndexBuilder mib = new MockIndexBuilder(".");
            return mib;

  For more information see, there are
  a lot of documentations and links to Mock generators.

  The only way to make Mock to be of the same class as original
  is to inherite from the original. That's what is impossible with the
  current Lucene -- a lot of classes has final, a lot of methods has
  final too. Right now I would like to mock IndexWriter, Document
  and Field to test my IndexBuilder logic, but I can't. Sad.

  Personally, I misbelief in final modifier. When someone extends
  the class he shall know what he does, and if he does something
  bad, it's his own fault. But making code untestable brings much
  more danger, IMHO.

  May I ask Lucene development team to remove final modifiers from
  the code? ;)


View raw message