Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSHARED-860] suppress deprecations and clean up test methods #46

Merged
merged 7 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
import org.apache.maven.shared.utils.Os;

/**
* XMLWriter with nice indentation
*/
/**
* XMLWriter with nice indentation.
*
* @author kama
*
*/
public class PrettyPrintXMLWriter
implements XMLWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;
import org.apache.maven.shared.utils.io.IOUtil;

import org.apache.commons.io.IOUtils;
import org.apache.maven.shared.utils.xml.XmlStreamReader;

/**
Expand Down Expand Up @@ -66,8 +67,7 @@ private static String createXmlContent( String text, String encoding )
return xmlDecl + "\n<text>" + text + "</text>";
}

private static void checkXmlContent( String xml, String encoding )
throws IOException
private static void checkXmlContent( String xml, String encoding ) throws IOException
{
checkXmlContent( xml, encoding, null );
}
Expand All @@ -76,15 +76,15 @@ private static void checkXmlContent( String xml, String encoding, byte[] bom ) t
{
byte[] xmlContent = xml.getBytes( encoding );
InputStream in = new ByteArrayInputStream( xmlContent );

if ( bom != null )
{
in = new SequenceInputStream( new ByteArrayInputStream( bom ), in );
}

XmlStreamReader reader = new XmlStreamReader( in );
assertEquals( encoding, reader.getEncoding() );
String result = IOUtil.toString( reader );
String result = IOUtils.toString( reader );
assertEquals( xml, result );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
/**
* @author Kristian Rosenvold
*/
@SuppressWarnings( "deprecation" )
public class MatchPatternTest
{
@Test
public void matchPath()
throws Exception
{
MatchPattern mp = MatchPattern.fromString( "ABC*" );
assertTrue( mp.matchPath( "ABCD", true ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
/**
* @author Kristian Rosenvold
*/
@SuppressWarnings( "deprecation" )
public class MatchPatternsTest
{
@Test
public void matches()
throws Exception
{
MatchPatterns from = MatchPatterns.from( "ABC**", "CDE**" );
assertTrue( from.matches( "ABCDE", true ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

/**
* Test the {@link SelectorUtils} class.
*
*/
@SuppressWarnings( "deprecation" )
public class SelectorUtilsTest
{

Expand Down Expand Up @@ -67,7 +67,6 @@ public void testAntPatternStrings()
assertAntDoesNotMatch( "/aaa/", "\\aaa\\bbb" );
}


private void assertAntDoesNotMatch( String pattern, String target )
{
assertEquals( false, SelectorUtils.matchPatternStart( wrapWithAntHandler( pattern ), target ) );
Expand Down

This file was deleted.

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

import org.apache.maven.shared.utils.io.FileUtils;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.commons.io.FileUtils;

import java.io.*;
import org.junit.rules.TemporaryFolder;

/**
* A few utility methods for file based tests
* A few utility methods for file based tests.
*/
public final class FileTestHelper
{

private FileTestHelper()
{
// utility function doesn't need a public ct
// utility function doesn't need a public constructor
}

public static void generateTestData( OutputStream out, long size )
Expand All @@ -54,14 +60,12 @@ public static void generateTestFile( File testfile, int size )
testfile.delete();
}

OutputStream os = new FileOutputStream( testfile );
generateTestData( os, size );
os.flush();
os.close();
try ( OutputStream os = new FileOutputStream( testfile ) ) {
generateTestData( os, size );
os.flush();
}
}



public static void createLineBasedFile( File file, String[] data )
throws IOException
{
Expand All @@ -70,11 +74,12 @@ public static void createLineBasedFile( File file, String[] data )
throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
}

try ( PrintWriter out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) ) )
try ( Writer out = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) )
{
for ( String aData : data )
{
out.println( aData );
out.write( aData );
out.write( System.lineSeparator() );
}
}
}
Expand All @@ -92,7 +97,7 @@ public static File newFile( TemporaryFolder folder, String filename )

if ( destination.exists() )
{
FileUtils.forceDelete( destination );
FileUtils.deleteQuietly( destination );
}
return destination;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.apache.maven.shared.utils.xml;

import java.io.IOException;
import javax.swing.text.html.HTML;
import java.io.StringWriter;
import static org.junit.Assert.fail;

import java.io.File;
import java.io.FileOutputStream;

/*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -23,13 +24,14 @@
* under the License.
*/

import java.io.IOException;

import javax.swing.text.html.HTML;
import java.io.StringWriter;

import org.apache.maven.shared.utils.Os;
import org.apache.maven.shared.utils.StringUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
Expand All @@ -40,26 +42,9 @@
*/
public class PrettyPrintXmlWriterTest
{
StringWriter w;

PrettyPrintXMLWriter writer;

@Before
public void before()
throws Exception
{
w = new StringWriter();
writer = new PrettyPrintXMLWriter( w );
}

@After
public void after()
throws Exception
{
writer = null;
w = null;
}

private StringWriter w = new StringWriter();
private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( w );

@Test
public void testDefaultPrettyPrintXMLWriter() throws IOException
{
Expand Down Expand Up @@ -178,12 +163,12 @@ private void writeXhtmlBody( XMLWriter writer ) throws IOException
writer.endElement(); // Tag.BODY
}

private String expectedResult( String lineSeparator )
private static String expectedResult( String lineSeparator )
{
return expectedResult( " ", lineSeparator );
}

private String expectedResult( String lineIndenter, String lineSeparator )
private static String expectedResult( String lineIndenter, String lineSeparator )
{
StringBuilder expected = new StringBuilder();

Expand Down