Examples of MockControl


Examples of org.easymock.MockControl

    assertTrue(called[1]);
  }

  final public void testAddDocumentWithManagerAndNameError() throws Exception {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
    IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
    MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
    LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();

    DefaultDocumentHandlerManager manager=new DefaultDocumentHandlerManager();

    //Object to index
    final String text="a text";

    //document
    final Document document = new Document();
    document.add(new Field("text", text, Field.Store.YES, Field.Index.TOKENIZED));

    final boolean[] called = {false, false};
    manager.registerDocumentHandler(new IdentityDocumentMatching("text1"), new AbstractDocumentHandler() {
      public boolean supports(Class clazz) {
        called[0] = true;
        return true;
      }

      protected Document doGetDocument(Map description, Object object) throws Exception {
        called[1] = true;
        return document;
      }
    });
   
    indexFactoryControl.replay();
    indexWriterControl.replay();

    try {
      //Lucene template
      LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory, analyzer);
      template.addDocument(new DocumentCreatorWithManager(manager, "text", text));
      fail();
    } catch(Exception ex) {
      //Check if a writer has been opened
      //Check if the writer calls the addDocument method
      //Check if the writer of the template is closed
      indexFactoryControl.verify();
      indexWriterControl.verify();
     
      //Check if the writer calls the getResourceName, getResourceDescription and
      //createInputStream methods
      assertFalse(called[0]);
      assertFalse(called[1]);
View Full Code Here

Examples of org.easymock.MockControl

    }
  }

  final public void testAddDocuments() throws Exception {
    SimpleAnalyzer analyzer = new SimpleAnalyzer();
    MockControl indexFactoryControl = MockControl.createStrictControl(IndexFactory.class);
    IndexFactory indexFactory = (IndexFactory)indexFactoryControl.getMock();
    MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
    LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
    MockControl documentsCreatorControl = MockControl.createStrictControl(DocumentsCreator.class);
    DocumentsCreator documentsCreator = (DocumentsCreator)documentsCreatorControl.getMock();
   
    //documents
    List documents = new ArrayList();
    Document document1 = new Document();
    document1.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document1.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document1.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
    documents.add(document1);

    indexFactory.getIndexWriter();
    indexFactoryControl.setReturnValue(indexWriter, 1);
   
    documentsCreator.createDocuments();
    documentsCreatorControl.setReturnValue(documents, 1);
   
    indexWriter.addDocument(document1);
    indexWriterControl.setVoidCallable();
   
    indexWriter.close();
    indexWriterControl.setVoidCallable(1);
   
    indexFactoryControl.replay();
    indexWriterControl.replay();
    documentsCreatorControl.replay();
   
    //Lucene template
    LuceneIndexTemplate template = new DefaultLuceneIndexTemplate(indexFactory,analyzer);
    template.addDocuments(documentsCreator);

    indexFactoryControl.verify();
    indexWriterControl.verify();
    documentsCreatorControl.verify();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.