Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/Reflector.java Tue Oct 9 17:45:37 2012 @@ -33,13 +33,13 @@ import java.util.Map; * * @author John Casey */ -public final class Reflector +final class Reflector { private static final String CONSTRUCTOR_METHOD_NAME = "$$CONSTRUCTOR$$"; private static final String GET_INSTANCE_METHOD_NAME = "getInstance"; - private Map<String, Map<String, Map<String, Member>>> classMaps = + private final Map<String, Map<String, Map<String, Member>>> classMaps = new HashMap<String, Map<String, Map<String, Member>>>(); /** @@ -86,10 +86,9 @@ public final class Reflector buffer.append( theClass.getName() ); buffer.append( " with specified or ancestor parameter classes: " ); - for ( int i = 0; i < paramTypes.length; i++ ) - { - buffer.append( paramTypes[i].getName() ); - buffer.append( ',' ); + for (Class paramType : paramTypes) { + buffer.append(paramType.getName()); + buffer.append(','); } buffer.setLength( buffer.length() - 1 ); @@ -185,10 +184,9 @@ public final class Reflector buffer.append( "Singleton-producing method named '" ).append( methodName ).append( "' not found with specified parameter classes: " ); - for ( int i = 0; i < paramTypes.length; i++ ) - { - buffer.append( paramTypes[i].getName() ); - buffer.append( ',' ); + for (Class paramType : paramTypes) { + buffer.append(paramType.getName()); + buffer.append(','); } buffer.setLength( buffer.length() - 1 ); @@ -320,13 +318,11 @@ public final class Reflector { StringBuilder buffer = new StringBuilder(); - buffer.append( "Singleton-producing method named \'" + methodName - + "\' not found with specified parameter classes: " ); + buffer.append("Singleton-producing method named \'").append(methodName).append("\' not found with specified parameter classes: "); - for ( int i = 0; i < paramTypes.length; i++ ) - { - buffer.append( paramTypes[i].getName() ); - buffer.append( ',' ); + for (Class paramType : paramTypes) { + buffer.append(paramType.getName()); + buffer.append(','); } buffer.setLength( buffer.length() - 1 ); @@ -365,10 +361,9 @@ public final class Reflector key.append( "(" ); - for ( int i = 0, len = params.length; i < len; i++ ) - { - key.append( params[i].getName() ); - key.append( "," ); + for (Class param : params) { + key.append(param.getName()); + key.append(","); } if ( params.length > 0 ) @@ -378,7 +373,7 @@ public final class Reflector key.append( ")" ); - Constructor constructor = null; + Constructor constructor; String paramKey = key.toString(); @@ -390,26 +385,22 @@ public final class Reflector { Constructor[] cands = targetClass.getConstructors(); - for ( int i = 0, len = cands.length; i < len; i++ ) - { - Class[] types = cands[i].getParameterTypes(); + for (Constructor cand : cands) { + Class[] types = cand.getParameterTypes(); - if ( params.length != types.length ) - { + if (params.length != types.length) { continue; } - for ( int j = 0, len2 = params.length; j < len2; j++ ) - { - if ( !types[j].isAssignableFrom( params[j] ) ) - { + for (int j = 0, len2 = params.length; j < len2; j++) { + if (!types[j].isAssignableFrom(params[j])) { continue; } } // we got it, so store it! - constructor = cands[i]; - constructorMap.put( paramKey, constructor ); + constructor = cand; + constructorMap.put(paramKey, constructor); } } } @@ -426,7 +417,7 @@ public final class Reflector public Object getObjectProperty( Object target, String propertyName ) throws ReflectorException { - Object returnValue = null; + Object returnValue; if ( propertyName == null || propertyName.trim().length() < 1 ) { @@ -485,7 +476,7 @@ public final class Reflector else { returnValue = getField( target, propertyName, true ); - if ( method == null && returnValue == null ) + if (returnValue == null) { // TODO: Check if exception is the right action! Field exists, but contains null throw new ReflectorException( @@ -530,15 +521,14 @@ public final class Reflector key.append( "(" ); - for ( int i = 0, len = params.length; i < len; i++ ) - { - key.append( params[i].getName() ); - key.append( "," ); + for (Class<?> param : params) { + key.append(param.getName()); + key.append(","); } key.append( ")" ); - Method method = null; + Method method; String paramKey = key.toString(); @@ -550,33 +540,28 @@ public final class Reflector { Method[] cands = targetClass.getMethods(); - for ( int i = 0, len = cands.length; i < len; i++ ) - { - String name = cands[i].getName(); + for (Method cand : cands) { + String name = cand.getName(); - if ( !methodName.equals( name ) ) - { + if (!methodName.equals(name)) { continue; } - Class<?>[] types = cands[i].getParameterTypes(); + Class<?>[] types = cand.getParameterTypes(); - if ( params.length != types.length ) - { + if (params.length != types.length) { continue; } - for ( int j = 0, len2 = params.length; j < len2; j++ ) - { - if ( !types[j].isAssignableFrom( params[j] ) ) - { + for (int j = 0, len2 = params.length; j < len2; j++) { + if (!types[j].isAssignableFrom(params[j])) { continue; } } // we got it, so store it! - method = cands[i]; - methodMap.put( paramKey, method ); + method = cand; + methodMap.put(paramKey, method); } } } @@ -603,12 +588,10 @@ public final class Reflector * @param theClass the class to lookup. * @param methodName The name of the method to lookup. * @return The cache of constructors. - * @throws ReflectorException in case of a lookup error. */ private Map<String, Member> getMethodMap( Class<?> theClass, String methodName ) - throws ReflectorException { - Map<String, Member> methodMap = null; + Map<String, Member> methodMap; if ( theClass == null ) {
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/ReflectorException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/ReflectorException.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/ReflectorException.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/reflection/ReflectorException.java Tue Oct 9 17:45:37 2012 @@ -26,7 +26,7 @@ package org.apache.maven.shared.utils.re * * @author John Casey */ -public class ReflectorException +class ReflectorException extends Exception { /** Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReader.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReader.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReader.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReader.java Tue Oct 9 17:45:37 2012 @@ -48,43 +48,43 @@ public class XmlReader return _staticDefaultEncoding; } - public XmlReader( File file ) + XmlReader( File file ) throws IOException { this( new FileInputStream( file ) ); } - public XmlReader( InputStream is ) + XmlReader( InputStream is ) throws IOException { this( is, true ); } - public XmlReader( InputStream is, boolean lenient ) + XmlReader( InputStream is, boolean lenient ) throws IOException, XmlStreamReaderException { reader = new org.apache.commons.io.input.XmlStreamReader( is, lenient, _staticDefaultEncoding ); } - public XmlReader( URL url ) + XmlReader( URL url ) throws IOException { this( url.openConnection() ); } - public XmlReader( URLConnection conn ) + XmlReader( URLConnection conn ) throws IOException { reader = new org.apache.commons.io.input.XmlStreamReader( conn, _staticDefaultEncoding ); } - public XmlReader( InputStream is, String httpContentType ) + XmlReader( InputStream is, String httpContentType ) throws IOException { this( is, httpContentType, true ); } - public XmlReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) + XmlReader( InputStream is, String httpContentType, boolean lenient, String defaultEncoding ) throws IOException, XmlStreamReaderException { reader = new org.apache.commons.io.input.XmlStreamReader( is, httpContentType, lenient, @@ -93,7 +93,7 @@ public class XmlReader : defaultEncoding ); } - public XmlReader( InputStream is, String httpContentType, boolean lenient ) + XmlReader( InputStream is, String httpContentType, boolean lenient ) throws IOException, XmlStreamReaderException { this( is, httpContentType, lenient, null ); Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReaderException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReaderException.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReaderException.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlReaderException.java Tue Oct 9 17:45:37 2012 @@ -30,20 +30,20 @@ import java.io.InputStream; * @author Alejandro Abdelnur * @version revision 1.1 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) */ -public class XmlReaderException +class XmlReaderException extends IOException { - private String _bomEncoding; + private final String _bomEncoding; - private String _xmlGuessEncoding; + private final String _xmlGuessEncoding; - private String _xmlEncoding; + private final String _xmlEncoding; - private String _contentTypeMime; + private final String _contentTypeMime; - private String _contentTypeEncoding; + private final String _contentTypeEncoding; - private InputStream _is; + private final InputStream _is; /** * Creates an exception instance if the charset encoding could not be determined. @@ -57,7 +57,7 @@ public class XmlReaderException * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) + XmlReaderException( String msg, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) { this( msg, null, null, bomEnc, xmlGuessEnc, xmlEnc, is ); } @@ -76,7 +76,7 @@ public class XmlReaderException * @param xmlEnc XML prolog encoding. * @param is the unconsumed InputStream. */ - public XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, + XmlReaderException( String msg, String ctMime, String ctEnc, String bomEnc, String xmlGuessEnc, String xmlEnc, InputStream is ) { super( msg ); Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamReaderException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamReaderException.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamReaderException.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamReaderException.java Tue Oct 9 17:45:37 2012 @@ -29,7 +29,7 @@ import java.io.InputStream; * @author Alejandro Abdelnur * @version revision 1.1 taken on 26/06/2007 from Rome (see https://rome.dev.java.net/source/browse/rome/src/java/com/sun/syndication/io/XmlReaderException.java) */ -public class XmlStreamReaderException +class XmlStreamReaderException extends XmlReaderException { /** Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamWriter.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamWriter.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamWriter.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamWriter.java Tue Oct 9 17:45:37 2012 @@ -24,7 +24,7 @@ import java.io.FileNotFoundException; import java.io.OutputStream; @Deprecated -public class XmlStreamWriter +class XmlStreamWriter extends org.apache.commons.io.output.XmlStreamWriter { public XmlStreamWriter( OutputStream out ) Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExceptionUtilsTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExceptionUtilsTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExceptionUtilsTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExceptionUtilsTest.java Tue Oct 9 17:45:37 2012 @@ -44,7 +44,7 @@ public class ExceptionUtilsTest extends { private final String LS = System.getProperty( "line.separator" ); - protected static StackTraceElement[] STACKTRACE_WO_SPECIAL_METHODS = + private static final StackTraceElement[] STACKTRACE_WO_SPECIAL_METHODS = { new StackTraceElement("org.apache.maven.test.Class1", "method1", null, 101), new StackTraceElement("org.apache.maven.test.Class2", "method2", null, 101), @@ -239,7 +239,7 @@ public class ExceptionUtilsTest extends // NPE safe test try { - ExceptionUtils.getStackTrace((Throwable) null); + ExceptionUtils.getStackTrace(null); fail( "getStackTrace(null) NPE expected" ); } catch ( NullPointerException e ) @@ -268,7 +268,7 @@ public class ExceptionUtilsTest extends // NPE safe test try { - ExceptionUtils.getStackFrames((Throwable) null); + ExceptionUtils.getStackFrames(null); fail( "getStackFrames(null) NPE expected" ); } catch ( NullPointerException e ) Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExpandTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExpandTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExpandTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/ExpandTest.java Tue Oct 9 17:45:37 2012 @@ -72,11 +72,10 @@ public class ExpandTest extends Assert * * @return */ - private File getTestTargetDir() throws IOException + private File getTestTargetDir() { - File targetDir = tempFolder.newFolder( TEST_ZIP_TARGET_FOLDER ); - return targetDir; + return tempFolder.newFolder( TEST_ZIP_TARGET_FOLDER ); } @Test @@ -317,7 +316,7 @@ public class ExpandTest extends Assert return expandedFile; } - private File verifyExpandedFileAndContent( File targetDir, String expectedContent ) + private void verifyExpandedFileAndContent( File targetDir, String expectedContent ) throws FileNotFoundException { File expandedFile = verifyExpandedFile( targetDir ); @@ -330,8 +329,6 @@ public class ExpandTest extends Assert assertThat( "expanded file content must match" , text , is( expectedContent) ); - - return expandedFile; } Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java Tue Oct 9 17:45:37 2012 @@ -65,8 +65,7 @@ public class XmlStreamReaderTest { xmlDecl = "<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>"; } - String xml = xmlDecl + "\n<text>" + text + "</text>"; - return xml; + return xmlDecl + "\n<text>" + text + "</text>"; } private static void checkXmlContent( String xml, String encoding ) Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java Tue Oct 9 17:45:37 2012 @@ -32,33 +32,6 @@ public class CommandLineUtilsTest extends TestCase { - public void testQuoteArguments() - { - try - { - String result = CommandLineUtils.quote( "Hello" ); - System.out.println( result ); - assertEquals( "Hello", result ); - result = CommandLineUtils.quote( "Hello World" ); - System.out.println( result ); - assertEquals( "\"Hello World\"", result ); - result = CommandLineUtils.quote( "\"Hello World\"" ); - System.out.println( result ); - assertEquals( "\'\"Hello World\"\'", result ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } - try - { - CommandLineUtils.quote( "\"Hello \'World\'\'" ); - fail(); - } - catch ( Exception e ) - { - } - } /** * Tests that case-insensitive environment variables are normalized to upper case. Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java Tue Oct 9 17:45:37 2012 @@ -27,7 +27,7 @@ public class BourneShellTest extends TestCase { - protected Shell newShell() + Shell newShell() { return new BourneShell(); } Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java Tue Oct 9 17:45:37 2012 @@ -40,11 +40,13 @@ public class TestException extends Excep this.cause = cause; } + @SuppressWarnings("UnusedDeclaration") public Throwable getSourceException() { return cause; } + @SuppressWarnings("UnusedDeclaration") public Throwable getSpecialCause() { return specialCause; Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java Tue Oct 9 17:45:37 2012 @@ -154,7 +154,7 @@ public class ReflectionValueExtractorTes private Scm scm; - private List dependencies = new ArrayList(); + private final List dependencies = new ArrayList(); private Build build; @@ -246,7 +246,8 @@ public class ReflectionValueExtractorTes public Dependency[] getDependenciesAsArray() { - return (Dependency[]) getDependencies().toArray( new Dependency[0]); + List list = getDependencies(); + return (Dependency[]) list.toArray(new Dependency[list.size()]); } public Map getDependenciesAsMap() Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java Tue Oct 9 17:45:37 2012 @@ -156,7 +156,6 @@ public class DirectoryScannerTest String[] expectedNotIncludedDirectories, String[] expectedExcludedFiles, String[] expectedExcludedDirectories ) - throws Exception { DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir( tempFolder.getRoot() ); @@ -190,7 +189,7 @@ public class DirectoryScannerTest checkFiles( "expectedExcludedFiles", expectedExcludedFiles, ds.getExcludedFiles() ); checkFiles( "expectedExcludedDirectories", expectedExcludedDirectories, ds.getExcludedDirectories() ); - checkFiles( "visitedFiles", expectedIncludedFiles, scanConductor.visitedFiles.toArray( new String[ 0 ] ) ); + checkFiles( "visitedFiles", expectedIncludedFiles, scanConductor.visitedFiles.toArray(new String[scanConductor.visitedFiles.size()])); } /** @@ -218,7 +217,7 @@ public class DirectoryScannerTest private static class TestScanConductor implements ScanConductor { - List<String> visitedFiles = new ArrayList<String>(); + final List<String> visitedFiles = new ArrayList<String>(); public ScanConductor.ScanAction visitDirectory( String name, File directory ) { Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java Tue Oct 9 17:45:37 2012 @@ -113,7 +113,7 @@ public class FileUtilsTest createFile( testFile2, testFile2Size ); } - protected void createFile( File file, long size ) + void createFile( File file, long size ) throws IOException { if ( !file.getParentFile().exists() ) @@ -132,63 +132,10 @@ public class FileUtilsTest } - - protected void checkFile( File file, File referenceFile ) - throws Exception - { - assertThat( "Check existence of output file", file.exists(), is( true ) ); - assertEqualContent( referenceFile, file ); - } - - /** - * Assert that the content of two files is the same. - */ - private void assertEqualContent( File f0, File f1 ) - throws IOException - { - /* This doesn't work because the filesize isn't updated until the file - * is closed. - assertTrue( "The files " + f0 + " and " + f1 + - " have differing file sizes (" + f0.length() + - " vs " + f1.length() + ")", ( f0.length() == f1.length() ) ); - */ - InputStream is0 = new java.io.FileInputStream( f0 ); - try - { - InputStream is1 = new java.io.FileInputStream( f1 ); - try - { - byte[] buf0 = new byte[1024]; - byte[] buf1 = new byte[1024]; - int n0 = 0; - int n1 = 0; - - while ( -1 != n0 ) - { - n0 = is0.read( buf0 ); - n1 = is1.read( buf1 ); - assertThat( - "The files " + f0 + " and " + f1 + " have differing number of bytes available (" + n0 + " vs " - + n1 + ")", n0, is( n1 ) ); - - assertThat( "The files " + f0 + " and " + f1 + " have different content", buf0, is( buf1 ) ); - } - } - finally - { - is1.close(); - } - } - finally - { - is0.close(); - } - } - /** * Assert that the content of a file is equal to that in a byte[]. */ - protected void assertEqualContent( byte[] b0, File file ) + void assertEqualContent( byte[] b0, File file ) throws IOException { InputStream is = new java.io.FileInputStream( file ); @@ -213,64 +160,7 @@ public class FileUtilsTest } } - /** - * Assert that the content of a file is equal to that in a char[]. - */ - protected void assertEqualContent( char[] c0, File file ) - throws IOException - { - Reader ir = new java.io.FileReader( file ); - int count = 0, numRead = 0; - char[] c1 = new char[c0.length]; - try - { - while ( count < c0.length && numRead >= 0 ) - { - numRead = ir.read( c1, count, c0.length ); - count += numRead; - } - assertThat( "Different number of chars: ", count, is( c0.length ) ); - for ( int i = 0; i < count; i++ ) - { - assertThat( "char " + i + " differs", c1[i], is( c0[i] ) ); - } - } - finally - { - ir.close(); - } - } - - protected void checkWrite( OutputStream output ) - throws Exception - { - try - { - new java.io.PrintStream( output ).write( 0 ); - } - catch ( Throwable t ) - { - throw new AssertionFailedError( - "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage() ); - } - } - - protected void checkWrite( Writer output ) - throws Exception - { - try - { - new java.io.PrintWriter( output ).write( 'a' ); - } - catch ( Throwable t ) - { - throw new AssertionFailedError( - "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage() ); - } - } - - protected void deleteFile( File file ) - throws Exception + void deleteFile( File file ) { if ( file.exists() ) { @@ -312,7 +202,7 @@ public class FileUtilsTest public void toFile3() throws Exception { - assertThat( FileUtils.toFile( (URL) null ), CoreMatchers.<File>nullValue() ); + assertThat( FileUtils.toFile(null), CoreMatchers.<File>nullValue() ); assertThat( FileUtils.toFile( new URL( "http://jakarta.apache.org" ) ), CoreMatchers.<File>nullValue() ); } @@ -552,23 +442,6 @@ public class FileUtilsTest testFile1.lastModified() == destination.lastModified());*/ } - public void testCopyFileLarge() - throws Exception - { - - File largeFile = new File( tempFolder.getRoot(), "large.txt" ); - File destination = new File( tempFolder.getRoot(), "copylarge.txt" ); - - System.out.println( "START: " + new java.util.Date() ); - createFile( largeFile, FileUtils.ONE_GB ); - System.out.println( "CREATED: " + new java.util.Date() ); - FileUtils.copyFile( largeFile, destination ); - System.out.println( "COPIED: " + new java.util.Date() ); - - assertThat( "Check Exist", destination.exists(), is( true ) ); - assertThat( "Check Full copy", destination.length(), is( largeFile.length() ) ); - } - @Test public void copyFile2() throws Exception Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java Tue Oct 9 17:45:37 2012 @@ -643,28 +643,28 @@ public class IOUtilTest public void copyNullByteArrayNullOutputStreamNegBufSz() throws Exception { - IOUtil.copy( nullByteArray(), nullOutputStream(), -1 ); + IOUtil.copy( nullByteArray(), nullOutputStream()); } @Test( expected = NullPointerException.class ) public void copyNullByteArrayValidOutputStreamNegBufSz() throws Exception { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream(), -1 ); + IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); } @Test( expected = NullPointerException.class ) public void copyEmptyByteArrayNullOutputStreamNegBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), nullOutputStream(), -1 ); + IOUtil.copy( emptyByteArray(), nullOutputStream()); } @Test public void copyEmptyByteArrayValidOutputStreamNegBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream(), -1 ); + IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); } @Test @@ -673,7 +673,7 @@ public class IOUtilTest { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream, -1 ); + IOUtil.copy( input, outputStream); assertThat( outputStream.toByteArray(), is( input ) ); } @@ -681,28 +681,28 @@ public class IOUtilTest public void copyNullByteArrayNullOutputStreamZeroBufSz() throws Exception { - IOUtil.copy( nullByteArray(), nullOutputStream(), 0 ); + IOUtil.copy( nullByteArray(), nullOutputStream()); } @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) public void copyNullByteArrayValidOutputStreamZeroBufSz() throws Exception { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream(), 0 ); + IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); } @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) public void copyEmptyByteArrayNullOutputStreamZeroBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), nullOutputStream(), 0 ); + IOUtil.copy( emptyByteArray(), nullOutputStream()); } @Test( timeout = INFINITE_LOOP_TIMEOUT ) public void copyEmptyByteArrayValidOutputStreamZeroBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream(), 0 ); + IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); } @Test( timeout = INFINITE_LOOP_TIMEOUT ) @@ -711,7 +711,7 @@ public class IOUtilTest { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream, 0 ); + IOUtil.copy( input, outputStream); assertThat( outputStream.toByteArray(), is( input ) ); } @@ -719,28 +719,28 @@ public class IOUtilTest public void copyNullByteArrayNullOutputStreamPosBufSz() throws Exception { - IOUtil.copy( nullByteArray(), nullOutputStream(), 1 ); + IOUtil.copy( nullByteArray(), nullOutputStream()); } @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) public void copyNullByteArrayValidOutputStreamPosBufSz() throws Exception { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream(), 1 ); + IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); } @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) public void copyEmptyByteArrayNullOutputStreamPosBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), nullOutputStream(), 1 ); + IOUtil.copy( emptyByteArray(), nullOutputStream()); } @Test( timeout = INFINITE_LOOP_TIMEOUT ) public void copyEmptyByteArrayValidOutputStreamPosBufSz() throws Exception { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream(), 1 ); + IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); } @Test( timeout = INFINITE_LOOP_TIMEOUT ) @@ -749,7 +749,7 @@ public class IOUtilTest { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream, 1 ); + IOUtil.copy( input, outputStream); assertThat( outputStream.toByteArray(), is( input ) ); } Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/reflection/ReflectorTest.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/reflection/ReflectorTest.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/reflection/ReflectorTest.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/reflection/ReflectorTest.java Tue Oct 9 17:45:37 2012 @@ -34,7 +34,7 @@ import static org.apache.maven.shared.ut */ public class ReflectorTest { - private Reflector reflector = new Reflector(); + private final Reflector reflector = new Reflector(); //// newInstance( Class, Object[] ) @@ -929,7 +929,7 @@ public class ReflectorTest public void getConstructorObjectEmpty() throws Exception { - assertThat( reflector.getConstructor( Object.class, new Class[0] ), + assertThat( reflector.getConstructor( Object.class), is( (Constructor) Object.class.getDeclaredConstructor() ) ); } @@ -938,7 +938,7 @@ public class ReflectorTest public void getConstructorPrivate() throws Exception { - assertThat( reflector.getConstructor( ReflectorTestHelper.class, new Class[0] ), + assertThat( reflector.getConstructor( ReflectorTestHelper.class), is( (Constructor) ReflectorTestHelper.class.getDeclaredConstructor() ) ); } @@ -946,7 +946,7 @@ public class ReflectorTest public void getConstructorPackage() throws Exception { - assertThat( reflector.getConstructor( ReflectorTestHelper.class, new Class[]{ Boolean.class } ), + assertThat( reflector.getConstructor( ReflectorTestHelper.class, Boolean.class), not( is( (Constructor) ReflectorTestHelper.class.getDeclaredConstructor( Boolean.class ) ) ) ); } @@ -954,7 +954,7 @@ public class ReflectorTest public void getConstructorProtected() throws Exception { - assertThat( reflector.getConstructor( ReflectorTestHelper.class, new Class[]{ Integer.class } ), + assertThat( reflector.getConstructor( ReflectorTestHelper.class, Integer.class), not( is( (Constructor) ReflectorTestHelper.class.getDeclaredConstructor( Integer.class ) ) ) ); } @@ -962,7 +962,7 @@ public class ReflectorTest public void getConstructorPublic() throws Exception { - assertThat( reflector.getConstructor( ReflectorTestHelper.class, new Class[]{ String.class } ), + assertThat( reflector.getConstructor( ReflectorTestHelper.class, String.class), is( (Constructor) ReflectorTestHelper.class.getDeclaredConstructor( String.class ) ) ); } @@ -1049,7 +1049,7 @@ public class ReflectorTest { class CoT { - private int _value = 42; + private final int _value = 42; private int getValue() { @@ -1065,7 +1065,7 @@ public class ReflectorTest { class CoT { - private int _value = 42; + private final int _value = 42; int getValue() { @@ -1081,7 +1081,7 @@ public class ReflectorTest { class CoT { - private int _value = 42; + private final int _value = 42; protected int getValue() { @@ -1097,7 +1097,7 @@ public class ReflectorTest { class CoT { - private int _value = 42; + private final int _value = 42; public int getValue() { Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java?rev=1396135&r1=1396134&r2=1396135&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java (original) +++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java Tue Oct 9 17:45:37 2012 @@ -24,13 +24,7 @@ import org.apache.maven.shared.utils.io. import org.apache.maven.shared.utils.io.IOUtil; import org.junit.rules.TemporaryFolder; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; +import java.io.*; /** * A few utility methods for file based tests @@ -43,20 +37,6 @@ public final class FileTestHelper // utility function doesn't need a public ct } - public static byte[] generateTestData( long size ) - { - try - { - ByteArrayOutputStream baout = new ByteArrayOutputStream(); - generateTestData( baout, size ); - return baout.toByteArray(); - } - catch ( IOException ioe ) - { - throw new RuntimeException( "This should never happen: " + ioe.getMessage() ); - } - } - public static void generateTestData( OutputStream out, long size ) throws IOException { @@ -71,6 +51,7 @@ public final class FileTestHelper { if ( testfile.exists() ) { + //noinspection ResultOfMethodCallIgnored testfile.delete(); } @@ -92,9 +73,8 @@ public final class FileTestHelper PrintWriter output = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) ); try { - for ( int i = 0; i < data.length; i++ ) - { - output.println( data[i] ); + for (String aData : data) { + output.println(aData); } } finally
