TempDirectoryNameGenerator implements PentahoNameGenerator { public void initialize( final ContentLocation contentLocation, final boolean safeToDelete ) { this.safeToDelete = safeToDelete; this.mimeRegistry = contentLocation.getRepository().getMimeRegistry(); if ( contentLocation instanceof FileContentLocation ) { final FileContentLocation fileContentLocation = (FileContentLocation) contentLocation; targetDirectory = (File) fileContentLocation.getContentId(); if ( targetDirectory.isDirectory() == false ) { throw new NullPointerException(); } } if ( targetDirectory == null ) { fallback = new DefaultNameGenerator( contentLocation ); } } TempDirectoryNameGenerator(); void initialize( final ContentLocation contentLocation, final boolean safeToDelete ); String generateName( final String nameHint, final String mimeType );  }
@Test public void testGenerateNameWithNoDirectory() throws Exception { FileContentLocation fileLocation = mock( FileContentLocation.class ); Repository repository = mock( Repository.class ); MimeRegistry mimeRegistry = mock( MimeRegistry.class ); doReturn( mimeRegistry ).when( repository ).getMimeRegistry(); doReturn( repository ).when( fileLocation ).getRepository(); File file = mock( File.class ); doReturn( file ).when( fileLocation ).getContentId(); doReturn( false ).when( file ).isDirectory(); try { generator.initialize( fileLocation, true ); } catch ( NullPointerException ex ) { assertTrue( true ); } }