Erik,

Erik,

> > public class LuceneSearchService implements SearchService {
> >     private static final String INDEX_FILE_PATH = "index";
> >     private Context context = new DefaultContext();
> >
> >     public void setContext(Context c) {
> >         this.context = c;
> >     }
> >
> > public void index(String componentId, String componentDescription)
> > throws
> > SearchService.Exception {
> >         IndexWriter writer = null;
> >         try {
> >             writer = context.createIndexWriter(INDEX_FILE_PATH, new
> > StandardAnalyzer(), !indexExists());
>
> Take this a step further, and have a createDirectory instead, that can
> return a RAMDirectory.  Forget about a MockIndexWriter.  Trust me :)

I understand what you are saying here, it is a good point and I will try to
work it into what I am doing.  But installing a createDirectory() method and
using a RAMDirectory will not help me verify() that IndexWriter.close() is
called when an IOException is thrown.  MockIndexWriter gives me more
control.

> You just aren't seeing the forest from the trees here.  You need to
> refactor and just let IndexWriter be internal and not mocked, but how
> you get at a Directory be flexible for testing.  Even if you always use
> a file system directory even for testing, I highly recommend you bind
> to abstractions not concreteness.  Bind to Directory, not IndexWriter
> as your "interface".

Yes, I will do this.  Its is more flexible for sure.  But I still need
MockIndexWriter for the control I talk about above.

Cheers,
Mike.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to