Skip to content

Commit

Permalink
Removed test-only code from production class.
Browse files Browse the repository at this point in the history
Equivalent helper method now in test class.
  • Loading branch information
jimwebber committed Jun 28, 2018
1 parent 3c92efe commit bb3953c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Expand Up @@ -55,13 +55,6 @@ public class ProcedureJarLoader
this.log = log;
}

// TODO: delete me and change the tests
Callables loadProcedures( URL jar ) throws Exception
{
return loadProcedures( jar, new URLClassLoader( new URL[]{jar}, this.getClass().getClassLoader() ),
new Callables() );
}

public Callables loadProceduresFromDir( File root ) throws IOException, KernelException
{
if ( !root.exists() )
Expand Down
Expand Up @@ -76,7 +76,7 @@ public void shouldLoadProcedureFromJar() throws Throwable
URL jar = createJarFor( ClassWithOneProcedure.class );

// When
List<CallableProcedure> procedures = jarloader.loadProcedures( jar ).procedures();
List<CallableProcedure> procedures = jarloader.loadProceduresFromDir( parentDir( jar ) ).procedures();

// Then
List<ProcedureSignature> signatures = procedures.stream().map( CallableProcedure::signature ).collect( toList() );
Expand All @@ -94,7 +94,7 @@ public void shouldLoadProcedureWithArgumentFromJar() throws Throwable
URL jar = createJarFor( ClassWithProcedureWithArgument.class );

// When
List<CallableProcedure> procedures = jarloader.loadProcedures( jar ).procedures();
List<CallableProcedure> procedures = jarloader.loadProceduresFromDir( parentDir( jar ) ).procedures();

// Then
List<ProcedureSignature> signatures = procedures.stream().map( CallableProcedure::signature ).collect( toList() );
Expand All @@ -115,7 +115,7 @@ public void shouldLoadProcedureFromJarWithMultipleProcedureClasses() throws Thro
URL jar = createJarFor( ClassWithOneProcedure.class, ClassWithAnotherProcedure.class, ClassWithNoProcedureAtAll.class );

// When
List<CallableProcedure> procedures = jarloader.loadProcedures( jar ).procedures();
List<CallableProcedure> procedures = jarloader.loadProceduresFromDir( parentDir( jar ) ).procedures();

// Then
List<ProcedureSignature> signatures = procedures.stream().map( CallableProcedure::signature ).collect( toList() );
Expand Down Expand Up @@ -143,7 +143,7 @@ public void shouldGiveHelpfulErrorOnInvalidProcedure() throws Throwable
"And then define your procedure as returning `Stream<Output>`." ));

// When
jarloader.loadProcedures( jar );
jarloader.loadProceduresFromDir( parentDir( jar ) );
}

@Test
Expand Down Expand Up @@ -175,7 +175,7 @@ public void shouldGiveHelpfulErrorOnWildCardProcedure() throws Throwable
"that you define and not a Stream<?>." ));

// When
jarloader.loadProcedures( jar );
jarloader.loadProceduresFromDir( parentDir( jar ) );
}

@Test
Expand All @@ -190,7 +190,7 @@ public void shouldGiveHelpfulErrorOnRawStreamProcedure() throws Throwable
"that you define and not a raw Stream." ));

// When
jarloader.loadProcedures( jar );
jarloader.loadProceduresFromDir( parentDir( jar ) );
}

@Test
Expand All @@ -206,7 +206,7 @@ public void shouldGiveHelpfulErrorOnGenericStreamProcedure() throws Throwable
".kernel.impl.proc.ProcedureJarLoaderTest$Output>."));

// When
jarloader.loadProcedures( jar );
jarloader.loadProceduresFromDir( parentDir( jar ) );
}

@Test
Expand All @@ -224,7 +224,7 @@ public void shouldLogHelpfullyWhenPluginJarIsCorrupt() throws Exception
// when
try
{
jarloader.loadProceduresFromDir( new File( theJar.getFile() ).getParentFile() );
jarloader.loadProceduresFromDir( parentDir( theJar ) );
fail("Should have logged and thrown exception.");
}
catch ( ZipException expected )
Expand All @@ -234,6 +234,11 @@ public void shouldLogHelpfullyWhenPluginJarIsCorrupt() throws Exception
}
}

private File parentDir( URL jar )
{
return new File( jar.getFile() ).getParentFile();
}

private void corruptJar( URL jar ) throws IOException, URISyntaxException
{
long fileLength = new File( jar.getFile() ).length();
Expand Down

0 comments on commit bb3953c

Please sign in to comment.