Skip to content

Commit

Permalink
Test code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Feb 6, 2021
1 parent 38a4bfd commit f04a98f
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 172 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
* under the License.
*/

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;

import org.apache.maven.plugin.testing.AbstractMojoTestCase;

Expand Down Expand Up @@ -59,41 +58,18 @@ public void testSourceDir()
assertTrue( new File( xrefTestDir, "stylesheet.css" ).exists() );

// check if there's a link to the javadoc files
String str = readFile( new File( xrefTestDir, "testsourcedir/test/AppSampleTest.html" ) );
assertTrue( str.toLowerCase().indexOf( "/apidocs/testsourcedir/test/AppSample.html\"".toLowerCase() ) == -1 );

str = readFile( new File( xrefTestDir, "testsourcedir/test/AppTest.html" ) );
assertTrue( str.toLowerCase().indexOf( "/apidocs/testsourcedir/test/App.html\"".toLowerCase() ) == -1 );

}

protected void tearDown()
throws Exception
{
String str = readFile( xrefTestDir, "testsourcedir/test/AppSampleTest.html" );
assertFalse( str.toLowerCase().contains( "/apidocs/testsourcedir/test/AppSample.html\"".toLowerCase() ) );

str = readFile( xrefTestDir, "testsourcedir/test/AppTest.html" );
assertFalse( str.toLowerCase().contains( "/apidocs/testsourcedir/test/App.html\"".toLowerCase() ) );
}

/**
* Read the contents of the specified file object into a string
*
* @param file the file to be read
* @return a String object that contains the contents of the file
* @throws java.io.IOException
*/
private String readFile( File file )
throws IOException
private String readFile( File xrefTestDir, String fileName ) throws IOException
{
String str = "", strTmp = "";

try ( BufferedReader in = new BufferedReader( new FileReader( file ) ) )
{
while ( ( strTmp = in.readLine() ) != null )
{
str = str + ' ' + strTmp;
}
}

return str;
return new String( Files.readAllBytes( xrefTestDir.toPath().resolve( fileName ) ) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -45,11 +44,11 @@ public AggregateTestMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File(
getBasedir() + "/src/test/resources/unit/aggregate-test/aggregate-test-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader(
getBasedir() + "/src/test/resources/unit/aggregate-test/aggregate-test-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -45,11 +44,11 @@ public DefaultConfigurationMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File( getBasedir() +
"/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader( getBasedir() +
"/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -44,11 +43,11 @@ public ExcludeConfigurationMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File( getBasedir() +
"/src/test/resources/unit/exclude-configuration/exclude-configuration-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader( getBasedir() +
"/src/test/resources/unit/exclude-configuration/exclude-configuration-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -44,11 +43,11 @@ public IncludeConfigurationMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File( getBasedir() +
"/src/test/resources/unit/include-configuration/include-configuration-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader( getBasedir() +
"/src/test/resources/unit/include-configuration/include-configuration-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -36,7 +35,7 @@
public class NoJavadocDirMavenProjectStub
extends MavenProjectStub
{
private List<ReportPlugin> reportPlugins = new ArrayList<>();
private List<ReportPlugin> reportPlugins;

public NoJavadocDirMavenProjectStub()
{
Expand All @@ -45,11 +44,11 @@ public NoJavadocDirMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File(
getBasedir() + "/src/test/resources/unit/nojavadocdir-test/nojavadocdir-test-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader(
getBasedir() + "/src/test/resources/unit/nojavadocdir-test/nojavadocdir-test-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class NoJavadocLinkConfigurationMavenProjectStub
extends MavenProjectStub
{
List<ReportPlugin> reportPlugins = new ArrayList<>();
List<ReportPlugin> reportPlugins;

public NoJavadocLinkConfigurationMavenProjectStub()
{
Expand All @@ -45,11 +45,11 @@ public NoJavadocLinkConfigurationMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File( getBasedir() +
"/src/test/resources/unit/nojavadoclink-configuration/nojavadoclink-configuration-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader( getBasedir() +
"/src/test/resources/unit/nojavadoclink-configuration/nojavadoclink-configuration-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand All @@ -61,7 +61,7 @@ public NoJavadocLinkConfigurationMavenProjectStub()
setInceptionYear( model.getInceptionYear() );

String basedir = getBasedir().getAbsolutePath();
List<String> compileSourceRoots = new ArrayList<String>();
List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add(
basedir + "/src/test/resources/unit/nojavadoclink-configuration/nojavadoclink/configuration" );
setCompileSourceRoots( compileSourceRoots );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PomMavenProjectStub
public PomMavenProjectStub()
{
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;
Model model;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;

import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -43,11 +42,11 @@ public TestSourceDirMavenProjectStub()

try
{
model = pomReader.read( new FileReader( new File(
getBasedir() + "/src/test/resources/unit/testsourcedir-test/testsourcedir-test-plugin-config.xml" ) ) );
model = pomReader.read( new FileReader(
getBasedir() + "/src/test/resources/unit/testsourcedir-test/testsourcedir-test-plugin-config.xml" ) );
setModel( model );
}
catch ( Exception e )
catch ( Exception ignored )
{

}
Expand Down

0 comments on commit f04a98f

Please sign in to comment.