Only search valid directories. Add a test to verify this.

Instead of expecting the calling code to only add valid paths to search,
we now verify that the paths are valid.

Change-Id: I06db9a1934723056f6ab41ac590e8af0eb91c455
Merge branch 'more_robust_factory'

Change-Id: Ic442b9926b15174cb2693705068059b55518ffe4