### Question:
PathConverter implements ValueConverter<Path> { @Override public Path convert( String value ) { Path path = Paths.get(value); if ( pathProperties != null ) { for ( PathProperties each : pathProperties ) { if ( !each.accept( path ) ) throw new ValueConversionException( message( each.getMessageKey(), path.toString() ) ); } } return path; } PathConverter( PathProperties... pathProperties ); @Override Path convert( String value ); @Override Class<Path> valueType(); @Override String valuePattern();  }### Answer:
@Test public void convertsValuesToPaths() throws Exception { Path path = Files.createTempFile( "prefix", null ); path.toFile().deleteOnExit(); String pathName = path.toString(); assertEquals( path, new PathConverter( null ).convert( pathName ) ); assertEquals( path, new PathConverter().convert( pathName ) ); }
@Test public void testReadableAndOverwritableFile() throws Exception { Path path = Files.createTempFile( "prefix", null ); path.toFile().deleteOnExit(); String pathName = path.toString(); assertTrue( Files.isReadable( new PathConverter( READABLE ).convert( pathName ) ) ); assertTrue( Files.exists( new PathConverter( READABLE ).convert( pathName ) ) ); assertTrue( Files.isWritable( new PathConverter( READABLE ).convert( pathName ) ) ); assertTrue( Files.isWritable( new PathConverter( FILE_OVERWRITABLE).convert( pathName ) ) ); }
@Test public void testNotExisting() throws Exception { Path path = Files.createTempFile( "prefix", null ); Files.deleteIfExists( path ); assertFalse( Files.exists( new PathConverter( NOT_EXISTING ).convert( path.toString() ) ) ); }
@Test public void testNotReadable() throws Exception { Path path = Files.createTempFile( "prefix", null ); String pathName = path.toString(); Files.deleteIfExists( path ); exception.expect( ValueConversionException.class ); exception.expectMessage( "File [" + pathName ); new PathConverter( READABLE ).convert( pathName ); }
@Test public void testDirectoryExisting() throws Exception { Path path = Files.createTempDirectory( "prefix" ); path.toFile().deleteOnExit(); String pathName = path.toString(); assertTrue( Files.isDirectory( new PathConverter( DIRECTORY_EXISTING ).convert( pathName ) ) ); }
@Test public void testDirectoryNotOverwritable() throws Exception { Path path = Files.createTempDirectory( "prefix" ); path.toFile().deleteOnExit(); String pathName = path.toString(); exception.expect( ValueConversionException.class ); exception.expectMessage( "File [" + pathName ); new PathConverter( FILE_OVERWRITABLE).convert( pathName ); }
@Test public void testNotExistingNotOverwritable() throws Exception { Path path = Files.createTempDirectory( "prefix" ); String pathName = path.toString(); Files.deleteIfExists( path ); exception.expect( ValueConversionException.class ); exception.expectMessage( "File [" + pathName ); new PathConverter( FILE_OVERWRITABLE ).convert( pathName ); }