diff --git a/pom.xml b/pom.xml index 2f5e6e3f..c19bdcdf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ - + " + CRLF ); + writer.writeMarkup("" + CRLF); } /** @@ -149,9 +138,8 @@ public static void writeCommentLineBreak( XMLWriter writer, int columnSize ) thr * @see #writeComment(XMLWriter, String, int, int) * @throws IOException if writing fails */ - public static void writeComment( XMLWriter writer, String comment ) throws IOException - { - writeComment( writer, comment, 0, DEFAULT_INDENTATION_SIZE ); + public static void writeComment(XMLWriter writer, String comment) throws IOException { + writeComment(writer, comment, 0, DEFAULT_INDENTATION_SIZE); } /** @@ -165,9 +153,8 @@ public static void writeComment( XMLWriter writer, String comment ) throws IOExc * @see #writeComment(XMLWriter, String, int, int) * @throws IOException if writing fails */ - public static void writeComment( XMLWriter writer, String comment, int indent ) throws IOException - { - writeComment( writer, comment, indent, DEFAULT_INDENTATION_SIZE ); + public static void writeComment(XMLWriter writer, String comment, int indent) throws IOException { + writeComment(writer, comment, indent, DEFAULT_INDENTATION_SIZE); } /** @@ -182,11 +169,10 @@ public static void writeComment( XMLWriter writer, String comment, int indent ) * @see #writeComment(XMLWriter, String, int, int, int) * @throws IOException if writing fails */ - public static void writeComment( XMLWriter writer, String comment, int indent, int indentSize ) throws IOException - { - writeComment( writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE ); + public static void writeComment(XMLWriter writer, String comment, int indent, int indentSize) throws IOException { + writeComment(writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE); } - + /** * Convenience method to write XML comment line. The comment is split to have a size of * columnSize and is indented by indent using indentSize. @@ -198,76 +184,62 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i * @param columnSize positive number * @throws IOException if writing fails */ - public static void writeComment( XMLWriter writer, String comment, int indent, int indentSize, int columnSize ) - throws IOException - { - if ( comment == null ) - { + public static void writeComment(XMLWriter writer, String comment, int indent, int indentSize, int columnSize) + throws IOException { + if (comment == null) { comment = "null"; } - if ( indent < 0 ) - { + if (indent < 0) { indent = 0; } - if ( indentSize < 0 ) - { + if (indentSize < 0) { indentSize = 0; } - if ( columnSize < 0 ) - { + if (columnSize < 0) { columnSize = DEFAULT_COLUMN_LINE; } - String indentation = StringUtils.repeat( " ", indent * indentSize ); + String indentation = StringUtils.repeat(" ", indent * indentSize); int magicNumber = indentation.length() + columnSize - "-->".length() - 1; - String[] sentences = StringUtils.split( comment, CRLF ); - - StringBuffer line = new StringBuffer( indentation + "" ).append( CRLF ); - writer.writeMarkup( line.toString() ); + line.append("-->").append(CRLF); + writer.writeMarkup(line.toString()); } - line = new StringBuffer( indentation + "" ).append( CRLF ); + line.append("-->").append(CRLF); - writer.writeMarkup( line.toString() ); + writer.writeMarkup(line.toString()); } /** @@ -280,9 +252,8 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i * @see #writeCommentText(XMLWriter, String, int, int) * @throws IOException if writing fails */ - public static void writeCommentText( XMLWriter writer, String comment ) throws IOException - { - writeCommentText( writer, comment, 0, DEFAULT_INDENTATION_SIZE ); + public static void writeCommentText(XMLWriter writer, String comment) throws IOException { + writeCommentText(writer, comment, 0, DEFAULT_INDENTATION_SIZE); } /** @@ -297,9 +268,8 @@ public static void writeCommentText( XMLWriter writer, String comment ) throws I * @see #writeCommentText(XMLWriter, String, int, int) * @throws IOException if writing fails */ - public static void writeCommentText( XMLWriter writer, String comment, int indent ) throws IOException - { - writeCommentText( writer, comment, indent, DEFAULT_INDENTATION_SIZE ); + public static void writeCommentText(XMLWriter writer, String comment, int indent) throws IOException { + writeCommentText(writer, comment, indent, DEFAULT_INDENTATION_SIZE); } /** @@ -314,10 +284,9 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden * @see #writeCommentText(XMLWriter, String, int, int, int) * @throws IOException if writing fails */ - public static void writeCommentText( XMLWriter writer, String comment, int indent, int indentSize ) - throws IOException - { - writeCommentText( writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE ); + public static void writeCommentText(XMLWriter writer, String comment, int indent, int indentSize) + throws IOException { + writeCommentText(writer, comment, indent, indentSize, DEFAULT_COLUMN_LINE); } /** @@ -332,34 +301,30 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden * @param columnSize positive number * @throws IOException if writing fails */ - public static void writeCommentText( XMLWriter writer, String comment, int indent, int indentSize, int columnSize ) - throws IOException - { - if ( indent < 0 ) - { + public static void writeCommentText(XMLWriter writer, String comment, int indent, int indentSize, int columnSize) + throws IOException { + if (indent < 0) { indent = 0; } - if ( indentSize < 0 ) - { + if (indentSize < 0) { indentSize = 0; } - if ( columnSize < 0 ) - { + if (columnSize < 0) { columnSize = DEFAULT_COLUMN_LINE; } - writeLineBreak( writer, 1 ); + writeLineBreak(writer, 1); - writer.writeMarkup( StringUtils.repeat( " ", indent * indentSize ) ); - writeCommentLineBreak( writer, columnSize ); + writer.writeMarkup(StringUtils.repeat(" ", indent * indentSize)); + writeCommentLineBreak(writer, columnSize); - writeComment( writer, comment, indent, indentSize, columnSize ); + writeComment(writer, comment, indent, indentSize, columnSize); - writer.writeMarkup( StringUtils.repeat( " ", indent * indentSize ) ); - writeCommentLineBreak( writer, columnSize ); + writer.writeMarkup(StringUtils.repeat(" ", indent * indentSize)); + writeCommentLineBreak(writer, columnSize); - writeLineBreak( writer, 1, indent, indentSize ); + writeLineBreak(writer, 1, indent, indentSize); } } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java index 1b2f1b66..40b7b633 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml; + +import javax.annotation.Nonnull; import java.io.IOException; import java.io.StringWriter; @@ -28,16 +29,12 @@ import java.util.List; import java.util.Map; -import javax.annotation.Nonnull; - /** * A reimplementation of Plexus Xpp3Dom based on the public interface of Plexus Xpp3Dom. * * @author Kristian Rosenvold */ -public class Xpp3Dom - implements Iterable -{ +public class Xpp3Dom implements Iterable { private static final long serialVersionUID = 2567894443061173996L; private String name; // plexus: protected @@ -64,7 +61,7 @@ public class Xpp3Dom */ public static final String CHILDREN_COMBINATION_APPEND = "append"; - @SuppressWarnings( "UnusedDeclaration" ) + @SuppressWarnings("UnusedDeclaration") private static final String DEFAULT_CHILDREN_COMBINATION_MODE = CHILDREN_COMBINATION_MERGE; // plexus: public /** @@ -75,15 +72,15 @@ public class Xpp3Dom /** * The attributes which identifies override. */ - public static final String SELF_COMBINATION_OVERRIDE = "override"; // plexus: public + public static final String SELF_COMBINATION_OVERRIDE = "override"; // plexus: public /** * The attribute which identifies merge */ public static final String SELF_COMBINATION_MERGE = "merge"; - @SuppressWarnings( "UnusedDeclaration" ) - private static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; // plexus: public + @SuppressWarnings("UnusedDeclaration") + private static final String DEFAULT_SELF_COMBINATION_MODE = SELF_COMBINATION_MERGE; // plexus: public private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final Xpp3Dom[] EMPTY_DOM_ARRAY = new Xpp3Dom[0]; @@ -91,8 +88,7 @@ public class Xpp3Dom /** * @param name The name of the instance. */ - public Xpp3Dom( String name ) - { + public Xpp3Dom(String name) { this.name = name; childList = new ArrayList(); childMap = new HashMap(); @@ -102,9 +98,8 @@ public Xpp3Dom( String name ) * Create instance. * @param source The source. */ - public Xpp3Dom( Xpp3Dom source ) - { - this( source, source.getName() ); + public Xpp3Dom(Xpp3Dom source) { + this(source, source.getName()); } /** @@ -112,132 +107,114 @@ public Xpp3Dom( Xpp3Dom source ) * @param src The source Dom. * @param name The name of the Dom. */ - public Xpp3Dom( @Nonnull Xpp3Dom src, String name ) - { + public Xpp3Dom(@Nonnull Xpp3Dom src, String name) { this.name = name; int size = src.getChildCount(); - childList = new ArrayList( size ); + childList = new ArrayList(size); childMap = new HashMap(); - setValue( src.getValue() ); + setValue(src.getValue()); - for ( String attributeName : src.getAttributeNames() ) - { - setAttribute( attributeName, src.getAttribute( attributeName ) ); + for (String attributeName : src.getAttributeNames()) { + setAttribute(attributeName, src.getAttribute(attributeName)); } - for ( Xpp3Dom xpp3Dom : src.getChildren() ) - { - addChild( new Xpp3Dom( xpp3Dom ) ); + for (Xpp3Dom xpp3Dom : src.getChildren()) { + addChild(new Xpp3Dom(xpp3Dom)); } } /** * @return The current name. */ - public String getName() - { + public String getName() { return name; } /** * @return The current value. */ - @Nonnull public String getValue() - { + @Nonnull + public String getValue() { return value; } /** * @param value The value to be set. */ - public void setValue( @Nonnull String value ) - { + public void setValue(@Nonnull String value) { this.value = value; } - /** * @return The array of attribute names. */ - public String[] getAttributeNames() - { + public String[] getAttributeNames() { boolean isNothing = attributes == null || attributes.isEmpty(); - return isNothing ? EMPTY_STRING_ARRAY : attributes.keySet().toArray( new String[attributes.size()] ); + return isNothing ? EMPTY_STRING_ARRAY : attributes.keySet().toArray(new String[attributes.size()]); } - /** * @param nameParameter The name of the attribute. * @return The attribute value. */ - public String getAttribute( String nameParameter ) - { - return this.attributes != null ? this.attributes.get( nameParameter ) : null; + public String getAttribute(String nameParameter) { + return this.attributes != null ? this.attributes.get(nameParameter) : null; } /** * @param nameParameter The name of the attribute. * @param valueParameter The value of the attribute. */ - public void setAttribute( @Nonnull String nameParameter, @Nonnull String valueParameter ) - { - if ( valueParameter == null ) - { - throw new NullPointerException( "value can not be null" ); + public void setAttribute(@Nonnull String nameParameter, @Nonnull String valueParameter) { + if (valueParameter == null) { + throw new NullPointerException("value can not be null"); } - if ( nameParameter == null ) - { - throw new NullPointerException( "name can not be null" ); + if (nameParameter == null) { + throw new NullPointerException("name can not be null"); } - if ( attributes == null ) - { + if (attributes == null) { attributes = new HashMap(); } - attributes.put( nameParameter, valueParameter ); + attributes.put(nameParameter, valueParameter); } /** * @param i The index to be selected. * @return The child selected by index. */ - public Xpp3Dom getChild( int i ) - { - return childList.get( i ); + public Xpp3Dom getChild(int i) { + return childList.get(i); } /** * @param nameParameter The name of the child. * @return The child selected by name. */ - public Xpp3Dom getChild( String nameParameter ) - { - return childMap.get( nameParameter ); + public Xpp3Dom getChild(String nameParameter) { + return childMap.get(nameParameter); } /** * @param child The child to be added. */ - public void addChild( Xpp3Dom child ) - { - child.setParent( this ); - childList.add( child ); - childMap.put( child.getName(), child ); + public void addChild(Xpp3Dom child) { + child.setParent(this); + childList.add(child); + childMap.put(child.getName(), child); } /** * @return The array of childs. */ - public Xpp3Dom[] getChildren() - { + public Xpp3Dom[] getChildren() { boolean isNothing = childList == null || childList.isEmpty(); - return isNothing ? EMPTY_DOM_ARRAY : childList.toArray( new Xpp3Dom[childList.size()] ); + return isNothing ? EMPTY_DOM_ARRAY : childList.toArray(new Xpp3Dom[childList.size()]); } - private List getChildrenList() - { + private List getChildrenList() { boolean isNothing = childList == null || childList.isEmpty(); return isNothing ? Collections.emptyList() : childList; } @@ -246,26 +223,19 @@ private List getChildrenList() * @param nameParameter The name of the child. * @return The array of the Dom. */ - public Xpp3Dom[] getChildren( String nameParameter ) - { - List children = getChildrenList( nameParameter ); - return children.toArray( new Xpp3Dom[children.size()] ); + public Xpp3Dom[] getChildren(String nameParameter) { + List children = getChildrenList(nameParameter); + return children.toArray(new Xpp3Dom[children.size()]); } - List getChildrenList( String nameParameter ) - { - if ( childList == null ) - { + List getChildrenList(String nameParameter) { + if (childList == null) { return Collections.emptyList(); - } - else - { + } else { ArrayList children = new ArrayList(); - for ( Xpp3Dom aChildList : childList ) - { - if ( nameParameter.equals( aChildList.getName() ) ) - { - children.add( aChildList ); + for (Xpp3Dom aChildList : childList) { + if (nameParameter.equals(aChildList.getName())) { + children.add(aChildList); } } return children; @@ -275,10 +245,8 @@ List getChildrenList( String nameParameter ) /** * @return The number of childs. */ - public int getChildCount() - { - if ( childList == null ) - { + public int getChildCount() { + if (childList == null) { return 0; } @@ -288,27 +256,24 @@ public int getChildCount() /** * @param i The child to be removed. */ - public void removeChild( int i ) - { - Xpp3Dom child = childList.remove( i ); - childMap.values().remove( child ); - child.setParent( null ); + public void removeChild(int i) { + Xpp3Dom child = childList.remove(i); + childMap.values().remove(child); + child.setParent(null); } /** * @return The current parent. */ - public Xpp3Dom getParent() - { + public Xpp3Dom getParent() { return parent; } /** * @param parent Set the parent. */ - public void setParent( Xpp3Dom parent ) - { - this.parent = parent; + public void setParent(Xpp3Dom parent) { + this.parent = parent; } /** @@ -317,9 +282,8 @@ public void setParent( Xpp3Dom parent ) * @param childMergeOverride true if child merge will take precedence false otherwise. * @return The merged Xpp3Dom. */ - public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride ) - { - return Xpp3DomUtils.mergeXpp3Dom( dominant, recessive, childMergeOverride ); + public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) { + return Xpp3DomUtils.mergeXpp3Dom(dominant, recessive, childMergeOverride); } /** @@ -327,88 +291,73 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean * @param recessive The recessive part. * @return The merged Xpp3Dom. */ - public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive ) - { - return Xpp3DomUtils.mergeXpp3Dom( dominant, recessive ); + public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) { + return Xpp3DomUtils.mergeXpp3Dom(dominant, recessive); } /** {@inheritDoc} */ - public boolean equals( Object obj ) - { - if ( obj == this ) - { + public boolean equals(Object obj) { + if (obj == this) { return true; } - if ( !( obj instanceof Xpp3Dom ) ) - { + if (!(obj instanceof Xpp3Dom)) { return false; } Xpp3Dom dom = (Xpp3Dom) obj; - return !( name == null ? dom.name != null : !name.equals( dom.name ) ) - && !( value == null ? dom.value != null : !value.equals( dom.value ) ) - && !( attributes == null ? dom.attributes != null : !attributes.equals( dom.attributes ) ) - && !( childList == null ? dom.childList != null : !childList.equals( dom.childList ) ); + return !(name == null ? dom.name != null : !name.equals(dom.name)) + && !(value == null ? dom.value != null : !value.equals(dom.value)) + && !(attributes == null ? dom.attributes != null : !attributes.equals(dom.attributes)) + && !(childList == null ? dom.childList != null : !childList.equals(dom.childList)); } /** {@inheritDoc} */ - public int hashCode() - { + public int hashCode() { int result = 17; - result = 37 * result + ( name != null ? name.hashCode() : 0 ); - result = 37 * result + ( value != null ? value.hashCode() : 0 ); - result = 37 * result + ( attributes != null ? attributes.hashCode() : 0 ); - result = 37 * result + ( childList != null ? childList.hashCode() : 0 ); + result = 37 * result + (name != null ? name.hashCode() : 0); + result = 37 * result + (value != null ? value.hashCode() : 0); + result = 37 * result + (attributes != null ? attributes.hashCode() : 0); + result = 37 * result + (childList != null ? childList.hashCode() : 0); return result; } /** {@inheritDoc} */ - public String toString() - { - try - { + public String toString() { + try { StringWriter writer = new StringWriter(); - Xpp3DomWriter.write( getPrettyPrintXMLWriter( writer ), this ); + Xpp3DomWriter.write(getPrettyPrintXMLWriter(writer), this); return writer.toString(); - } - catch ( final IOException e ) - { + } catch (final IOException e) { // JDK error in StringWriter. - throw (AssertionError) new AssertionError( "Unexpected IOException from StringWriter." ).initCause( e ); + throw (AssertionError) new AssertionError("Unexpected IOException from StringWriter.").initCause(e); } } /** * @return Unescaped string. */ - public String toUnescapedString() - { - try - { + public String toUnescapedString() { + try { StringWriter writer = new StringWriter(); - Xpp3DomWriter.write( getPrettyPrintXMLWriter( writer ), this, false ); + Xpp3DomWriter.write(getPrettyPrintXMLWriter(writer), this, false); return writer.toString(); - } - catch ( final IOException e ) - { + } catch (final IOException e) { // JDK error in StringWriter. - throw (AssertionError) new AssertionError( "Unexpected IOException from StringWriter." ).initCause( e ); + throw (AssertionError) new AssertionError("Unexpected IOException from StringWriter.").initCause(e); } } - private PrettyPrintXMLWriter getPrettyPrintXMLWriter( StringWriter writer ) - { - return new PrettyPrintXMLWriter( writer, "UTF-8", null ); + private PrettyPrintXMLWriter getPrettyPrintXMLWriter(StringWriter writer) { + return new PrettyPrintXMLWriter(writer, "UTF-8", null); } /** * @param str The string to be checked. * @return true if the string is not empty (length > 0) and not null. */ - public static boolean isNotEmpty( String str ) - { + public static boolean isNotEmpty(String str) { return str != null && str.length() > 0; } @@ -416,14 +365,12 @@ public static boolean isNotEmpty( String str ) * @param str The string to be checked. * @return true if the string is empty or null. */ - public static boolean isEmpty( String str ) - { + public static boolean isEmpty(String str) { return str == null || str.trim().length() == 0; } /** {@inheritDoc} */ - public Iterator iterator() - { + public Iterator iterator() { return getChildrenList().iterator(); } } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java index 2b8f4ab6..640a9c4a 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,13 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; +package org.apache.maven.shared.utils.xml; import javax.annotation.Nonnull; import javax.annotation.WillClose; @@ -37,11 +29,17 @@ import java.util.ArrayList; import java.util.List; +import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.DefaultHandler; + /** * @author Kristian Rosenvold */ -public class Xpp3DomBuilder -{ +public class Xpp3DomBuilder { private static final boolean DEFAULT_TRIM = true; /** @@ -49,10 +47,8 @@ public class Xpp3DomBuilder * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build( @WillClose @Nonnull Reader reader ) - throws XmlPullParserException - { - return build( reader, DEFAULT_TRIM ); + public static Xpp3Dom build(@WillClose @Nonnull Reader reader) throws XmlPullParserException { + return build(reader, DEFAULT_TRIM); } /** @@ -61,10 +57,8 @@ public static Xpp3Dom build( @WillClose @Nonnull Reader reader ) * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding ) - throws XmlPullParserException - { - return build( is, encoding, DEFAULT_TRIM ); + public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding) throws XmlPullParserException { + return build(is, encoding, DEFAULT_TRIM); } /** @@ -74,17 +68,13 @@ public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding, boolean trim ) - throws XmlPullParserException - { - try - { - Reader reader = new InputStreamReader( is, encoding ); - return build( reader, trim ); - } - catch ( UnsupportedEncodingException e ) - { - throw new XmlPullParserException( e ); + public static Xpp3Dom build(@WillClose InputStream is, @Nonnull String encoding, boolean trim) + throws XmlPullParserException { + try { + Reader reader = new InputStreamReader(is, encoding); + return build(reader, trim); + } catch (UnsupportedEncodingException e) { + throw new XmlPullParserException(e); } } @@ -94,95 +84,63 @@ public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding * @return the built DOM * @throws XmlPullParserException in case of an error */ - public static Xpp3Dom build( @WillClose Reader in, boolean trim ) - throws XmlPullParserException - { - try ( Reader reader = in ) - { - DocHandler docHandler = parseSax( new InputSource( reader ), trim ); + public static Xpp3Dom build(@WillClose Reader in, boolean trim) throws XmlPullParserException { + try (Reader reader = in) { + DocHandler docHandler = parseSax(new InputSource(reader), trim); reader.close(); return docHandler.result; - } - catch ( final IOException e ) - { - throw new XmlPullParserException( e ); + } catch (final IOException e) { + throw new XmlPullParserException(e); } } - private static DocHandler parseSax( @Nonnull InputSource inputSource, boolean trim ) - throws XmlPullParserException - { - try - { - DocHandler ch = new DocHandler( trim ); + private static DocHandler parseSax(@Nonnull InputSource inputSource, boolean trim) throws XmlPullParserException { + try { + DocHandler ch = new DocHandler(trim); XMLReader parser = createXmlReader(); - parser.setContentHandler( ch ); - parser.parse( inputSource ); + parser.setContentHandler(ch); + parser.parse(inputSource); return ch; - } - catch ( IOException e ) - { - throw new XmlPullParserException( e ); - } - catch ( SAXException e ) - { - throw new XmlPullParserException( e ); + } catch (IOException e) { + throw new XmlPullParserException(e); + } catch (SAXException e) { + throw new XmlPullParserException(e); } } - - private static XMLReader createXmlReader() - throws SAXException - { - XMLReader comSunXmlReader = instantiate( "com.sun.org.apache.xerces.internal.parsers.SAXParser" ); - if ( comSunXmlReader != null ) - { + private static XMLReader createXmlReader() throws SAXException { + XMLReader comSunXmlReader = instantiate("com.sun.org.apache.xerces.internal.parsers.SAXParser"); + if (comSunXmlReader != null) { return comSunXmlReader; } String key = "org.xml.sax.driver"; - String oldParser = System.getProperty( key ); - System.clearProperty( key ); // There's a "slight" problem with this an parallel maven: It does not work ;) + String oldParser = System.getProperty(key); + System.clearProperty(key); // There's a "slight" problem with this an parallel maven: It does not work ;) - try - { + try { return org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); - } - finally - { - if ( oldParser != null ) - { - System.setProperty( key, oldParser ); + } finally { + if (oldParser != null) { + System.setProperty(key, oldParser); } } - } - private static XMLReader instantiate( String s ) - { - try - { - Class aClass = Thread.currentThread().getContextClassLoader().loadClass( s ); + private static XMLReader instantiate(String s) { + try { + Class aClass = Thread.currentThread().getContextClassLoader().loadClass(s); return (XMLReader) aClass.newInstance(); - } - catch ( ClassNotFoundException e ) - { - return null; - } - catch ( InstantiationException e ) - { - return null; - } - catch ( IllegalAccessException e ) - { - return null; + } catch (ClassNotFoundException e) { + return null; + } catch (InstantiationException e) { + return null; + } catch (IllegalAccessException e) { + return null; } } - - private static class DocHandler - extends DefaultHandler - { + private static class DocHandler extends DefaultHandler { private final List elemStack = new ArrayList(); private final List values = new ArrayList(); @@ -193,96 +151,78 @@ private static class DocHandler private boolean spacePreserve = false; - DocHandler( boolean trim ) - { + DocHandler(boolean trim) { this.trim = trim; } @Override - public void startElement( String uri, String localName, String qName, Attributes attributes ) - throws SAXException - { + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { spacePreserve = false; - Xpp3Dom child = new Xpp3Dom( localName ); + Xpp3Dom child = new Xpp3Dom(localName); - attachToParent( child ); - pushOnStack( child ); + attachToParent(child); + pushOnStack(child); - values.add( new StringBuilder() ); + values.add(new StringBuilder()); int size = attributes.getLength(); - for ( int i = 0; i < size; i++ ) - { - String name = attributes.getQName( i ); - String value = attributes.getValue( i ); - child.setAttribute( name, value ); - spacePreserve = spacePreserve || ( "xml:space".equals( name ) && "preserve".equals( value ) ); + for (int i = 0; i < size; i++) { + String name = attributes.getQName(i); + String value = attributes.getValue(i); + child.setAttribute(name, value); + spacePreserve = spacePreserve || ("xml:space".equals(name) && "preserve".equals(value)); } } - private boolean pushOnStack( Xpp3Dom child ) - { - return elemStack.add( child ); + private boolean pushOnStack(Xpp3Dom child) { + return elemStack.add(child); } - private void attachToParent( Xpp3Dom child ) - { + private void attachToParent(Xpp3Dom child) { int depth = elemStack.size(); - if ( depth > 0 ) - { - elemStack.get( depth - 1 ).addChild( child ); + if (depth > 0) { + elemStack.get(depth - 1).addChild(child); } } - private Xpp3Dom pop() - { + private Xpp3Dom pop() { int depth = elemStack.size() - 1; - return elemStack.remove( depth ); + return elemStack.remove(depth); } @Override - public void endElement( String uri, String localName, String qName ) - throws SAXException - { + public void endElement(String uri, String localName, String qName) throws SAXException { int depth = elemStack.size() - 1; Xpp3Dom element = pop(); /* this Object could be null if it is a singleton tag */ - Object accumulatedValue = values.remove( depth ); + Object accumulatedValue = values.remove(depth); - if ( element.getChildCount() == 0 ) - { - if ( accumulatedValue == null ) - { - element.setValue( "" ); // null in xpp3dom, but we don't do that around here - } - else - { - element.setValue( accumulatedValue.toString() ); + if (element.getChildCount() == 0) { + if (accumulatedValue == null) { + element.setValue(""); // null in xpp3dom, but we don't do that around here + } else { + element.setValue(accumulatedValue.toString()); } } - if ( depth == 0 ) - { + if (depth == 0) { result = element; } } @Override - public void characters( char[] ch, int start, int length ) - throws SAXException - { - String text = new String( ch, start, length ); - appendToTopValue( ( trim && !spacePreserve ) ? text.trim() : text ); + public void characters(char[] ch, int start, int length) throws SAXException { + String text = new String(ch, start, length); + appendToTopValue((trim && !spacePreserve) ? text.trim() : text); } - private void appendToTopValue( String toAppend ) - { + private void appendToTopValue(String toAppend) { // noinspection MismatchedQueryAndUpdateOfStringBuilder - StringBuilder stringBuilder = values.get( values.size() - 1 ); - stringBuilder.append( toAppend ); + StringBuilder stringBuilder = values.get(values.size() - 1); + stringBuilder.append(toAppend); } } - } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomUtils.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomUtils.java index 985c5592..d6d066c6 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomUtils.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml; import java.util.HashMap; import java.util.Iterator; @@ -25,19 +24,17 @@ import java.util.Map; /** - * + * */ -public class Xpp3DomUtils -{ +public class Xpp3DomUtils { /** * @param dominant {@link Xpp3Dom} * @param recessive {@link Xpp3Dom} * @param childMergeOverride true/false. * @return Merged dom. */ - public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride ) - { - return dominant != null ? merge( dominant, recessive, childMergeOverride ) : recessive; + public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) { + return dominant != null ? merge(dominant, recessive, childMergeOverride) : recessive; } /** @@ -45,9 +42,8 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean * @param recessive {@link Xpp3Dom} * @return Merged dom. */ - public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive ) - { - return dominant != null ? merge( dominant, recessive, null ) : recessive; + public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) { + return dominant != null ? merge(dominant, recessive, null) : recessive; } /** @@ -56,107 +52,84 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive ) * @param childMergeOverride true/false. * @return Merged dom. */ - public static Xpp3Dom merge( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride ) - { - if ( recessive == null || isCombineSelfOverride( dominant ) ) - { + public static Xpp3Dom merge(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) { + if (recessive == null || isCombineSelfOverride(dominant)) { return dominant; } - if ( isEmpty( dominant.getValue() ) ) - { - dominant.setValue( recessive.getValue() ); + if (isEmpty(dominant.getValue())) { + dominant.setValue(recessive.getValue()); } - for ( String attr : recessive.getAttributeNames() ) - { - if ( isEmpty( dominant.getAttribute( attr ) ) ) - { - dominant.setAttribute( attr, recessive.getAttribute( attr ) ); + for (String attr : recessive.getAttributeNames()) { + if (isEmpty(dominant.getAttribute(attr))) { + dominant.setAttribute(attr, recessive.getAttribute(attr)); } } - if ( recessive.getChildCount() > 0 ) - { - boolean mergeChildren = isMergeChildren( dominant, childMergeOverride ); + if (recessive.getChildCount() > 0) { + boolean mergeChildren = isMergeChildren(dominant, childMergeOverride); - if ( mergeChildren ) - { - Map> commonChildren = getCommonChildren( dominant, recessive ); - for ( Xpp3Dom recessiveChild : recessive ) - { - Iterator it = commonChildren.get( recessiveChild.getName() ); - if ( it == null ) - { - dominant.addChild( new Xpp3Dom( recessiveChild ) ); - } - else if ( it.hasNext() ) - { + if (mergeChildren) { + Map> commonChildren = getCommonChildren(dominant, recessive); + for (Xpp3Dom recessiveChild : recessive) { + Iterator it = commonChildren.get(recessiveChild.getName()); + if (it == null) { + dominant.addChild(new Xpp3Dom(recessiveChild)); + } else if (it.hasNext()) { Xpp3Dom dominantChild = it.next(); - merge( dominantChild, recessiveChild, childMergeOverride ); + merge(dominantChild, recessiveChild, childMergeOverride); } } - } - else - { + } else { Xpp3Dom[] dominantChildren = dominant.getChildren(); dominant.childList.clear(); - for ( Xpp3Dom child : recessive ) - { - dominant.addChild( new Xpp3Dom( child ) ); + for (Xpp3Dom child : recessive) { + dominant.addChild(new Xpp3Dom(child)); } - for ( Xpp3Dom aDominantChildren : dominantChildren ) - { - dominant.addChild( aDominantChildren ); + for (Xpp3Dom aDominantChildren : dominantChildren) { + dominant.addChild(aDominantChildren); } } } return dominant; } - private static Map> getCommonChildren( Xpp3Dom dominant, Xpp3Dom recessive ) - { + private static Map> getCommonChildren(Xpp3Dom dominant, Xpp3Dom recessive) { Map> commonChildren = new HashMap>(); - for ( String childName : recessive.childMap.keySet() ) - { - List dominantChildren = dominant.getChildrenList( childName ); - if ( dominantChildren.size() > 0 ) - { - commonChildren.put( childName, dominantChildren.iterator() ); + for (String childName : recessive.childMap.keySet()) { + List dominantChildren = dominant.getChildrenList(childName); + if (dominantChildren.size() > 0) { + commonChildren.put(childName, dominantChildren.iterator()); } } return commonChildren; } - private static boolean isCombineSelfOverride( Xpp3Dom xpp3Dom ) - { - String selfMergeMode = xpp3Dom.getAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE ); - return Xpp3Dom.SELF_COMBINATION_OVERRIDE.equals( selfMergeMode ); + private static boolean isCombineSelfOverride(Xpp3Dom xpp3Dom) { + String selfMergeMode = xpp3Dom.getAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE); + return Xpp3Dom.SELF_COMBINATION_OVERRIDE.equals(selfMergeMode); } - private static boolean isMergeChildren( Xpp3Dom dominant, Boolean override ) - { - return override != null ? override : !isMergeChildren( dominant ); + private static boolean isMergeChildren(Xpp3Dom dominant, Boolean override) { + return override != null ? override : !isMergeChildren(dominant); } - private static boolean isMergeChildren( Xpp3Dom dominant ) - { + private static boolean isMergeChildren(Xpp3Dom dominant) { return Xpp3Dom.CHILDREN_COMBINATION_APPEND.equals( - dominant.getAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE ) ); + dominant.getAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE)); } /** - * @deprecated use str == null || String.isBlank(str) (Java 11+) + * @deprecated use str == null || String.isBlank(str) (Java 11+) * or org.apache.commons.lang3.StringUtils.isBlank(str) * @param str the string to be checked * @return true if the string is null, empty, or whitespace only; false otherwise */ @Deprecated - public static boolean isEmpty( String str ) - { + public static boolean isEmpty(String str) { return str == null || str.trim().length() == 0; } - } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomWriter.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomWriter.java index b390c545..f4924985 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomWriter.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomWriter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml; import java.io.IOException; import java.io.PrintWriter; @@ -26,16 +25,14 @@ /** * @author Brett Porter */ -public class Xpp3DomWriter -{ +public class Xpp3DomWriter { /** * @param writer {@link Writer} * @param dom {@link Xpp3Dom} * @throws IOException if writing fails. */ - public static void write( Writer writer, Xpp3Dom dom ) throws IOException - { - write( new PrettyPrintXMLWriter( writer ), dom ); + public static void write(Writer writer, Xpp3Dom dom) throws IOException { + write(new PrettyPrintXMLWriter(writer), dom); } /** @@ -43,9 +40,8 @@ public static void write( Writer writer, Xpp3Dom dom ) throws IOException * @param dom {@link Xpp3Dom} * @throws IOException if writing fails. */ - public static void write( PrintWriter writer, Xpp3Dom dom ) throws IOException - { - write( new PrettyPrintXMLWriter( writer ), dom ); + public static void write(PrintWriter writer, Xpp3Dom dom) throws IOException { + write(new PrettyPrintXMLWriter(writer), dom); } /** @@ -53,9 +49,8 @@ public static void write( PrintWriter writer, Xpp3Dom dom ) throws IOException * @param dom {@link Xpp3Dom} * @throws IOException if writing fails. */ - public static void write( XMLWriter xmlWriter, Xpp3Dom dom ) throws IOException - { - write( xmlWriter, dom, true ); + public static void write(XMLWriter xmlWriter, Xpp3Dom dom) throws IOException { + write(xmlWriter, dom, true); } /** @@ -64,33 +59,25 @@ public static void write( XMLWriter xmlWriter, Xpp3Dom dom ) throws IOException * @param escape true/false. * @throws IOException if writing fails. */ - public static void write( XMLWriter xmlWriter, Xpp3Dom dom, boolean escape ) throws IOException - { - xmlWriter.startElement( dom.getName() ); + public static void write(XMLWriter xmlWriter, Xpp3Dom dom, boolean escape) throws IOException { + xmlWriter.startElement(dom.getName()); String[] attributeNames = dom.getAttributeNames(); - for ( String attributeName : attributeNames ) - { - xmlWriter.addAttribute( attributeName, dom.getAttribute( attributeName ) ); + for (String attributeName : attributeNames) { + xmlWriter.addAttribute(attributeName, dom.getAttribute(attributeName)); } Xpp3Dom[] children = dom.getChildren(); - for ( Xpp3Dom aChildren : children ) - { - write( xmlWriter, aChildren, escape ); + for (Xpp3Dom aChildren : children) { + write(xmlWriter, aChildren, escape); } String value = dom.getValue(); - if ( value != null ) - { - if ( escape ) - { - xmlWriter.writeText( value ); - } - else - { - xmlWriter.writeMarkup( value ); + if (value != null) { + if (escape) { + xmlWriter.writeText(value); + } else { + xmlWriter.writeMarkup(value); } } xmlWriter.endElement(); } - } diff --git a/src/main/java/org/apache/maven/shared/utils/xml/pull/XmlPullParserException.java b/src/main/java/org/apache/maven/shared/utils/xml/pull/XmlPullParserException.java index 3858a902..5f495b11 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/pull/XmlPullParserException.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/pull/XmlPullParserException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml.pull; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,44 +16,34 @@ * specific language governing permissions and limitations * under the License. */ - -import org.xml.sax.SAXException; +package org.apache.maven.shared.utils.xml.pull; import java.io.IOException; -/** - * - */ -public class XmlPullParserException - extends RuntimeException -{ +import org.xml.sax.SAXException; + +public class XmlPullParserException extends RuntimeException { - /** - * - */ private static final long serialVersionUID = 117075811816936575L; /** * @param e IOException. */ - public XmlPullParserException( IOException e ) - { - super( e ); + public XmlPullParserException(IOException e) { + super(e); } /** * @param e The exception. */ - public XmlPullParserException( SAXException e ) - { - super( e ); + public XmlPullParserException(SAXException e) { + super(e); } /** * @param message The message. */ - public XmlPullParserException( String message ) - { - super( message ); + public XmlPullParserException(String message) { + super(message); } } diff --git a/src/test/java/org/apache/maven/shared/utils/CaseTest.java b/src/test/java/org/apache/maven/shared/utils/CaseTest.java index 7eae3028..113c441c 100644 --- a/src/test/java/org/apache/maven/shared/utils/CaseTest.java +++ b/src/test/java/org/apache/maven/shared/utils/CaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; import java.util.Locale; @@ -32,36 +31,33 @@ * give intuitive result, or why one should avoid {@link String#toUpperCase()} and {@link String#toLowerCase()} * (platform locale dependent, with sometimes unexpected results) * but prefer {@link String#equalsIgnoreCase(String)} when possible. - * + * * @author Hervé Boutemy * @see Simple Smiles - Xuelei Fan's Blog */ -public class CaseTest - extends Assert -{ - private final static Locale LOCALE_TURKISH = new Locale( "tr" ); +public class CaseTest extends Assert { + private static final Locale LOCALE_TURKISH = new Locale("tr"); /** common ASCII 'i' */ - private final static char DOTTED_i = '\u0069'; + private static final char DOTTED_i = '\u0069'; /** common ASCII 'I' */ - private final static char DOTLESS_I = '\u0049'; + private static final char DOTLESS_I = '\u0049'; /** turkish dotless i = ı */ - private final static char DOTLESS_i = '\u0131'; + private static final char DOTLESS_i = '\u0131'; /** turkish dotted I = İ */ - private final static char DOTTED_I = '\u0130'; + private static final char DOTTED_I = '\u0130'; /** http://en.wikipedia.org/wiki/Dot_(diacritic) */ - private final static char COMBINING_DOT_ABOVE = '\u0307'; + private static final char COMBINING_DOT_ABOVE = '\u0307'; - private final static Locale SAVED_DEFAULT_LOCALE = Locale.getDefault(); + private static final Locale SAVED_DEFAULT_LOCALE = Locale.getDefault(); @AfterClass - public static void restoreDefaultLocale() - { - Locale.setDefault( SAVED_DEFAULT_LOCALE ); + public static void restoreDefaultLocale() { + Locale.setDefault(SAVED_DEFAULT_LOCALE); } /** @@ -69,42 +65,47 @@ public static void restoreDefaultLocale() * @see The infamous Turkish locale bug */ @Test - public void testTurkishI() - { + public void testTurkishI() { // check common i and I - assertEquals( "common lowercase i should have a dot", 'i', DOTTED_i ); - assertEquals( "common uppercase I should not have a dot", 'I', DOTLESS_I ); + assertEquals("common lowercase i should have a dot", 'i', DOTTED_i); + assertEquals("common uppercase I should not have a dot", 'I', DOTLESS_I); final String iIıİ = "iIıİ"; // check source encoding doesn't wreck havoc */ - assertUnicodeEquals( "misc i directly in (UTF-8) source", iIıİ, "" + DOTTED_i + DOTLESS_I + DOTLESS_i - + DOTTED_I ); + assertUnicodeEquals( + "misc i directly in (UTF-8) source", iIıİ, "" + DOTTED_i + DOTLESS_I + DOTLESS_i + DOTTED_I); // check toUpperCase and toLowerCase difference with turkish and english locales - assertUnicodeEquals( "'iIıİ'.toUpperCase('tr')=='İIIİ'", "" + DOTTED_I + DOTLESS_I + DOTLESS_I + DOTTED_I, - iIıİ.toUpperCase( LOCALE_TURKISH ) ); - assertUnicodeEquals( "'iIıİ'.toLowerCase('tr')=='iııi'", "" + DOTTED_i + DOTLESS_i + DOTLESS_i + DOTTED_i, - iIıİ.toLowerCase( LOCALE_TURKISH ) ); - assertUnicodeEquals( "'iIıİ'.toUpperCase('en')=='IIIİ'", "" + DOTLESS_I + DOTLESS_I + DOTLESS_I + DOTTED_I, - iIıİ.toUpperCase( Locale.ENGLISH ) ); - String lower = iIıİ.toLowerCase( Locale.ENGLISH ); // on some platforms, ends with extra COMBINED DOT ABOVE - assertUnicodeEquals( "'iIıİ'.toLowerCase('en')=='iiıi'", "" + DOTTED_i + DOTTED_i + DOTLESS_i + DOTTED_i - + ( lower.length() > 4 ? COMBINING_DOT_ABOVE : "" ), lower ); + assertUnicodeEquals( + "'iIıİ'.toUpperCase('tr')=='İIIİ'", + "" + DOTTED_I + DOTLESS_I + DOTLESS_I + DOTTED_I, + iIıİ.toUpperCase(LOCALE_TURKISH)); + assertUnicodeEquals( + "'iIıİ'.toLowerCase('tr')=='iııi'", + "" + DOTTED_i + DOTLESS_i + DOTLESS_i + DOTTED_i, + iIıİ.toLowerCase(LOCALE_TURKISH)); + assertUnicodeEquals( + "'iIıİ'.toUpperCase('en')=='IIIİ'", + "" + DOTLESS_I + DOTLESS_I + DOTLESS_I + DOTTED_I, + iIıİ.toUpperCase(Locale.ENGLISH)); + String lower = iIıİ.toLowerCase(Locale.ENGLISH); // on some platforms, ends with extra COMBINED DOT ABOVE + assertUnicodeEquals( + "'iIıİ'.toLowerCase('en')=='iiıi'", + "" + DOTTED_i + DOTTED_i + DOTLESS_i + DOTTED_i + (lower.length() > 4 ? COMBINING_DOT_ABOVE : ""), + lower); // check equalsIgnoreCase() , which has no locale - for ( int i = 0; i < iIıİ.length(); i++ ) - { - char currentI = iIıİ.charAt( i ); - - StringBuilder sb = new StringBuilder( iIıİ.length() ); - for ( int j = 0; j < iIıİ.length(); j++ ) - { - sb.append( currentI ); + for (int i = 0; i < iIıİ.length(); i++) { + char currentI = iIıİ.charAt(i); + + StringBuilder sb = new StringBuilder(iIıİ.length()); + for (int j = 0; j < iIıİ.length(); j++) { + sb.append(currentI); } String current = sb.toString(); - assertTrue( "'" + current + "'.equalsIgnoreCase('" + iIıİ + "')", current.equalsIgnoreCase( iIıİ ) ); + assertTrue("'" + current + "'.equalsIgnoreCase('" + iIıİ + "')", current.equalsIgnoreCase(iIıİ)); } } @@ -114,15 +115,13 @@ public void testTurkishI() * @param expected * @param actual */ - private void assertUnicodeEquals( String message, String expected, String actual ) - { - if ( expected.equals( actual ) ) - { + private void assertUnicodeEquals(String message, String expected, String actual) { + if (expected.equals(actual)) { return; } - throw new ComparisonFailure( message, StringEscapeUtils.escapeJava( expected ), - StringEscapeUtils.escapeJava( actual ) ); + throw new ComparisonFailure( + message, StringEscapeUtils.escapeJava(expected), StringEscapeUtils.escapeJava(actual)); } /** @@ -130,43 +129,46 @@ private void assertUnicodeEquals( String message, String expected, String actual * exception on these characters. */ @Test - public void testAsciiAvailableLocales() - { + public void testAsciiAvailableLocales() { final String lower = "abcdefghijklmnopqrstuvwxyz"; final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - for ( Locale locale : Locale.getAvailableLocales() ) - { + for (Locale locale : Locale.getAvailableLocales()) { // check that toUpper() == toUpper(default locale) and toLower() = toLower(default locale) - Locale.setDefault( locale ); - assertEquals( lower.toUpperCase(), lower.toUpperCase( locale ) ); - assertEquals( upper.toLowerCase(), upper.toLowerCase( locale ) ); + Locale.setDefault(locale); + assertEquals(lower.toUpperCase(), lower.toUpperCase(locale)); + assertEquals(upper.toLowerCase(), upper.toLowerCase(locale)); // check result String expectedToUpperCase = upper; String expectedToLowerCase = lower; - if ( LOCALE_TURKISH.getLanguage().equals( locale.getLanguage() ) || - new Locale( "az" ).getLanguage().equals( locale.getLanguage() ) ) - { - expectedToUpperCase = upper.replace( DOTLESS_I, DOTTED_I ); - expectedToLowerCase = lower.replace( DOTTED_i, DOTLESS_i ); + if (LOCALE_TURKISH.getLanguage().equals(locale.getLanguage()) + || new Locale("az").getLanguage().equals(locale.getLanguage())) { + expectedToUpperCase = upper.replace(DOTLESS_I, DOTTED_I); + expectedToLowerCase = lower.replace(DOTTED_i, DOTLESS_i); } - assertEquals( "'" + lower + "'.toUpperCase('" + locale.toString() + "')", expectedToUpperCase, - lower.toUpperCase( locale ) ); - assertEquals( "'" + upper + "'.toLowerCase('" + locale.toString() + "')", expectedToLowerCase, - upper.toLowerCase( locale ) ); + assertEquals( + "'" + lower + "'.toUpperCase('" + locale.toString() + "')", + expectedToUpperCase, + lower.toUpperCase(locale)); + assertEquals( + "'" + upper + "'.toLowerCase('" + locale.toString() + "')", + expectedToLowerCase, + upper.toLowerCase(locale)); // check that toLowerCase on lower and toUpperCase on upper don't cause harm - assertEquals( "'" + lower + "'.toLowerCase('" + locale.toString() + "')", lower, lower.toLowerCase( locale ) ); - assertEquals( "'" + upper + "'.toUpperCase('" + locale.toString() + "')", upper, upper.toUpperCase( locale ) ); + assertEquals("'" + lower + "'.toLowerCase('" + locale.toString() + "')", lower, lower.toLowerCase(locale)); + assertEquals("'" + upper + "'.toUpperCase('" + locale.toString() + "')", upper, upper.toUpperCase(locale)); // check equalsIgnoreCase - assertTrue( "'" + upper + "'.equalsIgnoreCase('" + lower + "')", upper.equalsIgnoreCase( lower ) ); - assertTrue( "'" + upper + "'.equalsIgnoreCase('" + expectedToLowerCase + "')", - upper.equalsIgnoreCase( expectedToLowerCase ) ); - assertTrue( "'" + expectedToUpperCase + "'.equalsIgnoreCase('" + lower + "')", - expectedToUpperCase.equalsIgnoreCase( lower ) ); + assertTrue("'" + upper + "'.equalsIgnoreCase('" + lower + "')", upper.equalsIgnoreCase(lower)); + assertTrue( + "'" + upper + "'.equalsIgnoreCase('" + expectedToLowerCase + "')", + upper.equalsIgnoreCase(expectedToLowerCase)); + assertTrue( + "'" + expectedToUpperCase + "'.equalsIgnoreCase('" + lower + "')", + expectedToUpperCase.equalsIgnoreCase(lower)); } } } diff --git a/src/test/java/org/apache/maven/shared/utils/OsTest.java b/src/test/java/org/apache/maven/shared/utils/OsTest.java index 951c9fc2..e5a321a0 100644 --- a/src/test/java/org/apache/maven/shared/utils/OsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/OsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,13 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; + +import java.util.Set; -import org.junit.Test; -import org.junit.Before; import org.junit.After; import org.junit.Assert; - -import java.util.Set; +import org.junit.Before; +import org.junit.Test; import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.MatcherAssert.assertThat; @@ -34,156 +33,118 @@ * * @author Mark Struberg */ -public class OsTest -{ +public class OsTest { private String origOsName; private String origOsArch; private String origOsVersion; - @Before - public void setUp() - { - origOsName = System.getProperty( "os.name" ); - origOsArch = System.getProperty( "os.arch" ); - origOsVersion = System.getProperty( "os.version" ); + public void setUp() { + origOsName = System.getProperty("os.name"); + origOsArch = System.getProperty("os.arch"); + origOsVersion = System.getProperty("os.version"); // and now set some special settings ;) - System.setProperty( "os.name" , "os/2" ); - System.setProperty( "os.arch" , "i386" ); - System.setProperty( "os.version", "2.1.32" ); + System.setProperty("os.name", "os/2"); + System.setProperty("os.arch", "i386"); + System.setProperty("os.version", "2.1.32"); } @After - public void tearDown() - { + public void tearDown() { // set the original OS settings again - System.setProperty( "os.name" , origOsName ); - System.setProperty( "os.arch" , origOsArch ); - System.setProperty( "os.version", origOsVersion ); + System.setProperty("os.name", origOsName); + System.setProperty("os.arch", origOsArch); + System.setProperty("os.version", origOsVersion); } @Test - public void testConstructor() - { - Os os = new Os(); + public void testConstructor() { + Os os = new Os(); os.eval(); - Assert.assertTrue( Os.isName( Os.FAMILY_OS2 ) ); - - Assert.assertFalse( Os.isName( Os.FAMILY_DOS ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_MAC ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_NETWARE ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_OPENVMS ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_OS400 ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_TANDEM ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_UNIX ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_WIN9X ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_WINDOWS ) ); - Assert.assertFalse( Os.isName( Os.FAMILY_ZOS ) ); + Assert.assertTrue(Os.isName(Os.FAMILY_OS2)); + + Assert.assertFalse(Os.isName(Os.FAMILY_DOS)); + Assert.assertFalse(Os.isName(Os.FAMILY_MAC)); + Assert.assertFalse(Os.isName(Os.FAMILY_NETWARE)); + Assert.assertFalse(Os.isName(Os.FAMILY_OPENVMS)); + Assert.assertFalse(Os.isName(Os.FAMILY_OS400)); + Assert.assertFalse(Os.isName(Os.FAMILY_TANDEM)); + Assert.assertFalse(Os.isName(Os.FAMILY_UNIX)); + Assert.assertFalse(Os.isName(Os.FAMILY_WIN9X)); + Assert.assertFalse(Os.isName(Os.FAMILY_WINDOWS)); + Assert.assertFalse(Os.isName(Os.FAMILY_ZOS)); } @Test - public void testFamilyNames() - { - Assert.assertEquals( Os.FAMILY_DOS, "dos" ); - Assert.assertEquals( Os.FAMILY_MAC, "mac" ); - Assert.assertEquals( Os.FAMILY_NETWARE, "netware" ); - Assert.assertEquals( Os.FAMILY_OPENVMS, "openvms" ); - Assert.assertEquals( Os.FAMILY_OS2, "os/2" ); - Assert.assertEquals( Os.FAMILY_OS400, "os/400" ); - Assert.assertEquals( Os.FAMILY_TANDEM, "tandem" ); - Assert.assertEquals( Os.FAMILY_UNIX, "unix" ); - Assert.assertEquals( Os.FAMILY_WIN9X, "win9x" ); - Assert.assertEquals( Os.FAMILY_WINDOWS, "windows" ); - Assert.assertEquals( Os.FAMILY_ZOS, "z/os" ); + public void testFamilyNames() { + Assert.assertEquals(Os.FAMILY_DOS, "dos"); + Assert.assertEquals(Os.FAMILY_MAC, "mac"); + Assert.assertEquals(Os.FAMILY_NETWARE, "netware"); + Assert.assertEquals(Os.FAMILY_OPENVMS, "openvms"); + Assert.assertEquals(Os.FAMILY_OS2, "os/2"); + Assert.assertEquals(Os.FAMILY_OS400, "os/400"); + Assert.assertEquals(Os.FAMILY_TANDEM, "tandem"); + Assert.assertEquals(Os.FAMILY_UNIX, "unix"); + Assert.assertEquals(Os.FAMILY_WIN9X, "win9x"); + Assert.assertEquals(Os.FAMILY_WINDOWS, "windows"); + Assert.assertEquals(Os.FAMILY_ZOS, "z/os"); } @Test - public void testGetValidFamilies() - { + public void testGetValidFamilies() { Set osFamilies = Os.getValidFamilies(); - Assert.assertTrue( "OsFamilies Set size" - , osFamilies.size() >= 11 ); - - Assert.assertTrue( osFamilies.contains( Os.FAMILY_DOS ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_MAC ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_NETWARE ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_OPENVMS ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_OS2 ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_OS400 ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_TANDEM ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_UNIX ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_WIN9X ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_WINDOWS ) ); - Assert.assertTrue( osFamilies.contains( Os.FAMILY_ZOS ) ); - + Assert.assertTrue("OsFamilies Set size", osFamilies.size() >= 11); + + Assert.assertTrue(osFamilies.contains(Os.FAMILY_DOS)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_MAC)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_NETWARE)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_OPENVMS)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS2)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS400)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_TANDEM)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_UNIX)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_WIN9X)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_WINDOWS)); + Assert.assertTrue(osFamilies.contains(Os.FAMILY_ZOS)); } - @Test - public void testIsArch() - { - assertThat( "Arch is i386" - , Os.isArch( "i386" ) - , is( true ) ); - - assertThat( "Os is not Mac" - , Os.isArch( "x86_64" ) - , is( false ) ); + public void testIsArch() { + assertThat("Arch is i386", Os.isArch("i386"), is(true)); + + assertThat("Os is not Mac", Os.isArch("x86_64"), is(false)); } @Test - public void testIsFamily() - { - assertThat( "Family is os/2" - , Os.isFamily( Os.FAMILY_OS2 ) - , is( true ) ); - - assertThat( "Family is not mac" - , Os.isFamily( Os.FAMILY_MAC ) - , is( false ) ); + public void testIsFamily() { + assertThat("Family is os/2", Os.isFamily(Os.FAMILY_OS2), is(true)); + + assertThat("Family is not mac", Os.isFamily(Os.FAMILY_MAC), is(false)); } @Test - public void testIsName() - { - assertThat( "Name is os/2" - , Os.isName( "os/2" ) - , is( true ) ); - - assertThat( "Name is not Mac OS X" - , Os.isName( "Mac OS X" ) - , is( false ) ); + public void testIsName() { + assertThat("Name is os/2", Os.isName("os/2"), is(true)); + + assertThat("Name is not Mac OS X", Os.isName("Mac OS X"), is(false)); } @Test - public void testIsValidFamily() - { - assertThat( "os/2 isValidFamily" - , Os.isValidFamily( Os.FAMILY_OS2 ) - , is( true ) ); - - assertThat( "iPone != isValidFamily" - , Os.isValidFamily( "iPhone" ) - , is( false ) ); + public void testIsValidFamily() { + assertThat("os/2 isValidFamily", Os.isValidFamily(Os.FAMILY_OS2), is(true)); + + assertThat("iPone != isValidFamily", Os.isValidFamily("iPhone"), is(false)); } @Test - public void testIsVersion() - { - assertThat( "isVersion" - , Os.isVersion( "2.1.32" ) - , is( true ) ); - - assertThat( "isVersion" - , Os.isVersion( "2.1" ) - , is( false ) ); + public void testIsVersion() { + assertThat("isVersion", Os.isVersion("2.1.32"), is(true)); - assertThat( "isVersion" - , Os.isVersion( "4.5" ) - , is( false ) ); + assertThat("isVersion", Os.isVersion("2.1"), is(false)); + assertThat("isVersion", Os.isVersion("4.5"), is(false)); } } diff --git a/src/test/java/org/apache/maven/shared/utils/PathToolTest.java b/src/test/java/org/apache/maven/shared/utils/PathToolTest.java index f8db74ff..3aa0da39 100644 --- a/src/test/java/org/apache/maven/shared/utils/PathToolTest.java +++ b/src/test/java/org/apache/maven/shared/utils/PathToolTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; + +import java.io.File; import org.hamcrest.CoreMatchers; import org.junit.Assume; @@ -25,134 +26,98 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; - -import java.io.File; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; - /** * Test the {@link PathTool} class. * * @author Mark Struberg */ -public class PathToolTest -{ +public class PathToolTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); @Test // Keep in sync with testGetRelativeFilePath_Windows() - public void testGetRelativeFilePath_NonWindows() - { - Assume.assumeThat( File.separatorChar, is( '/' ) ); + public void testGetRelativeFilePath_NonWindows() { + Assume.assumeThat(File.separatorChar, is('/')); - assertThat( PathTool.getRelativeFilePath( null, null ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath(null, null), is("")); - assertThat( PathTool.getRelativeFilePath( null, "/usr/local/java/bin" ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath(null, "/usr/local/java/bin"), is("")); - assertThat( PathTool.getRelativeFilePath( "/usr/local", null ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local", null), is("")); - assertThat( PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin" ) - , is( "java/bin" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"), is("java/bin")); - assertThat( PathTool.getRelativeFilePath( "/usr/local", "/usr/local/java/bin/" ) - , is( "java/bin/" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"), is("java/bin/")); - assertThat( PathTool.getRelativeFilePath( "/usr/local/java/bin", "/usr/local/" ) - , is( "../../" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"), is("../../")); - assertThat( PathTool.getRelativeFilePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) - , is( "java/bin/java.sh" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("java/bin/java.sh")); - assertThat( PathTool.getRelativeFilePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) - , is( "../../../" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"), is("../../../")); - assertThat( PathTool.getRelativeFilePath( "/usr/local/", "/bin" ) - , is( "../../bin" ) ); + assertThat(PathTool.getRelativeFilePath("/usr/local/", "/bin"), is("../../bin")); - assertThat( PathTool.getRelativeFilePath( "/bin", "/usr/local/" ) - , is( "../usr/local/" ) ); + assertThat(PathTool.getRelativeFilePath("/bin", "/usr/local/"), is("../usr/local/")); } - + @Test // Keep in sync with testGetRelativeFilePath_NonWindows() - public void testGetRelativeFilePath_Windows() - { - Assume.assumeThat( File.separatorChar, is( '\\' ) ); + public void testGetRelativeFilePath_Windows() { + Assume.assumeThat(File.separatorChar, is('\\')); - assertThat( PathTool.getRelativeFilePath( null, null ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath(null, null), is("")); - assertThat( PathTool.getRelativeFilePath( null, "c:\\usr\\local\\java\\bin" ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath(null, "c:\\usr\\local\\java\\bin"), is("")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local", null ) - , is( "" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", null), is("")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local", "c:\\usr\\local\\java\\bin" ) - , is( "java\\bin" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin"), is("java\\bin")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local", "c:\\usr\\local\\java\\bin\\" ) - , is( "java\\bin\\" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin\\"), is("java\\bin\\")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local\\java\\bin", "c:\\usr\\local\\" ) - , is( "..\\..\\" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin", "c:\\usr\\local\\"), is("..\\..\\")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local\\", "c:\\usr\\local\\java\\bin\\java.sh" ) - , is( "java\\bin\\java.sh" ) ); + assertThat( + PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\usr\\local\\java\\bin\\java.sh"), + is("java\\bin\\java.sh")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local\\java\\bin\\java.sh", "c:\\usr\\local\\" ) - , is( "..\\..\\..\\" ) ); + assertThat( + PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin\\java.sh", "c:\\usr\\local\\"), + is("..\\..\\..\\")); - assertThat( PathTool.getRelativeFilePath( "c:\\usr\\local\\", "c:\\bin" ) - , is( "..\\..\\bin" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\bin"), is("..\\..\\bin")); - assertThat( PathTool.getRelativeFilePath( "c:\\bin", "c:\\usr\\local\\" ) - , is( "..\\usr\\local\\" ) ); + assertThat(PathTool.getRelativeFilePath("c:\\bin", "c:\\usr\\local\\"), is("..\\usr\\local\\")); } @Test - public void testGetRelativePath_2parm() - { - assertThat( PathTool.getRelativePath( null, null ) - , is( "" ) ); + public void testGetRelativePath_2parm() { + assertThat(PathTool.getRelativePath(null, null), is("")); - assertThat( PathTool.getRelativePath( null, "/usr/local/java/bin" ) - , is( "" ) ); + assertThat(PathTool.getRelativePath(null, "/usr/local/java/bin"), is("")); - assertThat( PathTool.getRelativePath( "/usr/local/", null ) - , is( "" ) ); + assertThat(PathTool.getRelativePath("/usr/local/", null), is("")); - assertThat( PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin" ) - , is( ".." ) ); + assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"), is("..")); - assertThat( PathTool.getRelativePath( "/usr/local/", "/usr/local/java/bin/java.sh" ) - , is( "../.." ) ); + assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("../..")); - assertThat( PathTool.getRelativePath( "/usr/local/java/bin/java.sh", "/usr/local/" ) - , is( "" ) ); + assertThat(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"), is("")); } @Test - public void testUppercaseDrive() - { - assertThat( PathTool.uppercaseDrive( null ) - , CoreMatchers.nullValue() ); + public void testUppercaseDrive() { + assertThat(PathTool.uppercaseDrive(null), CoreMatchers.nullValue()); - assertThat( PathTool.uppercaseDrive( "d:" ) - , is( "D:" ) ); + assertThat(PathTool.uppercaseDrive("d:"), is("D:")); - assertThat( PathTool.uppercaseDrive( "D:" ) - , is( "D:" ) ); + assertThat(PathTool.uppercaseDrive("D:"), is("D:")); - assertThat( PathTool.uppercaseDrive( "/notadrive" ) - , is( "/notadrive" ) ); + assertThat(PathTool.uppercaseDrive("/notadrive"), is("/notadrive")); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java index 0c696415..24940a9f 100644 --- a/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; import java.io.ByteArrayInputStream; import java.io.File; @@ -41,155 +40,122 @@ import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; -public class PropertyUtilsTest -{ +public class PropertyUtilsTest { - @Retention( RetentionPolicy.RUNTIME ) - @Target( ElementType.METHOD ) - @interface NeedsTemporaryFolder - { - } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface NeedsTemporaryFolder {} @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); @Test - @SuppressWarnings( "deprecation" ) + @SuppressWarnings("deprecation") // @ReproducesPlexusBug( "Should return null on error like url and file do" ) - public void loadNullInputStream() - throws Exception - { - assertThat( PropertyUtils.loadProperties( (InputStream) null ), is( new Properties() ) ); + public void loadNullInputStream() throws Exception { + assertThat(PropertyUtils.loadProperties((InputStream) null), is(new Properties())); } @Test - public void loadOptionalNullInputStream() - throws Exception - { - assertThat( PropertyUtils.loadOptionalProperties( (InputStream) null ), is( new Properties() ) ); + public void loadOptionalNullInputStream() throws Exception { + assertThat(PropertyUtils.loadOptionalProperties((InputStream) null), is(new Properties())); } - @Test - public void loadOptionalProperties_ioException() - throws Exception - { - URL url = new URL( "https://nonesuch12344.foo.bar.com" ); - assertThat( PropertyUtils.loadOptionalProperties( url ), is( new Properties() ) ); + public void loadOptionalProperties_ioException() throws Exception { + URL url = new URL("https://nonesuch12344.foo.bar.com"); + assertThat(PropertyUtils.loadOptionalProperties(url), is(new Properties())); } @Test - @SuppressWarnings( "deprecation" ) - public void loadNullURL() - throws Exception - { - assertThat( PropertyUtils.loadProperties( (URL) null ), nullValue( Properties.class ) ); + @SuppressWarnings("deprecation") + public void loadNullURL() throws Exception { + assertThat(PropertyUtils.loadProperties((URL) null), nullValue(Properties.class)); } @Test - public void loadOptionalNullURL() - throws Exception - { - assertThat( PropertyUtils.loadOptionalProperties( (URL) null ), is( new Properties() ) ); + public void loadOptionalNullURL() throws Exception { + assertThat(PropertyUtils.loadOptionalProperties((URL) null), is(new Properties())); } @Test - @SuppressWarnings( "deprecation" ) - public void loadNullFile() - throws Exception - { - assertThat( PropertyUtils.loadProperties( (File) null ), nullValue( Properties.class ) ); + @SuppressWarnings("deprecation") + public void loadNullFile() throws Exception { + assertThat(PropertyUtils.loadProperties((File) null), nullValue(Properties.class)); } @Test - public void loadOptionalNullFile() - throws Exception - { - assertThat( PropertyUtils.loadOptionalProperties( (File) null ), is( new Properties() ) ); + public void loadOptionalNullFile() throws Exception { + assertThat(PropertyUtils.loadOptionalProperties((File) null), is(new Properties())); } @Test - @SuppressWarnings( "deprecation" ) - public void loadEmptyInputStream() - throws Exception - { - assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( new byte[ 0 ] ) ), - is( new Properties() ) ); - - assertThat( PropertyUtils.loadOptionalProperties( new ByteArrayInputStream( new byte[ 0 ] ) ), - is( new Properties() ) ); + @SuppressWarnings("deprecation") + public void loadEmptyInputStream() throws Exception { + assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])), is(new Properties())); + assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])), is(new Properties())); } @Test @NeedsTemporaryFolder - @SuppressWarnings( "deprecation" ) - public void loadEmptyFile() - throws Exception - { - assertThat( PropertyUtils.loadProperties( tempFolder.newFile( "empty" ) ), is( new Properties() ) ); - assertThat( PropertyUtils.loadOptionalProperties( tempFolder.newFile( "optional" ) ), is( new Properties() ) ); + @SuppressWarnings("deprecation") + public void loadEmptyFile() throws Exception { + assertThat(PropertyUtils.loadProperties(tempFolder.newFile("empty")), is(new Properties())); + assertThat(PropertyUtils.loadOptionalProperties(tempFolder.newFile("optional")), is(new Properties())); } @Test @NeedsTemporaryFolder - @SuppressWarnings( "deprecation" ) - public void loadEmptyURL() - throws Exception - { - assertThat( PropertyUtils.loadProperties( tempFolder.newFile( "empty" ).toURI().toURL() ), - is( new Properties() ) ); - - assertThat( PropertyUtils.loadOptionalProperties( tempFolder.newFile( "optional" ).toURI().toURL() ), - is( new Properties() ) ); - + @SuppressWarnings("deprecation") + public void loadEmptyURL() throws Exception { + assertThat( + PropertyUtils.loadProperties(tempFolder.newFile("empty").toURI().toURL()), is(new Properties())); + + assertThat( + PropertyUtils.loadOptionalProperties( + tempFolder.newFile("optional").toURI().toURL()), + is(new Properties())); } @Test - @SuppressWarnings( "deprecation" ) - public void loadValidInputStream() throws UnsupportedEncodingException - { + @SuppressWarnings("deprecation") + public void loadValidInputStream() throws UnsupportedEncodingException { Properties value = new Properties(); - value.setProperty( "a", "b" ); + value.setProperty("a", "b"); - assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( "a=b".getBytes( "ISO-8859-1" ) ) ), - is( value ) ); - - assertThat( PropertyUtils.loadOptionalProperties( new ByteArrayInputStream( "a=b".getBytes( "ISO-8859-1" ) ) ), - is( value ) ); + assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))), is(value)); + assertThat( + PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))), + is(value)); } @Test @NeedsTemporaryFolder - @SuppressWarnings( "deprecation" ) - public void loadValidFile() throws IOException - { - File valid = tempFolder.newFile( "valid" ); + @SuppressWarnings("deprecation") + public void loadValidFile() throws IOException { + File valid = tempFolder.newFile("valid"); Properties value = new Properties(); - value.setProperty( "a", "b" ); - try ( OutputStream out = new FileOutputStream( valid ) ) - { - value.store( out, "a test" ); - assertThat( PropertyUtils.loadProperties( valid ), is( value ) ); - assertThat( PropertyUtils.loadOptionalProperties( valid ), is( value ) ); + value.setProperty("a", "b"); + try (OutputStream out = new FileOutputStream(valid)) { + value.store(out, "a test"); + assertThat(PropertyUtils.loadProperties(valid), is(value)); + assertThat(PropertyUtils.loadOptionalProperties(valid), is(value)); } } @Test @NeedsTemporaryFolder - @SuppressWarnings( "deprecation" ) - public void loadValidURL() throws IOException - { - File valid = tempFolder.newFile( "valid" ); + @SuppressWarnings("deprecation") + public void loadValidURL() throws IOException { + File valid = tempFolder.newFile("valid"); Properties value = new Properties(); - value.setProperty( "a", "b" ); - try ( OutputStream out = new FileOutputStream( valid ) ) - { - value.store( out, "a test" ); - assertThat( PropertyUtils.loadProperties( valid.toURI().toURL() ), is( value ) ); - assertThat( PropertyUtils.loadOptionalProperties( valid.toURI().toURL() ), is( value ) ); + value.setProperty("a", "b"); + try (OutputStream out = new FileOutputStream(valid)) { + value.store(out, "a test"); + assertThat(PropertyUtils.loadProperties(valid.toURI().toURL()), is(value)); + assertThat(PropertyUtils.loadOptionalProperties(valid.toURI().toURL()), is(value)); } } - } diff --git a/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java index 505cf508..5ef56f6e 100644 --- a/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/StringUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; import java.util.ArrayList; import java.util.HashMap; @@ -32,2049 +31,1479 @@ /** * Test the {@link StringUtils} class. - * + * * @author Mark Struberg */ -public class StringUtilsTest -{ +public class StringUtilsTest { - @Test( expected = NullPointerException.class ) - public void testAbbreviate_NPE() - { - assertThat( StringUtils.abbreviate( null, 10 ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testAbbreviate_NPE() { + assertThat(StringUtils.abbreviate(null, 10), nullValue()); } - @Test( expected = IllegalArgumentException.class ) - public void testAbbreviate_MinLength() - { - assertThat( StringUtils.abbreviate( "This is a longtext", 3 ) - , is( "T" ) ); + @Test(expected = IllegalArgumentException.class) + public void testAbbreviate_MinLength() { + assertThat(StringUtils.abbreviate("This is a longtext", 3), is("T")); } @Test - public void testAbbreviate() - { - assertThat( StringUtils.abbreviate( "This is a longtext", 10 ) - , is( "This is..." ) ); + public void testAbbreviate() { + assertThat(StringUtils.abbreviate("This is a longtext", 10), is("This is...")); - assertThat( StringUtils.abbreviate( "This is a longtext", 50 ) - , is( "This is a longtext" ) ); + assertThat(StringUtils.abbreviate("This is a longtext", 50), is("This is a longtext")); } - @Test( expected = NullPointerException.class ) - public void testAbbreviate_Offset_NPE() - { - assertThat( StringUtils.abbreviate( null, 10, 20 ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testAbbreviate_Offset_NPE() { + assertThat(StringUtils.abbreviate(null, 10, 20), nullValue()); } - @Test( expected = IllegalArgumentException.class ) - public void testAbbreviate_Offset_MinLength() - { - assertThat( StringUtils.abbreviate( "This is a longtext", 10, 3 ) - , is( "T" ) ); + @Test(expected = IllegalArgumentException.class) + public void testAbbreviate_Offset_MinLength() { + assertThat(StringUtils.abbreviate("This is a longtext", 10, 3), is("T")); } @Test - public void testAbbreviate_Offset() - { - assertThat( StringUtils.abbreviate( "This is a longtext", 5, 10 ) - , is( "...is a..." ) ); + public void testAbbreviate_Offset() { + assertThat(StringUtils.abbreviate("This is a longtext", 5, 10), is("...is a...")); - assertThat( StringUtils.abbreviate( "This is a longtext", 10, 20 ) - , is( "This is a longtext" ) ); + assertThat(StringUtils.abbreviate("This is a longtext", 10, 20), is("This is a longtext")); - assertThat( StringUtils.abbreviate( "This is a longtext", 50, 20 ) - , is( "This is a longtext" ) ); + assertThat(StringUtils.abbreviate("This is a longtext", 50, 20), is("This is a longtext")); } - @Test( expected = NullPointerException.class ) - public void testAddAndDeHump_NPE() - { - StringUtils.addAndDeHump( null ); + @Test(expected = NullPointerException.class) + public void testAddAndDeHump_NPE() { + StringUtils.addAndDeHump(null); } @Test - public void testAddAndDeHump() - { - assertThat( StringUtils.addAndDeHump( "lalala" ) - , is( "lalala" ) ); - - assertThat( StringUtils.addAndDeHump( "LaLaLa" ) - , is( "la-la-la" ) ); + public void testAddAndDeHump() { + assertThat(StringUtils.addAndDeHump("lalala"), is("lalala")); - assertThat( StringUtils.addAndDeHump( "ALLUPPER" ) - , is( "a-l-l-u-p-p-e-r" ) ); + assertThat(StringUtils.addAndDeHump("LaLaLa"), is("la-la-la")); + assertThat(StringUtils.addAndDeHump("ALLUPPER"), is("a-l-l-u-p-p-e-r")); } @Test - public void testCapitalise() - { - assertThat( StringUtils.capitalise( null ) - , nullValue() ); + public void testCapitalise() { + assertThat(StringUtils.capitalise(null), nullValue()); - assertThat( StringUtils.capitalise( "startBig" ) - , is( "StartBig" ) ); + assertThat(StringUtils.capitalise("startBig"), is("StartBig")); } @Test - public void testCapitaliseAllWords() - { - assertThat( StringUtils.capitaliseAllWords( null ) - , nullValue() ); + public void testCapitaliseAllWords() { + assertThat(StringUtils.capitaliseAllWords(null), nullValue()); - assertThat( StringUtils.capitaliseAllWords( "start all big" ) - , is( "Start All Big" ) ); + assertThat(StringUtils.capitaliseAllWords("start all big"), is("Start All Big")); } - @Test( expected = NullPointerException.class ) - public void testCapitalizeFirstLetter_NPE() - { - assertThat( StringUtils.capitalizeFirstLetter( null ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testCapitalizeFirstLetter_NPE() { + assertThat(StringUtils.capitalizeFirstLetter(null), nullValue()); } @Test - public void testCapitalizeFirstLetter() - { - assertThat( StringUtils.capitalizeFirstLetter( "Dings" ) - , is( "Dings" ) ); + public void testCapitalizeFirstLetter() { + assertThat(StringUtils.capitalizeFirstLetter("Dings"), is("Dings")); - assertThat( StringUtils.capitalizeFirstLetter( " dings" ) - , is( " dings" ) ); + assertThat(StringUtils.capitalizeFirstLetter(" dings"), is(" dings")); - assertThat( StringUtils.capitalizeFirstLetter( "start all big" ) - , is( "Start all big" ) ); + assertThat(StringUtils.capitalizeFirstLetter("start all big"), is("Start all big")); } - @Test( expected = NullPointerException.class ) - public void testCenter_NPE() - { - StringUtils.center( null, 20 ); + @Test(expected = NullPointerException.class) + public void testCenter_NPE() { + StringUtils.center(null, 20); } @Test - public void testCenter() - { - assertThat( StringUtils.center( "centerMe", 20 ) - , is( " centerMe " ) ); + public void testCenter() { + assertThat(StringUtils.center("centerMe", 20), is(" centerMe ")); - assertThat( StringUtils.center( "centerMe", 4 ) - , is( "centerMe" ) ); + assertThat(StringUtils.center("centerMe", 4), is("centerMe")); - assertThat( StringUtils.center( " centerMe", 20 ) - , is( " centerMe " ) ); + assertThat(StringUtils.center(" centerMe", 20), is(" centerMe ")); } - @Test( expected = NullPointerException.class ) - public void testCenter_Delim_NPE() - { - StringUtils.center( null, 20, "*" ); + @Test(expected = NullPointerException.class) + public void testCenter_Delim_NPE() { + StringUtils.center(null, 20, "*"); } @Test - public void testCenter_Delim() - { - assertThat( StringUtils.center( "centerMe", 20, "*" ) - , is( "******centerMe******" ) ); + public void testCenter_Delim() { + assertThat(StringUtils.center("centerMe", 20, "*"), is("******centerMe******")); - assertThat( StringUtils.center( "centerMe", 4, "*" ) - , is( "centerMe" ) ); + assertThat(StringUtils.center("centerMe", 4, "*"), is("centerMe")); - assertThat( StringUtils.center( " centerMe", 20, "*" ) - , is( "** centerMe**" ) ); + assertThat(StringUtils.center(" centerMe", 20, "*"), is("** centerMe**")); } - @Test( expected = NullPointerException.class ) - public void testChomp_NPE() - { - StringUtils.chomp( null ); + @Test(expected = NullPointerException.class) + public void testChomp_NPE() { + StringUtils.chomp(null); } @Test - public void testChomp() - { - assertThat( StringUtils.chomp( "dings" ) - , is( "dings" ) ); + public void testChomp() { + assertThat(StringUtils.chomp("dings"), is("dings")); - assertThat( StringUtils.chomp( "dings\n" ) - , is( "dings" ) ); + assertThat(StringUtils.chomp("dings\n"), is("dings")); - assertThat( StringUtils.chomp( "dings\nbums" ) - , is( "dings" ) ); + assertThat(StringUtils.chomp("dings\nbums"), is("dings")); - assertThat( StringUtils.chomp( "dings\nbums\ndongs" ) - , is( "dings\nbums" ) ); + assertThat(StringUtils.chomp("dings\nbums\ndongs"), is("dings\nbums")); } - @Test( expected = NullPointerException.class ) - public void testChomp_Delim_NPE() - { - StringUtils.chomp( null, "+" ); + @Test(expected = NullPointerException.class) + public void testChomp_Delim_NPE() { + StringUtils.chomp(null, "+"); } @Test - public void testChomp_Delim() - { - assertThat( StringUtils.chomp( "dings", "+" ) - , is( "dings" ) ); + public void testChomp_Delim() { + assertThat(StringUtils.chomp("dings", "+"), is("dings")); - assertThat( StringUtils.chomp( "dings+", "+" ) - , is( "dings" ) ); + assertThat(StringUtils.chomp("dings+", "+"), is("dings")); - assertThat( StringUtils.chomp( "dings+bums", "+" ) - , is( "dings" ) ); + assertThat(StringUtils.chomp("dings+bums", "+"), is("dings")); - assertThat( StringUtils.chomp( "dings+bums+dongs", "+" ) - , is( "dings+bums" ) ); + assertThat(StringUtils.chomp("dings+bums+dongs", "+"), is("dings+bums")); } - - @Test( expected = NullPointerException.class ) - public void testChompLast_NPE() - { - StringUtils.chompLast( null ); + @Test(expected = NullPointerException.class) + public void testChompLast_NPE() { + StringUtils.chompLast(null); } @Test - public void testChompLast() - { - assertThat( StringUtils.chompLast( "dings" ) - , is( "dings" ) ); + public void testChompLast() { + assertThat(StringUtils.chompLast("dings"), is("dings")); - assertThat( StringUtils.chompLast( "\n" ) - , is( "" ) ); + assertThat(StringUtils.chompLast("\n"), is("")); - assertThat( StringUtils.chompLast( "dings\n" ) - , is( "dings" ) ); + assertThat(StringUtils.chompLast("dings\n"), is("dings")); - assertThat( StringUtils.chompLast( "dings\nbums" ) - , is( "dings\nbums" ) ); + assertThat(StringUtils.chompLast("dings\nbums"), is("dings\nbums")); - assertThat( StringUtils.chompLast( "dings\nbums\ndongs\n" ) - , is( "dings\nbums\ndongs" ) ); + assertThat(StringUtils.chompLast("dings\nbums\ndongs\n"), is("dings\nbums\ndongs")); } - @Test( expected = NullPointerException.class ) - public void testChompLast_Delim_NPE() - { - StringUtils.chompLast( null, "+" ); + @Test(expected = NullPointerException.class) + public void testChompLast_Delim_NPE() { + StringUtils.chompLast(null, "+"); } @Test - public void testChompLast_Delim() - { - assertThat( StringUtils.chompLast( "dings", "+" ) - , is( "dings" ) ); + public void testChompLast_Delim() { + assertThat(StringUtils.chompLast("dings", "+"), is("dings")); - assertThat( StringUtils.chompLast( "+", "+" ) - , is( "" ) ); + assertThat(StringUtils.chompLast("+", "+"), is("")); - assertThat( StringUtils.chompLast( "dings+", "+" ) - , is( "dings" ) ); + assertThat(StringUtils.chompLast("dings+", "+"), is("dings")); - assertThat( StringUtils.chompLast( "dings+bums", "+" ) - , is( "dings+bums" ) ); + assertThat(StringUtils.chompLast("dings+bums", "+"), is("dings+bums")); - assertThat( StringUtils.chompLast( "dings+bums+dongs+", "+" ) - , is( "dings+bums+dongs" ) ); + assertThat(StringUtils.chompLast("dings+bums+dongs+", "+"), is("dings+bums+dongs")); } - @Test( expected = NullPointerException.class ) - public void testChop_NPE() - { - StringUtils.chop( null ); + @Test(expected = NullPointerException.class) + public void testChop_NPE() { + StringUtils.chop(null); } @Test - public void testChop() - { - assertThat( StringUtils.chop( "dings" ) - , is( "ding" ) ); + public void testChop() { + assertThat(StringUtils.chop("dings"), is("ding")); - assertThat( StringUtils.chop( "x" ) - , is( "" ) ); + assertThat(StringUtils.chop("x"), is("")); - assertThat( StringUtils.chop( "dings\n" ) - , is( "dings" ) ); + assertThat(StringUtils.chop("dings\n"), is("dings")); - assertThat( StringUtils.chop( "dings\r\n" ) - , is( "dings" ) ); + assertThat(StringUtils.chop("dings\r\n"), is("dings")); - assertThat( StringUtils.chop( "dings\n\r" ) - , is( "dings\n" ) ); + assertThat(StringUtils.chop("dings\n\r"), is("dings\n")); } - @Test( expected = NullPointerException.class ) - public void testChopNewline_NPE() - { - StringUtils.chopNewline( null ); + @Test(expected = NullPointerException.class) + public void testChopNewline_NPE() { + StringUtils.chopNewline(null); } @Test - public void testChopNewline() - { - assertThat( StringUtils.chopNewline( "dings" ) - , is( "dings" ) ); + public void testChopNewline() { + assertThat(StringUtils.chopNewline("dings"), is("dings")); - assertThat( StringUtils.chopNewline( "x" ) - , is( "x" ) ); + assertThat(StringUtils.chopNewline("x"), is("x")); + assertThat(StringUtils.chopNewline("dings\n"), is("dings")); - assertThat( StringUtils.chopNewline( "dings\n" ) - , is( "dings" ) ); + assertThat(StringUtils.chopNewline("dings\r\n"), is("dings")); - assertThat( StringUtils.chopNewline( "dings\r\n" ) - , is( "dings" ) ); - - assertThat( StringUtils.chopNewline( "dings\n\r" ) - , is( "dings\n\r" ) ); + assertThat(StringUtils.chopNewline("dings\n\r"), is("dings\n\r")); } - @Test - public void testClean() - { - assertThat( StringUtils.clean( null ) - , is( "" ) ); + public void testClean() { + assertThat(StringUtils.clean(null), is("")); - assertThat( StringUtils.clean( " " ) - , is( "" ) ); + assertThat(StringUtils.clean(" "), is("")); - assertThat( StringUtils.clean( " c " ) - , is( "c" ) ); + assertThat(StringUtils.clean(" c "), is("c")); - assertThat( StringUtils.clean( " dings \n " ) - , is( "dings" ) ); + assertThat(StringUtils.clean(" dings \n "), is("dings")); } - - @Test( expected = NullPointerException.class ) - public void testConcatenate_NPE() - { - StringUtils.concatenate( null ); + @Test(expected = NullPointerException.class) + public void testConcatenate_NPE() { + StringUtils.concatenate(null); } @Test - public void testConcatenate() - { - assertThat( StringUtils.concatenate( new String[0] ) - , is( "" ) ); + public void testConcatenate() { + assertThat(StringUtils.concatenate(new String[0]), is("")); - assertThat( StringUtils.concatenate( new String[]{ "x" } ) - , is( "x" ) ); + assertThat(StringUtils.concatenate(new String[] {"x"}), is("x")); - assertThat( StringUtils.concatenate( new String[]{ "x", "y", "z" } ) - , is( "xyz" ) ); + assertThat(StringUtils.concatenate(new String[] {"x", "y", "z"}), is("xyz")); } @Test - public void testContains_String() - { - assertThat( StringUtils.contains( null, null ) - , is( false ) ); + public void testContains_String() { + assertThat(StringUtils.contains(null, null), is(false)); - assertThat( StringUtils.contains( null, "string" ) - , is( false ) ); + assertThat(StringUtils.contains(null, "string"), is(false)); - assertThat( StringUtils.contains( "string", null ) - , is( false ) ); + assertThat(StringUtils.contains("string", null), is(false)); - assertThat( StringUtils.contains( "string", "" ) - , is( true ) ); + assertThat(StringUtils.contains("string", ""), is(true)); - assertThat( StringUtils.contains( "string", "in" ) - , is( true ) ); + assertThat(StringUtils.contains("string", "in"), is(true)); - assertThat( StringUtils.contains( "string", "IN" ) - , is( false ) ); + assertThat(StringUtils.contains("string", "IN"), is(false)); } @Test - public void testContains_Char() - { - assertThat( StringUtils.contains( null, 'c' ) - , is( false ) ); + public void testContains_Char() { + assertThat(StringUtils.contains(null, 'c'), is(false)); - assertThat( StringUtils.contains( "string", "c" ) - , is( false ) ); + assertThat(StringUtils.contains("string", "c"), is(false)); - assertThat( StringUtils.contains( "string", "" ) - , is( true ) ); + assertThat(StringUtils.contains("string", ""), is(true)); - assertThat( StringUtils.contains( "string", "r" ) - , is( true ) ); - - assertThat( StringUtils.contains( "string", "R" ) - , is( false ) ); + assertThat(StringUtils.contains("string", "r"), is(true)); + assertThat(StringUtils.contains("string", "R"), is(false)); } - @Test( expected = NullPointerException.class ) - public void testCountMatches_NPE() - { - StringUtils.countMatches( null, null ); + @Test(expected = NullPointerException.class) + public void testCountMatches_NPE() { + StringUtils.countMatches(null, null); } - @Test( expected = NullPointerException.class ) - public void testCountMatches_NPE2() - { - StringUtils.countMatches( "this is it", null ); + @Test(expected = NullPointerException.class) + public void testCountMatches_NPE2() { + StringUtils.countMatches("this is it", null); } @Test - public void testCountMatches() - { - assertThat( StringUtils.countMatches( null, "is" ) - , is( 0 ) ); + public void testCountMatches() { + assertThat(StringUtils.countMatches(null, "is"), is(0)); - assertThat( StringUtils.countMatches( "this is it", "is" ) - , is( 2 ) ); + assertThat(StringUtils.countMatches("this is it", "is"), is(2)); - assertThat( StringUtils.countMatches( "this is it", "notincluded" ) - , is( 0 ) ); + assertThat(StringUtils.countMatches("this is it", "notincluded"), is(0)); } @Test - public void testDefaultString() - { - assertThat( StringUtils.defaultString( null ) - , is( "" ) ); + public void testDefaultString() { + assertThat(StringUtils.defaultString(null), is("")); - assertThat( StringUtils.defaultString( "dings" ) - , is( "dings" ) ); + assertThat(StringUtils.defaultString("dings"), is("dings")); } @Test - public void testDefaultString_defaultValue() - { - assertThat( StringUtils.defaultString( null, "defaultValue" ) - , is( "defaultValue" ) ); + public void testDefaultString_defaultValue() { + assertThat(StringUtils.defaultString(null, "defaultValue"), is("defaultValue")); - assertThat( StringUtils.defaultString( "dings", "defaultValue" ) - , is( "dings" ) ); + assertThat(StringUtils.defaultString("dings", "defaultValue"), is("dings")); } - @Test( expected = NullPointerException.class ) - public void testDeleteWhitespace_NPE() - { - StringUtils.deleteWhitespace( null ); + @Test(expected = NullPointerException.class) + public void testDeleteWhitespace_NPE() { + StringUtils.deleteWhitespace(null); } @Test - public void testDeleteWhitespace() - { - assertThat( StringUtils.deleteWhitespace( " \t \n" ) - , is( "" ) ); + public void testDeleteWhitespace() { + assertThat(StringUtils.deleteWhitespace(" \t \n"), is("")); - assertThat( StringUtils.deleteWhitespace( " \t \b \n" ) - , is( "\b" ) ); + assertThat(StringUtils.deleteWhitespace(" \t \b \n"), is("\b")); - assertThat( StringUtils.deleteWhitespace( "dings" ) - , is( "dings" ) ); + assertThat(StringUtils.deleteWhitespace("dings"), is("dings")); - assertThat( StringUtils.deleteWhitespace( "\n dings \t " ) - , is( "dings" ) ); + assertThat(StringUtils.deleteWhitespace("\n dings \t "), is("dings")); } - @Test( expected = NullPointerException.class ) - public void testDifference_NPE() - { - StringUtils.difference( null, null ); + @Test(expected = NullPointerException.class) + public void testDifference_NPE() { + StringUtils.difference(null, null); } - @Test( expected = NullPointerException.class ) - public void testDifference_NPE2() - { - StringUtils.difference( null, "another" ); + @Test(expected = NullPointerException.class) + public void testDifference_NPE2() { + StringUtils.difference(null, "another"); } - @Test( expected = NullPointerException.class ) - public void testDifference_NPE3() - { - StringUtils.difference( "this", null ); + @Test(expected = NullPointerException.class) + public void testDifference_NPE3() { + StringUtils.difference("this", null); } @Test - public void testDifference() - { - assertThat( StringUtils.difference( "this", "another" ) - , is( "another" ) ); + public void testDifference() { + assertThat(StringUtils.difference("this", "another"), is("another")); - assertThat( StringUtils.difference( "I am human", "I am a robot" ) - , is( "a robot" ) ); + assertThat(StringUtils.difference("I am human", "I am a robot"), is("a robot")); - assertThat( StringUtils.difference( "I am human", "I AM a robot" ) - , is( "AM a robot" ) ); + assertThat(StringUtils.difference("I am human", "I AM a robot"), is("AM a robot")); } - @Test( expected = NullPointerException.class ) - public void testDifferenceAt_NPE() - { - StringUtils.differenceAt( null, null ); + @Test(expected = NullPointerException.class) + public void testDifferenceAt_NPE() { + StringUtils.differenceAt(null, null); } - @Test( expected = NullPointerException.class ) - public void testDifferenceAt_NPE2() - { - StringUtils.differenceAt( "test", null ); + @Test(expected = NullPointerException.class) + public void testDifferenceAt_NPE2() { + StringUtils.differenceAt("test", null); } - @Test( expected = NullPointerException.class ) - public void testDifferenceAt_NPE3() - { - StringUtils.differenceAt( null, "test" ); + @Test(expected = NullPointerException.class) + public void testDifferenceAt_NPE3() { + StringUtils.differenceAt(null, "test"); } @Test - public void testDifferenceAt() - { - assertThat( StringUtils.differenceAt( "this", "another" ) - , is( 0 ) ); + public void testDifferenceAt() { + assertThat(StringUtils.differenceAt("this", "another"), is(0)); - assertThat( StringUtils.differenceAt( "I am human", "I am a robot" ) - , is( 5 ) ); + assertThat(StringUtils.differenceAt("I am human", "I am a robot"), is(5)); - assertThat( StringUtils.differenceAt( "I am human", "I AM a robot" ) - , is( 2 ) ); + assertThat(StringUtils.differenceAt("I am human", "I AM a robot"), is(2)); } @Test - public void testEndsWithIgnoreCase() - { - assertThat( StringUtils.endsWithIgnoreCase( null, null ) - , is( false ) ); + public void testEndsWithIgnoreCase() { + assertThat(StringUtils.endsWithIgnoreCase(null, null), is(false)); - assertThat( StringUtils.endsWithIgnoreCase( null, "string" ) - , is( false ) ); + assertThat(StringUtils.endsWithIgnoreCase(null, "string"), is(false)); - assertThat( StringUtils.endsWithIgnoreCase( "string", null ) - , is( false ) ); + assertThat(StringUtils.endsWithIgnoreCase("string", null), is(false)); - assertThat( StringUtils.endsWithIgnoreCase( "string", "ing" ) - , is( true ) ); + assertThat(StringUtils.endsWithIgnoreCase("string", "ing"), is(true)); - assertThat( StringUtils.endsWithIgnoreCase( "string", "a string" ) - , is( false ) ); + assertThat(StringUtils.endsWithIgnoreCase("string", "a string"), is(false)); - assertThat( StringUtils.endsWithIgnoreCase( "string", "str" ) - , is( false ) ); + assertThat(StringUtils.endsWithIgnoreCase("string", "str"), is(false)); } @Test - public void testEquals() - { - assertThat( StringUtils.equals( null, null ) - , is( true ) ); + public void testEquals() { + assertThat(StringUtils.equals(null, null), is(true)); - assertThat( StringUtils.equals( "x", null ) - , is( false ) ); + assertThat(StringUtils.equals("x", null), is(false)); - assertThat( StringUtils.equals( null, "x" ) - , is( false ) ); + assertThat(StringUtils.equals(null, "x"), is(false)); - assertThat( StringUtils.equals( "X", "x" ) - , is( false ) ); + assertThat(StringUtils.equals("X", "x"), is(false)); - assertThat( StringUtils.equals( "dings", "dings" ) - , is( true ) ); + assertThat(StringUtils.equals("dings", "dings"), is(true)); } @Test - public void testEqualsIgnoreCase() - { - assertThat( StringUtils.equalsIgnoreCase( null, null ) - , is( true ) ); + public void testEqualsIgnoreCase() { + assertThat(StringUtils.equalsIgnoreCase(null, null), is(true)); - assertThat( StringUtils.equalsIgnoreCase( "x", null ) - , is( false ) ); + assertThat(StringUtils.equalsIgnoreCase("x", null), is(false)); - assertThat( StringUtils.equalsIgnoreCase( null, "x" ) - , is( false ) ); + assertThat(StringUtils.equalsIgnoreCase(null, "x"), is(false)); - assertThat( StringUtils.equalsIgnoreCase( "X", "x" ) - , is( true ) ); + assertThat(StringUtils.equalsIgnoreCase("X", "x"), is(true)); - assertThat( StringUtils.equalsIgnoreCase( "dings", "dings" ) - , is( true ) ); + assertThat(StringUtils.equalsIgnoreCase("dings", "dings"), is(true)); - assertThat( StringUtils.equalsIgnoreCase( "dings", "diNGs" ) - , is( true ) ); + assertThat(StringUtils.equalsIgnoreCase("dings", "diNGs"), is(true)); } - @Test( expected = NullPointerException.class ) - public void testEscape_NPE() - { - StringUtils.escape( null ); + @Test(expected = NullPointerException.class) + public void testEscape_NPE() { + StringUtils.escape(null); } @Test - public void testEscape() - { - assertThat( StringUtils.escape( "dings" ) - , is( "dings" ) ); + public void testEscape() { + assertThat(StringUtils.escape("dings"), is("dings")); - assertThat( StringUtils.escape( "dings\tbums" ) - , is( "dings\\tbums" ) ); + assertThat(StringUtils.escape("dings\tbums"), is("dings\\tbums")); - assertThat( StringUtils.escape( "dings\nbums" ) - , is( "dings\\nbums" ) ); + assertThat(StringUtils.escape("dings\nbums"), is("dings\\nbums")); } - @Test - public void testEscape2() - { - assertThat( StringUtils.escape( null, null, '#' ) - , nullValue() ); + public void testEscape2() { + assertThat(StringUtils.escape(null, null, '#'), nullValue()); - assertThat( StringUtils.escape( "dings", new char[]{ '\t', '\b' }, '+' ) - , is( "dings" ) ); + assertThat(StringUtils.escape("dings", new char[] {'\t', '\b'}, '+'), is("dings")); - assertThat( StringUtils.escape( "dings\tbums", new char[]{ '\t', '\b' }, '+' ) - , is( "dings+\tbums" ) ); + assertThat(StringUtils.escape("dings\tbums", new char[] {'\t', '\b'}, '+'), is("dings+\tbums")); - assertThat( StringUtils.escape( "dings\nbums", new char[]{ '\t', '\b' }, '+' ) - , is( "dings\nbums" ) ); - assertThat( StringUtils.escape( "dings\bbums", new char[]{ '\t', '\b' }, '+' ) - , is( "dings+\bbums" ) ); + assertThat(StringUtils.escape("dings\nbums", new char[] {'\t', '\b'}, '+'), is("dings\nbums")); + assertThat(StringUtils.escape("dings\bbums", new char[] {'\t', '\b'}, '+'), is("dings+\bbums")); } - @Test( expected = NullPointerException.class ) - public void testGetChomp_NPE1() - { - StringUtils.getChomp( null, null ); + @Test(expected = NullPointerException.class) + public void testGetChomp_NPE1() { + StringUtils.getChomp(null, null); } - @Test( expected = NullPointerException.class ) - public void testGetChomp_NPE2() - { - StringUtils.getChomp( "dings", null ); + @Test(expected = NullPointerException.class) + public void testGetChomp_NPE2() { + StringUtils.getChomp("dings", null); } - @Test( expected = NullPointerException.class ) - public void testGetChomp_NPE3() - { - StringUtils.getChomp( null, "dings" ); + @Test(expected = NullPointerException.class) + public void testGetChomp_NPE3() { + StringUtils.getChomp(null, "dings"); } @Test - public void testGetChomp() - { - assertThat( StringUtils.getChomp( "dings-bums", "-" ) - , is( "-bums" ) ); + public void testGetChomp() { + assertThat(StringUtils.getChomp("dings-bums", "-"), is("-bums")); - assertThat( StringUtils.getChomp( "dings-", "-" ) - , is( "-" ) ); + assertThat(StringUtils.getChomp("dings-", "-"), is("-")); - assertThat( StringUtils.getChomp( "dingsbums", "-" ) - , is( "" ) ); + assertThat(StringUtils.getChomp("dingsbums", "-"), is("")); } - @Test( expected = NullPointerException.class ) - public void testGetNestedString_NPE() - { - assertThat( StringUtils.getNestedString( " +dings+ ", null ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testGetNestedString_NPE() { + assertThat(StringUtils.getNestedString(" +dings+ ", null), nullValue()); } @Test - public void testGetNestedString() - { - assertThat( StringUtils.getNestedString( null, null ) - , nullValue() ); + public void testGetNestedString() { + assertThat(StringUtils.getNestedString(null, null), nullValue()); - assertThat( StringUtils.getNestedString( " +dings+ ", "+" ) - , is( "dings" ) ); + assertThat(StringUtils.getNestedString(" +dings+ ", "+"), is("dings")); - assertThat( StringUtils.getNestedString( " +dings+ ", "not" ) - , nullValue() ); + assertThat(StringUtils.getNestedString(" +dings+ ", "not"), nullValue()); } - @Test( expected = NullPointerException.class ) - public void testGetNestedString2_NPE1() - { - assertThat( StringUtils.getNestedString( " +dings+ ", null, null ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testGetNestedString2_NPE1() { + assertThat(StringUtils.getNestedString(" +dings+ ", null, null), nullValue()); } - @Test( expected = NullPointerException.class ) - public void testGetNestedString2_NPE2() - { - assertThat( StringUtils.getNestedString( " +dings+ ", null, "neither" ) - , nullValue() ); + @Test(expected = NullPointerException.class) + public void testGetNestedString2_NPE2() { + assertThat(StringUtils.getNestedString(" +dings+ ", null, "neither"), nullValue()); } @Test - public void testGetNestedString2() - { - assertThat( StringUtils.getNestedString( null, null, null ) - , nullValue() ); + public void testGetNestedString2() { + assertThat(StringUtils.getNestedString(null, null, null), nullValue()); - assertThat( StringUtils.getNestedString( " +dings+ ", "not", null ) - , nullValue() ); + assertThat(StringUtils.getNestedString(" +dings+ ", "not", null), nullValue()); - assertThat( StringUtils.getNestedString( " +dings- ", "+", "-" ) - , is( "dings" ) ); + assertThat(StringUtils.getNestedString(" +dings- ", "+", "-"), is("dings")); - assertThat( StringUtils.getNestedString( " +dings+ ", "not", "neither" ) - , nullValue() ); + assertThat(StringUtils.getNestedString(" +dings+ ", "not", "neither"), nullValue()); } - @Test( expected = NullPointerException.class ) - public void testGetPrechomp_NPE1() - { - StringUtils.getPrechomp( null, null ); + @Test(expected = NullPointerException.class) + public void testGetPrechomp_NPE1() { + StringUtils.getPrechomp(null, null); } - @Test( expected = NullPointerException.class ) - public void testGetPrechomp_NPE2() - { - StringUtils.getPrechomp( null, "bums" ); + @Test(expected = NullPointerException.class) + public void testGetPrechomp_NPE2() { + StringUtils.getPrechomp(null, "bums"); } @Test - public void testGetPrechomp() - { - assertThat( StringUtils.getPrechomp( "dings bums dongs", "bums" ) - , is( "dings bums" ) ); + public void testGetPrechomp() { + assertThat(StringUtils.getPrechomp("dings bums dongs", "bums"), is("dings bums")); - assertThat( StringUtils.getPrechomp( "dings bums dongs", "non" ) - , is( "" ) ); + assertThat(StringUtils.getPrechomp("dings bums dongs", "non"), is("")); } @Test - public void testIndexOfAny() - { - assertThat( StringUtils.indexOfAny( null, null ) - , is( -1 ) ); + public void testIndexOfAny() { + assertThat(StringUtils.indexOfAny(null, null), is(-1)); - assertThat( StringUtils.indexOfAny( "dings", null ) - , is( -1 ) ); + assertThat(StringUtils.indexOfAny("dings", null), is(-1)); - assertThat( StringUtils.indexOfAny( null, new String[]{} ) - , is( -1 ) ); + assertThat(StringUtils.indexOfAny(null, new String[] {}), is(-1)); - assertThat( StringUtils.indexOfAny( "dings bums dongs", new String[]{ "knuff", "bums" } ) - , is( 6 ) ); + assertThat(StringUtils.indexOfAny("dings bums dongs", new String[] {"knuff", "bums"}), is(6)); } - @Test( expected = NullPointerException.class ) - public void testInterpolate_NPE() - { - StringUtils.interpolate( null, null ); + @Test(expected = NullPointerException.class) + public void testInterpolate_NPE() { + StringUtils.interpolate(null, null); } - @Test( expected = NullPointerException.class ) - public void testInterpolate_NPE2() - { - StringUtils.interpolate( "This ${text} will get replaced", null ); + @Test(expected = NullPointerException.class) + public void testInterpolate_NPE2() { + StringUtils.interpolate("This ${text} will get replaced", null); } @Test - public void testInterpolate() - { + public void testInterpolate() { Map variables = new HashMap(); - assertThat( StringUtils.interpolate( "This ${text} will get replaced", variables ) - , is( "This ${text} will get replaced" ) ); + assertThat( + StringUtils.interpolate("This ${text} will get replaced", variables), + is("This ${text} will get replaced")); - variables.put( "text", "with a special content" ); + variables.put("text", "with a special content"); - assertThat( StringUtils.interpolate( "This ${text} will get replaced", variables ) - , is( "This with a special content will get replaced" ) ); + assertThat( + StringUtils.interpolate("This ${text} will get replaced", variables), + is("This with a special content will get replaced")); } @Test - public void testIsAlpha() - { - assertThat( StringUtils.isAlpha( null ) - , is( false ) ); + public void testIsAlpha() { + assertThat(StringUtils.isAlpha(null), is(false)); - assertThat( StringUtils.isAlpha( "2" ) - , is( false ) ); + assertThat(StringUtils.isAlpha("2"), is(false)); - assertThat( StringUtils.isAlpha( "asvsdfSDF" ) - , is( true ) ); + assertThat(StringUtils.isAlpha("asvsdfSDF"), is(true)); - assertThat( StringUtils.isAlpha( "asvsdfSDF \t " ) - , is( false ) ); + assertThat(StringUtils.isAlpha("asvsdfSDF \t "), is(false)); - assertThat( StringUtils.isAlpha( "435afsafd3!" ) - , is( false ) ); + assertThat(StringUtils.isAlpha("435afsafd3!"), is(false)); } @Test - public void testIsAlphaSpace() - { - assertThat( StringUtils.isAlphaSpace( null ) - , is( false ) ); + public void testIsAlphaSpace() { + assertThat(StringUtils.isAlphaSpace(null), is(false)); - assertThat( StringUtils.isAlphaSpace( "2" ) - , is( false ) ); + assertThat(StringUtils.isAlphaSpace("2"), is(false)); - assertThat( StringUtils.isAlphaSpace( "asvsdfSDF" ) - , is( true ) ); + assertThat(StringUtils.isAlphaSpace("asvsdfSDF"), is(true)); - assertThat( StringUtils.isAlphaSpace( "asvsdfSDF " ) - , is( true ) ); + assertThat(StringUtils.isAlphaSpace("asvsdfSDF "), is(true)); - assertThat( StringUtils.isAlphaSpace( "asvsdfSDF \t " ) - , is( false ) ); + assertThat(StringUtils.isAlphaSpace("asvsdfSDF \t "), is(false)); - assertThat( StringUtils.isAlphaSpace( "435afsafd3!" ) - , is( false ) ); + assertThat(StringUtils.isAlphaSpace("435afsafd3!"), is(false)); } @Test - public void testIsAlphanumeric() - { - assertThat( StringUtils.isAlphanumeric( null ) - , is( false ) ); + public void testIsAlphanumeric() { + assertThat(StringUtils.isAlphanumeric(null), is(false)); - assertThat( StringUtils.isAlphanumeric( "2" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumeric("2"), is(true)); - assertThat( StringUtils.isAlphanumeric( "asvsdfSDF" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumeric("asvsdfSDF"), is(true)); - assertThat( StringUtils.isAlphanumeric( "asvsdfSDF " ) - , is( false ) ); + assertThat(StringUtils.isAlphanumeric("asvsdfSDF "), is(false)); - assertThat( StringUtils.isAlphanumeric( "asvsdfSDF \t " ) - , is( false ) ); + assertThat(StringUtils.isAlphanumeric("asvsdfSDF \t "), is(false)); - assertThat( StringUtils.isAlphanumeric( "435afsafd3!" ) - , is( false ) ); + assertThat(StringUtils.isAlphanumeric("435afsafd3!"), is(false)); - assertThat( StringUtils.isAlphanumeric( "435afsafd3" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumeric("435afsafd3"), is(true)); - assertThat( StringUtils.isAlphanumeric( "435 " ) - , is( false ) ); + assertThat(StringUtils.isAlphanumeric("435 "), is(false)); - assertThat( StringUtils.isAlphanumeric( "435" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumeric("435"), is(true)); } @Test - public void testIsAlphanumericSpace() - { - assertThat( StringUtils.isAlphanumericSpace( null ) - , is( false ) ); + public void testIsAlphanumericSpace() { + assertThat(StringUtils.isAlphanumericSpace(null), is(false)); - assertThat( StringUtils.isAlphanumericSpace( "2" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("2"), is(true)); - assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF"), is(true)); - assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF " ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF "), is(true)); - assertThat( StringUtils.isAlphanumericSpace( "asvsdfSDF \t " ) - , is( false ) ); + assertThat(StringUtils.isAlphanumericSpace("asvsdfSDF \t "), is(false)); - assertThat( StringUtils.isAlphanumericSpace( "435afsafd3!" ) - , is( false ) ); + assertThat(StringUtils.isAlphanumericSpace("435afsafd3!"), is(false)); - assertThat( StringUtils.isAlphanumericSpace( "435afsafd3" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("435afsafd3"), is(true)); - assertThat( StringUtils.isAlphanumericSpace( "435 " ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("435 "), is(true)); - assertThat( StringUtils.isAlphanumericSpace( "435" ) - , is( true ) ); + assertThat(StringUtils.isAlphanumericSpace("435"), is(true)); } @Test - public void testIsBlank() - { - assertThat( StringUtils.isBlank( null ) - , is( true ) ); + public void testIsBlank() { + assertThat(StringUtils.isBlank(null), is(true)); - assertThat( StringUtils.isBlank( "xx" ) - , is( false ) ); + assertThat(StringUtils.isBlank("xx"), is(false)); - assertThat( StringUtils.isBlank( "xx " ) - , is( false ) ); + assertThat(StringUtils.isBlank("xx "), is(false)); - assertThat( StringUtils.isBlank( " " ) - , is( true ) ); + assertThat(StringUtils.isBlank(" "), is(true)); - assertThat( StringUtils.isBlank( " \t " ) - , is( true ) ); + assertThat(StringUtils.isBlank(" \t "), is(true)); - assertThat( StringUtils.isBlank( " \n " ) - , is( true ) ); + assertThat(StringUtils.isBlank(" \n "), is(true)); } - @Test - public void testEmpty() - { - assertThat( StringUtils.isEmpty( null ) - , is( true ) ); + public void testEmpty() { + assertThat(StringUtils.isEmpty(null), is(true)); - assertThat( StringUtils.isEmpty( "xx" ) - , is( false ) ); + assertThat(StringUtils.isEmpty("xx"), is(false)); - assertThat( StringUtils.isEmpty( "xx " ) - , is( false ) ); + assertThat(StringUtils.isEmpty("xx "), is(false)); - assertThat( StringUtils.isEmpty( " " ) - , is( true ) ); + assertThat(StringUtils.isEmpty(" "), is(true)); - assertThat( StringUtils.isEmpty( " \t " ) - , is( true ) ); + assertThat(StringUtils.isEmpty(" \t "), is(true)); - assertThat( StringUtils.isEmpty( " \n " ) - , is( true ) ); + assertThat(StringUtils.isEmpty(" \n "), is(true)); } @Test - public void testNotBlank() - { - assertThat( StringUtils.isNotBlank( null ) - , is( false ) ); + public void testNotBlank() { + assertThat(StringUtils.isNotBlank(null), is(false)); - assertThat( StringUtils.isNotBlank( "xx" ) - , is( true ) ); + assertThat(StringUtils.isNotBlank("xx"), is(true)); - assertThat( StringUtils.isNotBlank( "xx " ) - , is( true ) ); + assertThat(StringUtils.isNotBlank("xx "), is(true)); - assertThat( StringUtils.isNotBlank( " " ) - , is( false ) ); + assertThat(StringUtils.isNotBlank(" "), is(false)); - assertThat( StringUtils.isNotBlank( " \t " ) - , is( false ) ); + assertThat(StringUtils.isNotBlank(" \t "), is(false)); - assertThat( StringUtils.isNotBlank( " \n " ) - , is( false ) ); + assertThat(StringUtils.isNotBlank(" \n "), is(false)); } @Test - public void testNotEmpty() - { - assertThat( StringUtils.isNotEmpty( null ) - , is( false ) ); + public void testNotEmpty() { + assertThat(StringUtils.isNotEmpty(null), is(false)); - assertThat( StringUtils.isNotEmpty( "xx" ) - , is( true ) ); + assertThat(StringUtils.isNotEmpty("xx"), is(true)); - assertThat( StringUtils.isNotEmpty( "xx " ) - , is( true ) ); + assertThat(StringUtils.isNotEmpty("xx "), is(true)); - assertThat( StringUtils.isNotEmpty( " " ) - , is( true ) ); + assertThat(StringUtils.isNotEmpty(" "), is(true)); - assertThat( StringUtils.isNotEmpty( "" ) - , is( false ) ); + assertThat(StringUtils.isNotEmpty(""), is(false)); - assertThat( StringUtils.isNotEmpty( " \t " ) - , is( true ) ); + assertThat(StringUtils.isNotEmpty(" \t "), is(true)); - assertThat( StringUtils.isNotEmpty( " \n " ) - , is( true ) ); + assertThat(StringUtils.isNotEmpty(" \n "), is(true)); } @Test - public void testIsNumeric() - { - assertThat( StringUtils.isNumeric( null ) - , is( false ) ); + public void testIsNumeric() { + assertThat(StringUtils.isNumeric(null), is(false)); - assertThat( StringUtils.isNumeric( "2" ) - , is( true ) ); + assertThat(StringUtils.isNumeric("2"), is(true)); - assertThat( StringUtils.isNumeric( "asvsdfSDF" ) - , is( false ) ); + assertThat(StringUtils.isNumeric("asvsdfSDF"), is(false)); - assertThat( StringUtils.isNumeric( "asvsdfSDF " ) - , is( false ) ); + assertThat(StringUtils.isNumeric("asvsdfSDF "), is(false)); - assertThat( StringUtils.isNumeric( "asvsdfSDF \t " ) - , is( false ) ); + assertThat(StringUtils.isNumeric("asvsdfSDF \t "), is(false)); - assertThat( StringUtils.isNumeric( "435afsafd3!" ) - , is( false ) ); + assertThat(StringUtils.isNumeric("435afsafd3!"), is(false)); - assertThat( StringUtils.isNumeric( "435afsafd3" ) - , is( false ) ); + assertThat(StringUtils.isNumeric("435afsafd3"), is(false)); - assertThat( StringUtils.isNumeric( "435 " ) - , is( false ) ); + assertThat(StringUtils.isNumeric("435 "), is(false)); - assertThat( StringUtils.isNumeric( "435" ) - , is( true ) ); + assertThat(StringUtils.isNumeric("435"), is(true)); } @Test - public void testIsWhitespace() - { - assertThat( StringUtils.isWhitespace( null ) - , is( false ) ); + public void testIsWhitespace() { + assertThat(StringUtils.isWhitespace(null), is(false)); - assertThat( StringUtils.isWhitespace( "xx" ) - , is( false ) ); + assertThat(StringUtils.isWhitespace("xx"), is(false)); - assertThat( StringUtils.isWhitespace( "xx " ) - , is( false ) ); + assertThat(StringUtils.isWhitespace("xx "), is(false)); - assertThat( StringUtils.isWhitespace( " " ) - , is( true ) ); + assertThat(StringUtils.isWhitespace(" "), is(true)); - assertThat( StringUtils.isWhitespace( "" ) - , is( true ) ); + assertThat(StringUtils.isWhitespace(""), is(true)); - assertThat( StringUtils.isWhitespace( " \t " ) - , is( true ) ); + assertThat(StringUtils.isWhitespace(" \t "), is(true)); - assertThat( StringUtils.isWhitespace( " \n " ) - , is( true ) ); + assertThat(StringUtils.isWhitespace(" \n "), is(true)); } - @Test( expected = NullPointerException.class ) - public void testJoin_Array_NPE() - { - StringUtils.join( ( Object[] ) null, null ); + @Test(expected = NullPointerException.class) + public void testJoin_Array_NPE() { + StringUtils.join((Object[]) null, null); } @Test - public void testJoin_Array() - { - assertThat( StringUtils.join( new Object[0], null ) - , is( "" ) ); + public void testJoin_Array() { + assertThat(StringUtils.join(new Object[0], null), is("")); - assertThat( StringUtils.join( new Object[]{ "a", "b", "c" }, null ) - , is( "abc" ) ); + assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, null), is("abc")); - assertThat( StringUtils.join( new Object[]{ "a", "b", "c" }, "__" ) - , is( "a__b__c" ) ); + assertThat(StringUtils.join(new Object[] {"a", "b", "c"}, "__"), is("a__b__c")); } - @Test( expected = NullPointerException.class ) - public void testJoin_Iterator_NPE() - { - StringUtils.join( (Iterator) null, null ); + @Test(expected = NullPointerException.class) + public void testJoin_Iterator_NPE() { + StringUtils.join((Iterator) null, null); } @Test - public void testJoin_Iterator() - { + public void testJoin_Iterator() { ArrayList list = new ArrayList(); - assertThat( StringUtils.join( list.iterator(), null ) - , is( "" ) ); + assertThat(StringUtils.join(list.iterator(), null), is("")); - list.add( "a" ); - list.add( "b" ); - list.add( "c" ); + list.add("a"); + list.add("b"); + list.add("c"); - assertThat( StringUtils.join( list.iterator(), null ) - , is( "abc" ) ); + assertThat(StringUtils.join(list.iterator(), null), is("abc")); - assertThat( StringUtils.join( list.iterator(), "__" ) - , is( "a__b__c" ) ); + assertThat(StringUtils.join(list.iterator(), "__"), is("a__b__c")); } @Test - public void testLastIndexOfAny() - { - assertThat( StringUtils.lastIndexOfAny( null, null ) - , is( -1 ) ); + public void testLastIndexOfAny() { + assertThat(StringUtils.lastIndexOfAny(null, null), is(-1)); - assertThat( StringUtils.lastIndexOfAny( "dings", null ) - , is( -1 ) ); + assertThat(StringUtils.lastIndexOfAny("dings", null), is(-1)); - assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] { "ms", " b" } ) - , is( 13 ) ); + assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"ms", " b"}), is(13)); - assertThat( StringUtils.lastIndexOfAny( "dings bums boms", new String[] { "nix", "da" } ) - , is( -1 ) ); + assertThat(StringUtils.lastIndexOfAny("dings bums boms", new String[] {"nix", "da"}), is(-1)); } - @Test( expected = IllegalArgumentException.class ) - public void testLeft_IAE() - { - StringUtils.left( null, -1 ); + @Test(expected = IllegalArgumentException.class) + public void testLeft_IAE() { + StringUtils.left(null, -1); } @Test - public void testLeft() - { - assertThat( StringUtils.left( null, 4 ) - , nullValue() ); + public void testLeft() { + assertThat(StringUtils.left(null, 4), nullValue()); - assertThat( StringUtils.left( "dingsbums", 4 ) - , is( "ding" ) ); + assertThat(StringUtils.left("dingsbums", 4), is("ding")); - assertThat( StringUtils.left( "dingsbums", 40 ) - , is( "dingsbums" ) ); + assertThat(StringUtils.left("dingsbums", 40), is("dingsbums")); - assertThat( StringUtils.left( "dingsbums", 0 ) - , is( "" ) ); + assertThat(StringUtils.left("dingsbums", 0), is("")); } - @Test( expected = NullPointerException.class ) - public void testLeftPad1_NPE() - { - StringUtils.leftPad( null, 0 ); + @Test(expected = NullPointerException.class) + public void testLeftPad1_NPE() { + StringUtils.leftPad(null, 0); } @Test - public void testLeftPad1() - { - assertThat( StringUtils.leftPad( "dings", 0 ) - , is( "dings") ); + public void testLeftPad1() { + assertThat(StringUtils.leftPad("dings", 0), is("dings")); - assertThat( StringUtils.leftPad( "dings", 2 ) - , is( "dings") ); + assertThat(StringUtils.leftPad("dings", 2), is("dings")); - assertThat( StringUtils.leftPad( "dings", 10 ) - , is( " dings") ); + assertThat(StringUtils.leftPad("dings", 10), is(" dings")); } - @Test( expected = NullPointerException.class ) - public void testLeftPad2_NPE1() - { - StringUtils.leftPad( null, 0, null ); + @Test(expected = NullPointerException.class) + public void testLeftPad2_NPE1() { + StringUtils.leftPad(null, 0, null); } - @Test( expected = NullPointerException.class ) - public void testLeftPad2_NPE2() - { - StringUtils.leftPad( "dings", 0, null ); + @Test(expected = NullPointerException.class) + public void testLeftPad2_NPE2() { + StringUtils.leftPad("dings", 0, null); } - @Test( expected = NullPointerException.class ) - public void testLeftPad2_NPE3() - { - StringUtils.leftPad( null, 0, "*" ); + @Test(expected = NullPointerException.class) + public void testLeftPad2_NPE3() { + StringUtils.leftPad(null, 0, "*"); } @Test - public void testLeftPad2() - { - assertThat( StringUtils.leftPad( "dings", 0, "*" ) - , is( "dings") ); + public void testLeftPad2() { + assertThat(StringUtils.leftPad("dings", 0, "*"), is("dings")); - assertThat( StringUtils.leftPad( "dings", 2, "*" ) - , is( "dings") ); + assertThat(StringUtils.leftPad("dings", 2, "*"), is("dings")); - assertThat( StringUtils.leftPad( "dings", 10, "*" ) - , is( "*****dings") ); + assertThat(StringUtils.leftPad("dings", 10, "*"), is("*****dings")); } @Test - public void testLowerCase() - { - assertThat( StringUtils.lowerCase( null ) - , nullValue() ); + public void testLowerCase() { + assertThat(StringUtils.lowerCase(null), nullValue()); - assertThat( StringUtils.lowerCase( "dinGSbuMS" ) - , is( "dingsbums" ) ); - - assertThat( StringUtils.lowerCase( "" ) - , is( "" ) ); + assertThat(StringUtils.lowerCase("dinGSbuMS"), is("dingsbums")); + assertThat(StringUtils.lowerCase(""), is("")); } - @Test( expected = NullPointerException.class ) - public void testLowerCaseFirstLetter_NPE() - { - StringUtils.lowercaseFirstLetter( null ); + @Test(expected = NullPointerException.class) + public void testLowerCaseFirstLetter_NPE() { + StringUtils.lowercaseFirstLetter(null); } @Test - public void testLowerCaseFirstLetter() - { - assertThat( StringUtils.lowercaseFirstLetter( "Dings Bums" ) - , is( "dings Bums" ) ); + public void testLowerCaseFirstLetter() { + assertThat(StringUtils.lowercaseFirstLetter("Dings Bums"), is("dings Bums")); } - @Test( expected = IllegalArgumentException.class ) - public void testMid_NegativeLen() - { - StringUtils.mid( null, 0, -2 ); + @Test(expected = IllegalArgumentException.class) + public void testMid_NegativeLen() { + StringUtils.mid(null, 0, -2); } - @Test( expected = IndexOutOfBoundsException.class ) - public void testMid_WrongPos() - { - StringUtils.mid( null, -2, 3 ); + @Test(expected = IndexOutOfBoundsException.class) + public void testMid_WrongPos() { + StringUtils.mid(null, -2, 3); } @Test - public void testMid() - { - assertThat( StringUtils.mid( null, 0, 0 ) - , nullValue() ); + public void testMid() { + assertThat(StringUtils.mid(null, 0, 0), nullValue()); - assertThat( StringUtils.mid( "dings bums", 0, 0 ) - , is( "" ) ); + assertThat(StringUtils.mid("dings bums", 0, 0), is("")); - assertThat( StringUtils.mid( "dings bums", 3, 4 ) - , is( "gs b" ) ); + assertThat(StringUtils.mid("dings bums", 3, 4), is("gs b")); } - @Test( expected = NullPointerException.class ) - public void testOverlayString_NPE1() - { - StringUtils.overlayString( null, null, 0, 0 ); + @Test(expected = NullPointerException.class) + public void testOverlayString_NPE1() { + StringUtils.overlayString(null, null, 0, 0); } - @Test( expected = NullPointerException.class ) - public void testOverlayString_NPE2() - { - StringUtils.overlayString( "dings", null, 0, 0 ); + @Test(expected = NullPointerException.class) + public void testOverlayString_NPE2() { + StringUtils.overlayString("dings", null, 0, 0); } - @Test( expected = NullPointerException.class ) - public void testOverlayString_NPE3() - { - StringUtils.overlayString( null, "bums", 0, 0 ); + @Test(expected = NullPointerException.class) + public void testOverlayString_NPE3() { + StringUtils.overlayString(null, "bums", 0, 0); } @Test - public void testOverlayString() - { - assertThat( StringUtils.overlayString( "dings", "bums", 0, 0 ) - , is( "bumsdings" ) ); + public void testOverlayString() { + assertThat(StringUtils.overlayString("dings", "bums", 0, 0), is("bumsdings")); - assertThat( StringUtils.overlayString( "dings", "bums", 2, 4 ) - , is( "dibumss" ) ); + assertThat(StringUtils.overlayString("dings", "bums", 2, 4), is("dibumss")); } - @Test( expected = NullPointerException.class ) - public void testPrechomp_NPE1() - { - StringUtils.prechomp( null, null ); + @Test(expected = NullPointerException.class) + public void testPrechomp_NPE1() { + StringUtils.prechomp(null, null); } - @Test( expected = NullPointerException.class ) - public void testPrechomp_NPE2() - { - StringUtils.prechomp( "dings", null ); + @Test(expected = NullPointerException.class) + public void testPrechomp_NPE2() { + StringUtils.prechomp("dings", null); } - @Test( expected = NullPointerException.class ) - public void testPrechomp_NPE3() - { - StringUtils.prechomp( null, "bums" ); + @Test(expected = NullPointerException.class) + public void testPrechomp_NPE3() { + StringUtils.prechomp(null, "bums"); } @Test - public void testPrechomp() - { - assertThat( StringUtils.prechomp( "dings bums", " " ) - , is( "bums" ) ); + public void testPrechomp() { + assertThat(StringUtils.prechomp("dings bums", " "), is("bums")); - assertThat( StringUtils.prechomp( "dings bums", "nix" ) - , is( "dings bums" ) ); + assertThat(StringUtils.prechomp("dings bums", "nix"), is("dings bums")); } @Test - public void testQuoteAndEscape1() - { - assertThat( StringUtils.quoteAndEscape( null, '+' ) - , nullValue() ); + public void testQuoteAndEscape1() { + assertThat(StringUtils.quoteAndEscape(null, '+'), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+' ) - , is( "" ) ); + assertThat(StringUtils.quoteAndEscape("", '+'), is("")); - assertThat( StringUtils.quoteAndEscape( "abc", '"' ) - , is( "abc" ) ); + assertThat(StringUtils.quoteAndEscape("abc", '"'), is("abc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"' ) - , is( "\"a\\\"bc\"" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '"'), is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'' ) - , is( "\'a\\'bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\'bc", '\''), is("\'a\\'bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'' ) - , is( "a\"bc" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\''), is("a\"bc")); } @Test - public void testQuoteAndEscape2() - { - assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' } ) - , nullValue() ); + public void testQuoteAndEscape2() { + assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' } ) - , is( "" ) ); + assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}), is("")); - assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' } ) - , is( "abc" ) ); + assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}), is("abc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' } ) - , is( "\"a\\\"bc\"" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}), is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' } ) - , is( "\'a\\'bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}), is("\'a\\'bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' } ) - , is( "a\"bc" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}), is("a\"bc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' } ) - , is( "\'a\"bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}), is("\'a\"bc\'")); } @Test - public void testQuoteAndEscape3() - { - assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, '\\', false ) - , nullValue() ); + public void testQuoteAndEscape3() { + assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', false), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, '\\', false ) - , is( "" ) ); + assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', false), is("")); - assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, '\\', false ) - , is( "abc" ) ); + assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', false), is("abc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, '\\', false ) - , is( "\"a\\\"bc\"" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', false), is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, '\\', false ) - , is( "a\'bc" ) ); + assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', false), is("a\'bc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, '\\', false ) - , is( "a\"bc" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', false), is("a\"bc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, '\\', false ) - , is( "\'a\\\"bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', false), is("\'a\\\"bc\'")); // with force flag - assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, '\\', true ) - , nullValue() ); + assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, '\\', true), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, '\\', true ) - , is( "++" ) ); + assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, '\\', true), is("++")); - assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, '\\', true ) - , is( "\"abc\"" ) ); + assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, '\\', true), is("\"abc\"")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, '\\', true ) - , is( "\"a\\\"bc\"" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, '\\', true), is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, '\\', true ) - , is( "\'a\'bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, '\\', true), is("\'a\'bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, '\\', true ) - , is( "\'a\"bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, '\\', true), is("\'a\"bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, '\\', true ) - , is( "\'a\\\"bc\'" ) ); + assertThat(StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, '\\', true), is("\'a\\\"bc\'")); } @Test - public void testQuoteAndEscape4() - { - assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, new char[]{ '"' }, '\\', false ) - , nullValue() ); + public void testQuoteAndEscape4() { + assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', false), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, new char[]{ '"' }, '\\', false ) - , is( "" ) ); + assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', false), is("")); - assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', false ) - , is( "abc" ) ); + assertThat(StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false), is("abc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', false ) - , is( "\"a\\\"bc\"" ) ); + assertThat( + StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', false), + is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, new char[]{ '"' }, '\\', false ) - , is( "a\'bc" ) ); + assertThat( + StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', false), + is("a\'bc")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, new char[]{ '"' }, '\\', false ) - , is( "\'a\"bc\'" ) ); + assertThat( + StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', false), + is("\'a\"bc\'")); - assertThat( StringUtils.quoteAndEscape( "\'a\"bc\'", '\'', new char[]{ '\'', '"' }, new char[]{ '"' }, '\\', false ) - , is( "\'a\"bc\'" ) ); + assertThat( + StringUtils.quoteAndEscape("\'a\"bc\'", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', false), + is("\'a\"bc\'")); // with force flag - assertThat( StringUtils.quoteAndEscape( null, '+', new char[]{ '"' }, new char[]{ '"' }, '\\', true ) - , nullValue() ); + assertThat(StringUtils.quoteAndEscape(null, '+', new char[] {'"'}, new char[] {'"'}, '\\', true), nullValue()); - assertThat( StringUtils.quoteAndEscape( "", '+', new char[]{ '"' }, new char[]{ '"' }, '\\', true ) - , is( "++" ) ); + assertThat(StringUtils.quoteAndEscape("", '+', new char[] {'"'}, new char[] {'"'}, '\\', true), is("++")); - assertThat( StringUtils.quoteAndEscape( "abc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', true ) - , is( "\"abc\"" ) ); + assertThat( + StringUtils.quoteAndEscape("abc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true), is("\"abc\"")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '"', new char[]{ '"' }, new char[]{ '"' }, '\\', true ) - , is( "\"a\\\"bc\"" ) ); + assertThat( + StringUtils.quoteAndEscape("a\"bc", '"', new char[] {'"'}, new char[] {'"'}, '\\', true), + is("\"a\\\"bc\"")); - assertThat( StringUtils.quoteAndEscape( "a\'bc", '\'', new char[]{ '"' }, new char[]{ '"' }, '\\', true ) - , is( "\'a\'bc\'" ) ); + assertThat( + StringUtils.quoteAndEscape("a\'bc", '\'', new char[] {'"'}, new char[] {'"'}, '\\', true), + is("\'a\'bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'' }, new char[]{ '"' }, '\\', true ) - , is( "\'a\"bc\'" ) ); + assertThat( + StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\''}, new char[] {'"'}, '\\', true), + is("\'a\"bc\'")); - assertThat( StringUtils.quoteAndEscape( "a\"bc", '\'', new char[]{ '\'', '"' }, new char[]{ '"' }, '\\', true ) - , is( "\'a\\\"bc\'" ) ); + assertThat( + StringUtils.quoteAndEscape("a\"bc", '\'', new char[] {'\'', '"'}, new char[] {'"'}, '\\', true), + is("\'a\\\"bc\'")); } - @Test( expected = NullPointerException.class ) - public void testRemoveAndHump_NPE1() - { - StringUtils.removeAndHump( null, null ); + @Test(expected = NullPointerException.class) + public void testRemoveAndHump_NPE1() { + StringUtils.removeAndHump(null, null); } - @Test( expected = NullPointerException.class ) - public void testRemoveAndHump_NPE2() - { - StringUtils.removeAndHump( "dings", null ); + @Test(expected = NullPointerException.class) + public void testRemoveAndHump_NPE2() { + StringUtils.removeAndHump("dings", null); } - @Test( expected = NullPointerException.class ) - public void testRemoveAndHump_NPE3() - { - StringUtils.removeAndHump( null, "bums" ); + @Test(expected = NullPointerException.class) + public void testRemoveAndHump_NPE3() { + StringUtils.removeAndHump(null, "bums"); } @Test - public void testRemoveAndHump() - { - assertThat( StringUtils.removeAndHump( "dings", "bums" ) - , is( "Ding" ) ); - - assertThat( StringUtils.removeAndHump( "this-is-it", "-" ) - , is( "ThisIsIt" ) ); + public void testRemoveAndHump() { + assertThat(StringUtils.removeAndHump("dings", "bums"), is("Ding")); - assertThat( StringUtils.removeAndHump( "THIS-IS-IT", "-" ) - , is( "THISISIT" ) ); + assertThat(StringUtils.removeAndHump("this-is-it", "-"), is("ThisIsIt")); + assertThat(StringUtils.removeAndHump("THIS-IS-IT", "-"), is("THISISIT")); } - @Test( expected = NullPointerException.class ) - public void testRemoveDuplicateWhitespace_NPE() - { - StringUtils.removeDuplicateWhitespace( null ); + @Test(expected = NullPointerException.class) + public void testRemoveDuplicateWhitespace_NPE() { + StringUtils.removeDuplicateWhitespace(null); } @Test - public void testRemoveDuplicateWhitespace() - { - assertThat( StringUtils.removeDuplicateWhitespace( "dings" ) - , is( "dings" ) ); - - assertThat( StringUtils.removeDuplicateWhitespace( "dings bums" ) - , is( "dings bums" ) ); + public void testRemoveDuplicateWhitespace() { + assertThat(StringUtils.removeDuplicateWhitespace("dings"), is("dings")); - assertThat( StringUtils.removeDuplicateWhitespace( "dings bums" ) - , is( "dings bums" ) ); + assertThat(StringUtils.removeDuplicateWhitespace("dings bums"), is("dings bums")); - assertThat( StringUtils.removeDuplicateWhitespace( "dings \t bums" ) - , is( "dings bums" ) ); + assertThat(StringUtils.removeDuplicateWhitespace("dings bums"), is("dings bums")); + assertThat(StringUtils.removeDuplicateWhitespace("dings \t bums"), is("dings bums")); } - @Test( expected = NullPointerException.class ) - public void testRepeat_NPE() - { - StringUtils.repeat( null, 0 ); + @Test(expected = NullPointerException.class) + public void testRepeat_NPE() { + StringUtils.repeat(null, 0); } - @Test( expected = NegativeArraySizeException.class ) - public void testRepeat_NegativeAmount() - { - StringUtils.repeat( "dings", -1 ); + @Test(expected = NegativeArraySizeException.class) + public void testRepeat_NegativeAmount() { + StringUtils.repeat("dings", -1); } - @Test - public void testRepeat() - { - assertThat( StringUtils.repeat( "dings", 0 ) - , is( "" ) ); + public void testRepeat() { + assertThat(StringUtils.repeat("dings", 0), is("")); - assertThat( StringUtils.repeat( "dings", 1 ) - , is( "dings" ) ); + assertThat(StringUtils.repeat("dings", 1), is("dings")); - assertThat( StringUtils.repeat( "dings", 3 ) - , is( "dingsdingsdings" ) ); + assertThat(StringUtils.repeat("dings", 3), is("dingsdingsdings")); } - @Test - public void testReplace_char() - { - assertThat( StringUtils.replace( null, 'i', 'o' ) - , nullValue() ); + public void testReplace_char() { + assertThat(StringUtils.replace(null, 'i', 'o'), nullValue()); - assertThat( StringUtils.replace( "dings", 'i', 'o' ) - , is( "dongs" ) ); + assertThat(StringUtils.replace("dings", 'i', 'o'), is("dongs")); - assertThat( StringUtils.replace( "dingsbims", 'i', 'o' ) - , is( "dongsboms" ) ); + assertThat(StringUtils.replace("dingsbims", 'i', 'o'), is("dongsboms")); - assertThat( StringUtils.replace( "dings", 'x', 'o' ) - , is( "dings" ) ); + assertThat(StringUtils.replace("dings", 'x', 'o'), is("dings")); } @Test - public void testReplace2_char_max() - { - assertThat( StringUtils.replace( null, 'i', 'o', 0 ) - , nullValue() ); + public void testReplace2_char_max() { + assertThat(StringUtils.replace(null, 'i', 'o', 0), nullValue()); - assertThat( StringUtils.replace( "dingsibumsi", 'i', 'o', 3 ) - , is( "dongsobumso" ) ); + assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 3), is("dongsobumso")); - assertThat( StringUtils.replace( "dingsibumsi", 'i', 'o', 2 ) - , is( "dongsobumsi" ) ); + assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 2), is("dongsobumsi")); - assertThat( StringUtils.replace( "dingsibumsi", 'i', 'o', 0 ) - , is( "dongsobumso" ) ); + assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', 0), is("dongsobumso")); - assertThat( StringUtils.replace( "dingsibumsi", 'i', 'o', -2 ) - , is( "dongsobumso" ) ); + assertThat(StringUtils.replace("dingsibumsi", 'i', 'o', -2), is("dongsobumso")); - assertThat( StringUtils.replace( "dings", 'x', 'o', 2 ) - , is( "dings" ) ); + assertThat(StringUtils.replace("dings", 'x', 'o', 2), is("dings")); } @Test - public void testReplace_string() - { - assertThat( StringUtils.replace( null, "in", "ox" ) - , nullValue() ); + public void testReplace_string() { + assertThat(StringUtils.replace(null, "in", "ox"), nullValue()); - assertThat( StringUtils.replace( "dings", "in", "ox" ) - , is( "doxgs" ) ); + assertThat(StringUtils.replace("dings", "in", "ox"), is("doxgs")); - assertThat( StringUtils.replace( "dingsbins", "in", "ox" ) - , is( "doxgsboxs" ) ); + assertThat(StringUtils.replace("dingsbins", "in", "ox"), is("doxgsboxs")); - assertThat( StringUtils.replace( "dings", "nin", "ox" ) - , is( "dings" ) ); + assertThat(StringUtils.replace("dings", "nin", "ox"), is("dings")); } - @Test - public void testReplace2_string_max() - { - assertThat( StringUtils.replace( null, "in", "ox", 0 ) - , nullValue() ); + public void testReplace2_string_max() { + assertThat(StringUtils.replace(null, "in", "ox", 0), nullValue()); - assertThat( StringUtils.replace( "dingsibumsi", "si", "xo", 3 ) - , is( "dingxobumxo" ) ); + assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 3), is("dingxobumxo")); - assertThat( StringUtils.replace( "dingsibumsi", "si", "xo", 2 ) - , is( "dingxobumxo" ) ); + assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 2), is("dingxobumxo")); - assertThat( StringUtils.replace( "dingsibumsi", "si", "xo", 1 ) - , is( "dingxobumsi" ) ); + assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 1), is("dingxobumsi")); - assertThat( StringUtils.replace( "dingsibumsi", "si", "xo", 0 ) - , is( "dingxobumxo" ) ); + assertThat(StringUtils.replace("dingsibumsi", "si", "xo", 0), is("dingxobumxo")); - assertThat( StringUtils.replace( "dingsibumsi", "si", "xo", -2 ) - , is( "dingxobumxo" ) ); + assertThat(StringUtils.replace("dingsibumsi", "si", "xo", -2), is("dingxobumxo")); - assertThat( StringUtils.replace( "dings", "si", "xo", 2 ) - , is( "dings" ) ); + assertThat(StringUtils.replace("dings", "si", "xo", 2), is("dings")); } @Test - public void testReplaceOnce_char() - { - assertThat( StringUtils.replaceOnce( null, 'i', 'o' ) - , nullValue() ); + public void testReplaceOnce_char() { + assertThat(StringUtils.replaceOnce(null, 'i', 'o'), nullValue()); - assertThat( StringUtils.replaceOnce( "dingsibumsi", 'i', 'o' ) - , is( "dongsibumsi" ) ); + assertThat(StringUtils.replaceOnce("dingsibumsi", 'i', 'o'), is("dongsibumsi")); - assertThat( StringUtils.replaceOnce( "dings", 'x', 'o' ) - , is( "dings" ) ); + assertThat(StringUtils.replaceOnce("dings", 'x', 'o'), is("dings")); } @Test - public void testReplaceOnce_string() - { - assertThat( StringUtils.replaceOnce( null, "in", "ox" ) - , nullValue() ); + public void testReplaceOnce_string() { + assertThat(StringUtils.replaceOnce(null, "in", "ox"), nullValue()); - assertThat( StringUtils.replaceOnce( "dingsibumsi", "si", "xo" ) - , is( "dingxobumsi" ) ); + assertThat(StringUtils.replaceOnce("dingsibumsi", "si", "xo"), is("dingxobumsi")); - assertThat( StringUtils.replaceOnce( "dings", "si", "xo" ) - , is( "dings" ) ); + assertThat(StringUtils.replaceOnce("dings", "si", "xo"), is("dings")); } - @Test - public void testReverse() - { - assertThat( StringUtils.reverse( null ) - , nullValue() ); + public void testReverse() { + assertThat(StringUtils.reverse(null), nullValue()); - assertThat( StringUtils.reverse( "" ) - , is( "" ) ); + assertThat(StringUtils.reverse(""), is("")); - assertThat( StringUtils.reverse( "dings" ) - , is( "sgnid" ) ); + assertThat(StringUtils.reverse("dings"), is("sgnid")); - assertThat( StringUtils.reverse( " dings " ) - , is( " sgnid " ) ); + assertThat(StringUtils.reverse(" dings "), is(" sgnid ")); } - @Test( expected = NullPointerException.class ) - public void testReverseDelimitedString_NPE1() - { - StringUtils.reverseDelimitedString( null, null ); + @Test(expected = NullPointerException.class) + public void testReverseDelimitedString_NPE1() { + StringUtils.reverseDelimitedString(null, null); } - @Test( expected = NullPointerException.class ) - public void testReverseDelimitedString_NPE2() - { - StringUtils.reverseDelimitedString( null, " " ); + @Test(expected = NullPointerException.class) + public void testReverseDelimitedString_NPE2() { + StringUtils.reverseDelimitedString(null, " "); } @Test - public void testReverseDelimitedString() - { - assertThat( StringUtils.reverseDelimitedString( "dings", null ) - , is( "dings" ) ); + public void testReverseDelimitedString() { + assertThat(StringUtils.reverseDelimitedString("dings", null), is("dings")); - assertThat( StringUtils.reverseDelimitedString( "", " " ) - , is( "" ) ); + assertThat(StringUtils.reverseDelimitedString("", " "), is("")); - assertThat( StringUtils.reverseDelimitedString( "dings", " " ) - , is( "dings" ) ); + assertThat(StringUtils.reverseDelimitedString("dings", " "), is("dings")); - assertThat( StringUtils.reverseDelimitedString( " dings ", " " ) - , is( "dings" ) ); + assertThat(StringUtils.reverseDelimitedString(" dings ", " "), is("dings")); - assertThat( StringUtils.reverseDelimitedString( "dings bums", " " ) - , is( "bums dings" ) ); + assertThat(StringUtils.reverseDelimitedString("dings bums", " "), is("bums dings")); } - @Test( expected = IllegalArgumentException.class ) - public void testRight_IAE1() - { - StringUtils.right( null, -1 ); + @Test(expected = IllegalArgumentException.class) + public void testRight_IAE1() { + StringUtils.right(null, -1); } - @Test( expected = IllegalArgumentException.class ) - public void testRight_IAE2() - { - StringUtils.right( "dings", -1 ); + @Test(expected = IllegalArgumentException.class) + public void testRight_IAE2() { + StringUtils.right("dings", -1); } @Test - public void testRight() - { - assertThat( StringUtils.right( null, 0 ) - , nullValue() ); + public void testRight() { + assertThat(StringUtils.right(null, 0), nullValue()); - assertThat( StringUtils.right( "dings", 0 ) - , is( "" ) ); + assertThat(StringUtils.right("dings", 0), is("")); - assertThat( StringUtils.right( "dings", 3 ) - , is( "ngs" ) ); + assertThat(StringUtils.right("dings", 3), is("ngs")); - assertThat( StringUtils.right( "dings ", 3 ) - , is( "gs " ) ); + assertThat(StringUtils.right("dings ", 3), is("gs ")); } - @Test( expected = NullPointerException.class ) - public void testRightPad1_NPE() - { - StringUtils.rightPad( null, 0 ); + @Test(expected = NullPointerException.class) + public void testRightPad1_NPE() { + StringUtils.rightPad(null, 0); } @Test - public void testRightPad1() - { - assertThat( StringUtils.rightPad( "dings", 0 ) - , is( "dings" ) ); + public void testRightPad1() { + assertThat(StringUtils.rightPad("dings", 0), is("dings")); - assertThat( StringUtils.rightPad( "dings", 3 ) - , is( "dings" ) ); + assertThat(StringUtils.rightPad("dings", 3), is("dings")); - assertThat( StringUtils.rightPad( "dings", 10 ) - , is( "dings " ) ); + assertThat(StringUtils.rightPad("dings", 10), is("dings ")); } - @Test( expected = NullPointerException.class ) - public void testRightPad2_NPE1() - { - StringUtils.rightPad( null, 0, null ); + @Test(expected = NullPointerException.class) + public void testRightPad2_NPE1() { + StringUtils.rightPad(null, 0, null); } - @Test( expected = NullPointerException.class ) - public void testRightPad2_NPE2() - { - StringUtils.rightPad( "dings", 0, null ); + @Test(expected = NullPointerException.class) + public void testRightPad2_NPE2() { + StringUtils.rightPad("dings", 0, null); } - @Test( expected = NullPointerException.class ) - public void testRightPad2_NPE23() - { - StringUtils.rightPad( null, 0, "+" ); + @Test(expected = NullPointerException.class) + public void testRightPad2_NPE23() { + StringUtils.rightPad(null, 0, "+"); } @Test - public void testRightPad2() - { - assertThat( StringUtils.rightPad( "dings", 0, "+" ) - , is( "dings" ) ); + public void testRightPad2() { + assertThat(StringUtils.rightPad("dings", 0, "+"), is("dings")); - assertThat( StringUtils.rightPad( "dings", 3, "+" ) - , is( "dings" ) ); + assertThat(StringUtils.rightPad("dings", 3, "+"), is("dings")); - assertThat( StringUtils.rightPad( "dings", 10, "+" ) - , is( "dings+++++" ) ); + assertThat(StringUtils.rightPad("dings", 10, "+"), is("dings+++++")); } - - @Test( expected = NullPointerException.class ) - public void testSplit1_NPE() - { - StringUtils.split( null ); + @Test(expected = NullPointerException.class) + public void testSplit1_NPE() { + StringUtils.split(null); } @Test - public void testSplit1() - { - assertThat( StringUtils.split( "dings" ) - , is( new String[]{ "dings" } ) ); + public void testSplit1() { + assertThat(StringUtils.split("dings"), is(new String[] {"dings"})); - assertThat( StringUtils.split( "dings bums" ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings bums"), is(new String[] {"dings", "bums"})); } - @Test( expected = NullPointerException.class ) - public void testSplit2_NPE1() - { - StringUtils.split( null, null ); + @Test(expected = NullPointerException.class) + public void testSplit2_NPE1() { + StringUtils.split(null, null); } - @Test( expected = NullPointerException.class ) - public void testSplit2_NPE2() - { - StringUtils.split( null, " " ); + @Test(expected = NullPointerException.class) + public void testSplit2_NPE2() { + StringUtils.split(null, " "); } @Test - public void testSplit2() - { - assertThat( StringUtils.split( "dings", null ) - , is( new String[]{ "dings" } ) ); + public void testSplit2() { + assertThat(StringUtils.split("dings", null), is(new String[] {"dings"})); - assertThat( StringUtils.split( "dings bums", null ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings bums", null), is(new String[] {"dings", "bums"})); - assertThat( StringUtils.split( "dings", "+" ) - , is( new String[]{ "dings" } ) ); + assertThat(StringUtils.split("dings", "+"), is(new String[] {"dings"})); - assertThat( StringUtils.split( "dings+bums", "+" ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings+bums", "+"), is(new String[] {"dings", "bums"})); } - @Test( expected = NullPointerException.class ) - public void testSplit3_NPE1() - { - StringUtils.split( null, null, 1 ); + @Test(expected = NullPointerException.class) + public void testSplit3_NPE1() { + StringUtils.split(null, null, 1); } - @Test( expected = NullPointerException.class ) - public void testSplit3_NPE2() - { - StringUtils.split( null, " ", 1 ); + @Test(expected = NullPointerException.class) + public void testSplit3_NPE2() { + StringUtils.split(null, " ", 1); } @Test - public void testSplit3() - { - assertThat( StringUtils.split( "dings", null, 3 ) - , is( new String[]{ "dings" } ) ); - - assertThat( StringUtils.split( "dings bums", null, 3 ) - , is( new String[]{ "dings", "bums" } ) ); + public void testSplit3() { + assertThat(StringUtils.split("dings", null, 3), is(new String[] {"dings"})); - assertThat( StringUtils.split( "dings", "+", 3 ) - , is( new String[]{ "dings" } ) ); + assertThat(StringUtils.split("dings bums", null, 3), is(new String[] {"dings", "bums"})); - assertThat( StringUtils.split( "dings+bums", "+", 3 ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings", "+", 3), is(new String[] {"dings"})); - assertThat( StringUtils.split( "dings+bums", "+", 1 ) - , is( new String[]{ "dings+bums" } ) ); + assertThat(StringUtils.split("dings+bums", "+", 3), is(new String[] {"dings", "bums"})); - assertThat( StringUtils.split( "dings+bums", "+", 0 ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings+bums", "+", 1), is(new String[] {"dings+bums"})); - assertThat( StringUtils.split( "dings+bums", "+", -5 ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.split("dings+bums", "+", 0), is(new String[] {"dings", "bums"})); + assertThat(StringUtils.split("dings+bums", "+", -5), is(new String[] {"dings", "bums"})); } - @Test - public void testStrip1() - { - assertThat( StringUtils.strip( null ) - , nullValue() ); + public void testStrip1() { + assertThat(StringUtils.strip(null), nullValue()); - assertThat( StringUtils.strip( "dings" ) - , is( "dings" ) ); + assertThat(StringUtils.strip("dings"), is("dings")); - assertThat( StringUtils.strip( " dings \t " ) - , is( "dings" ) ); + assertThat(StringUtils.strip(" dings \t "), is("dings")); } @Test - public void testStrip2() - { - assertThat( StringUtils.strip( null, " " ) - , nullValue() ); + public void testStrip2() { + assertThat(StringUtils.strip(null, " "), nullValue()); - assertThat( StringUtils.strip( null, null ) - , nullValue() ); + assertThat(StringUtils.strip(null, null), nullValue()); - assertThat( StringUtils.strip( "dings", " " ) - , is( "dings" ) ); + assertThat(StringUtils.strip("dings", " "), is("dings")); - assertThat( StringUtils.strip( " dings \t ", " " ) - , is( "dings \t" ) ); + assertThat(StringUtils.strip(" dings \t ", " "), is("dings \t")); } @Test - public void testStripAll1() - { - assertThat( StringUtils.stripAll( null ) - , nullValue() ); + public void testStripAll1() { + assertThat(StringUtils.stripAll(null), nullValue()); - assertThat( StringUtils.stripAll( new String[]{} ) - , is( new String[]{} ) ); + assertThat(StringUtils.stripAll(new String[] {}), is(new String[] {})); - assertThat( StringUtils.stripAll( new String[]{ "dings" } ) - , is( new String[]{ "dings" } ) ); + assertThat(StringUtils.stripAll(new String[] {"dings"}), is(new String[] {"dings"})); - assertThat( StringUtils.stripAll( new String[]{ " dings ", " bums \t " } ) - , is( new String[]{ "dings", "bums" } ) ); + assertThat(StringUtils.stripAll(new String[] {" dings ", " bums \t "}), is(new String[] {"dings", "bums"})); } @Test - public void testStripAll2() - { - assertThat( StringUtils.stripAll( null, " " ) - , nullValue() ); + public void testStripAll2() { + assertThat(StringUtils.stripAll(null, " "), nullValue()); - assertThat( StringUtils.stripAll( new String[]{}, " " ) - , is( new String[]{} ) ); + assertThat(StringUtils.stripAll(new String[] {}, " "), is(new String[] {})); - assertThat( StringUtils.stripAll( new String[]{ "dings" }, " " ) - , is( new String[]{ "dings" } ) ); + assertThat(StringUtils.stripAll(new String[] {"dings"}, " "), is(new String[] {"dings"})); - assertThat( StringUtils.stripAll( new String[]{ " dings ", " bums \t " }, " " ) - , is( new String[]{ "dings", "bums \t" } ) ); + assertThat( + StringUtils.stripAll(new String[] {" dings ", " bums \t "}, " "), + is(new String[] {"dings", "bums \t"})); } @Test - public void testStripEnd() - { - assertThat( StringUtils.stripEnd( null, null ) - , nullValue() ); + public void testStripEnd() { + assertThat(StringUtils.stripEnd(null, null), nullValue()); - assertThat( StringUtils.stripEnd( "dings", null ) - , is( "dings" ) ); + assertThat(StringUtils.stripEnd("dings", null), is("dings")); - assertThat( StringUtils.stripEnd( " dings \t ", null ) - , is( " dings" ) ); + assertThat(StringUtils.stripEnd(" dings \t ", null), is(" dings")); - assertThat( StringUtils.stripEnd( null, " " ) - , nullValue() ); + assertThat(StringUtils.stripEnd(null, " "), nullValue()); - assertThat( StringUtils.stripEnd( "dings", " " ) - , is( "dings" ) ); + assertThat(StringUtils.stripEnd("dings", " "), is("dings")); - assertThat( StringUtils.stripEnd( " dings \t ", " " ) - , is( " dings \t" ) ); + assertThat(StringUtils.stripEnd(" dings \t ", " "), is(" dings \t")); } @Test - public void testStripStart() - { - assertThat( StringUtils.stripStart( null, null ) - , nullValue() ); + public void testStripStart() { + assertThat(StringUtils.stripStart(null, null), nullValue()); - assertThat( StringUtils.stripStart( "dings", null ) - , is( "dings" ) ); + assertThat(StringUtils.stripStart("dings", null), is("dings")); - assertThat( StringUtils.stripStart( " dings \t ", null ) - , is( "dings \t " ) ); + assertThat(StringUtils.stripStart(" dings \t ", null), is("dings \t ")); - assertThat( StringUtils.stripStart( null, " " ) - , nullValue() ); + assertThat(StringUtils.stripStart(null, " "), nullValue()); - assertThat( StringUtils.stripStart( "dings", " " ) - , is( "dings" ) ); + assertThat(StringUtils.stripStart("dings", " "), is("dings")); - assertThat( StringUtils.stripStart( " \t dings \t ", " " ) - , is( "\t dings \t " ) ); + assertThat(StringUtils.stripStart(" \t dings \t ", " "), is("\t dings \t ")); } @Test - public void testSubstring1() - { - assertThat( StringUtils.substring( null, 0 ) - , nullValue() ); - assertThat( StringUtils.substring( null, -3 ) - , nullValue() ); + public void testSubstring1() { + assertThat(StringUtils.substring(null, 0), nullValue()); + assertThat(StringUtils.substring(null, -3), nullValue()); - assertThat( StringUtils.substring( "dings", 2 ) - , is( "ngs" ) ); + assertThat(StringUtils.substring("dings", 2), is("ngs")); - assertThat( StringUtils.substring( "dings", -2 ) - , is( "gs" ) ); + assertThat(StringUtils.substring("dings", -2), is("gs")); - assertThat( StringUtils.substring( "dings", 20 ) - , is( "" ) ); + assertThat(StringUtils.substring("dings", 20), is("")); } @Test - public void testSubstring2() - { - assertThat( StringUtils.substring( null, 0, 2 ) - , nullValue() ); + public void testSubstring2() { + assertThat(StringUtils.substring(null, 0, 2), nullValue()); - assertThat( StringUtils.substring( null, -3, 0 ) - , nullValue() ); + assertThat(StringUtils.substring(null, -3, 0), nullValue()); - assertThat( StringUtils.substring( "dings", 2, 4 ) - , is( "ng" ) ); + assertThat(StringUtils.substring("dings", 2, 4), is("ng")); - assertThat( StringUtils.substring( "dings", -2, 4 ) - , is( "g" ) ); + assertThat(StringUtils.substring("dings", -2, 4), is("g")); - assertThat( StringUtils.substring( "dings", 20, 23 ) - , is( "" ) ); + assertThat(StringUtils.substring("dings", 20, 23), is("")); - assertThat( StringUtils.substring( "dings", 4, 2 ) - , is( "" ) ); + assertThat(StringUtils.substring("dings", 4, 2), is("")); } @Test - public void testSwapCase() - { - assertThat( StringUtils.swapCase( null ) - , nullValue() ); + public void testSwapCase() { + assertThat(StringUtils.swapCase(null), nullValue()); - assertThat( StringUtils.swapCase( "dings" ) - , is( "DINGS" ) ); - - assertThat( StringUtils.swapCase( "DinGs" ) - , is( "dINgS" ) ); + assertThat(StringUtils.swapCase("dings"), is("DINGS")); + assertThat(StringUtils.swapCase("DinGs"), is("dINgS")); } @Test - public void testTrim() - { - assertThat( StringUtils.trim( null ) - , nullValue() ); + public void testTrim() { + assertThat(StringUtils.trim(null), nullValue()); - assertThat( StringUtils.trim( " " ) - , is( "" ) ); + assertThat(StringUtils.trim(" "), is("")); - assertThat( StringUtils.trim( " c " ) - , is( "c" ) ); + assertThat(StringUtils.trim(" c "), is("c")); - assertThat( StringUtils.trim( " dings \n " ) - , is( "dings" ) ); + assertThat(StringUtils.trim(" dings \n "), is("dings")); } @Test - public void testUncapitalise() - { - assertThat( StringUtils.uncapitalise( null ) - , nullValue() ); + public void testUncapitalise() { + assertThat(StringUtils.uncapitalise(null), nullValue()); - assertThat( StringUtils.uncapitalise( " " ) - , is( " " ) ); + assertThat(StringUtils.uncapitalise(" "), is(" ")); - assertThat( StringUtils.uncapitalise( "dings" ) - , is( "dings" ) ); + assertThat(StringUtils.uncapitalise("dings"), is("dings")); - assertThat( StringUtils.uncapitalise( "Dings" ) - , is( "dings" ) ); + assertThat(StringUtils.uncapitalise("Dings"), is("dings")); - assertThat( StringUtils.uncapitalise( "DINGS" ) - , is( "dINGS" ) ); + assertThat(StringUtils.uncapitalise("DINGS"), is("dINGS")); } @Test - public void testUncapitaliseAllWords() - { - assertThat( StringUtils.uncapitaliseAllWords( null ) - , nullValue() ); + public void testUncapitaliseAllWords() { + assertThat(StringUtils.uncapitaliseAllWords(null), nullValue()); - assertThat( StringUtils.uncapitaliseAllWords( " " ) - , is( " " ) ); + assertThat(StringUtils.uncapitaliseAllWords(" "), is(" ")); - assertThat( StringUtils.uncapitaliseAllWords( "dings bums" ) - , is( "dings bums" ) ); + assertThat(StringUtils.uncapitaliseAllWords("dings bums"), is("dings bums")); - assertThat( StringUtils.uncapitaliseAllWords( "Dings Bums" ) - , is( "dings bums" ) ); + assertThat(StringUtils.uncapitaliseAllWords("Dings Bums"), is("dings bums")); - assertThat( StringUtils.uncapitaliseAllWords( "DINGS Bums" ) - , is( "dINGS bums" ) ); + assertThat(StringUtils.uncapitaliseAllWords("DINGS Bums"), is("dINGS bums")); } @Test - public void testUnifyLineSeparators1() - { - String sls = System.getProperty( "line.separator" ); + public void testUnifyLineSeparators1() { + String sls = System.getProperty("line.separator"); - assertThat( StringUtils.unifyLineSeparators( null ) - , nullValue() ); + assertThat(StringUtils.unifyLineSeparators(null), nullValue()); - assertThat( StringUtils.unifyLineSeparators( " " ) - , is( " " ) ); + assertThat(StringUtils.unifyLineSeparators(" "), is(" ")); - assertThat( StringUtils.unifyLineSeparators( "dings\nbums\r\ndongs" ) - , is( "dings" + sls + "bums" + sls + "dongs") ); + assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs"), is("dings" + sls + "bums" + sls + "dongs")); } @Test - public void testUnifyLineSeparators2() - { - assertThat( StringUtils.unifyLineSeparators( null, "\n" ) - , nullValue() ); + public void testUnifyLineSeparators2() { + assertThat(StringUtils.unifyLineSeparators(null, "\n"), nullValue()); - assertThat( StringUtils.unifyLineSeparators( " ", "\n" ) - , is( " " ) ); + assertThat(StringUtils.unifyLineSeparators(" ", "\n"), is(" ")); - assertThat( StringUtils.unifyLineSeparators( " ", null ) // takes the sytem line separator - , is( " " ) ); + assertThat( + StringUtils.unifyLineSeparators(" ", null) // takes the sytem line separator + , + is(" ")); - assertThat( StringUtils.unifyLineSeparators( "dings\nbums\r\ndongs", "\n" ) - , is( "dings\nbums\ndongs" ) ); + assertThat(StringUtils.unifyLineSeparators("dings\nbums\r\ndongs", "\n"), is("dings\nbums\ndongs")); } @Test - public void testUppercase() - { - assertThat( StringUtils.upperCase( null ) - , nullValue() ); - - assertThat( StringUtils.upperCase( " " ) - , is( " " ) ); + public void testUppercase() { + assertThat(StringUtils.upperCase(null), nullValue()); - assertThat( StringUtils.upperCase( "" ) - , is( "" ) ); + assertThat(StringUtils.upperCase(" "), is(" ")); - assertThat( StringUtils.upperCase( "dings" ) - , is( "DINGS" ) ); + assertThat(StringUtils.upperCase(""), is("")); + assertThat(StringUtils.upperCase("dings"), is("DINGS")); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java index 2e305382..a61637b4 100644 --- a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java +++ b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,26 +16,23 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; - import junit.framework.ComparisonFailure; import junit.framework.TestCase; - import org.apache.commons.io.IOUtils; import org.apache.maven.shared.utils.xml.XmlStreamReader; /** - * + * * @author Hervé Boutemy */ -public class XmlStreamReaderTest - extends TestCase -{ +public class XmlStreamReaderTest extends TestCase { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; /** greek */ @@ -48,161 +43,134 @@ public class XmlStreamReaderTest private static final String TEXT_EUC_JP = "hiragana A: \u3042"; /** Unicode: support everything */ private static final String TEXT_UNICODE = - TEXT_LATIN1 + ", " + - TEXT_LATIN7 + ", " + - TEXT_LATIN15 + ", " + - TEXT_EUC_JP; + TEXT_LATIN1 + ", " + TEXT_LATIN7 + ", " + TEXT_LATIN15 + ", " + TEXT_EUC_JP; /** see http://unicode.org/faq/utf_bom.html#BOM */ - private static final byte[] BOM_UTF8 = { (byte)0xEF, (byte)0xBB, (byte)0xBF }; - private static final byte[] BOM_UTF16BE = { (byte)0xFE, (byte)0xFF }; - private static final byte[] BOM_UTF16LE = { (byte)0xFF, (byte)0xFE }; + private static final byte[] BOM_UTF8 = {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}; + + private static final byte[] BOM_UTF16BE = {(byte) 0xFE, (byte) 0xFF}; + private static final byte[] BOM_UTF16LE = {(byte) 0xFF, (byte) 0xFE}; - private static String createXmlContent( String text, String encoding ) - { + private static String createXmlContent(String text, String encoding) { String xmlDecl = ""; - if ( encoding != null ) - { + if (encoding != null) { xmlDecl = ""; } return xmlDecl + "\n" + text + ""; } - private static void checkXmlContent( String xml, String encoding ) throws IOException - { - checkXmlContent( xml, encoding, null ); + private static void checkXmlContent(String xml, String encoding) throws IOException { + checkXmlContent(xml, encoding, null); } - private static void checkXmlContent( String xml, String encoding, byte[] bom ) throws IOException - { - byte[] xmlContent = xml.getBytes( encoding ); - InputStream in = new ByteArrayInputStream( xmlContent ); - - if ( bom != null ) - { - in = new SequenceInputStream( new ByteArrayInputStream( bom ), in ); + private static void checkXmlContent(String xml, String encoding, byte[] bom) throws IOException { + 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 = IOUtils.toString( reader ); - assertEquals( xml, result ); + XmlStreamReader reader = new XmlStreamReader(in); + assertEquals(encoding, reader.getEncoding()); + String result = IOUtils.toString(reader); + assertEquals(xml, result); } - private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding ) - throws IOException - { - checkXmlStreamReader( text, encoding, effectiveEncoding, null ); + private static void checkXmlStreamReader(String text, String encoding, String effectiveEncoding) + throws IOException { + checkXmlStreamReader(text, encoding, effectiveEncoding, null); } - private static void checkXmlStreamReader( String text, String encoding ) throws IOException - { - checkXmlStreamReader( text, encoding, encoding, null ); + private static void checkXmlStreamReader(String text, String encoding) throws IOException { + checkXmlStreamReader(text, encoding, encoding, null); } - private static void checkXmlStreamReader( String text, String encoding, byte[] bom ) throws IOException - { - checkXmlStreamReader( text, encoding, encoding, bom ); + private static void checkXmlStreamReader(String text, String encoding, byte[] bom) throws IOException { + checkXmlStreamReader(text, encoding, encoding, bom); } - private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding, byte[] bom ) - throws IOException - { - String xml = createXmlContent( text, encoding ); - checkXmlContent( xml, effectiveEncoding, bom ); + private static void checkXmlStreamReader(String text, String encoding, String effectiveEncoding, byte[] bom) + throws IOException { + String xml = createXmlContent(text, encoding); + checkXmlContent(xml, effectiveEncoding, bom); } - public void testNoXmlHeader() throws IOException - { + public void testNoXmlHeader() throws IOException { String xml = "text with no XML header"; - checkXmlContent( xml, "UTF-8" ); - checkXmlContent( xml, "UTF-8", BOM_UTF8 ); + checkXmlContent(xml, "UTF-8"); + checkXmlContent(xml, "UTF-8", BOM_UTF8); } - public void testDefaultEncoding() throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8" ); - checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8", BOM_UTF8 ); + public void testDefaultEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8"); + checkXmlStreamReader(TEXT_UNICODE, null, "UTF-8", BOM_UTF8); } - public void testUTF8Encoding() throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-8" ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-8", BOM_UTF8 ); + public void testUTF8Encoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-8"); + checkXmlStreamReader(TEXT_UNICODE, "UTF-8", BOM_UTF8); } - public void testUTF16Encoding() throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", null ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE ); - checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE ); + public void testUTF16Encoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", null); + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE); + checkXmlStreamReader(TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE); } - public void testUTF16BEEncoding() throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16BE" ); + public void testUTF16BEEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16BE"); } - public void testUTF16LEEncoding() throws IOException - { - checkXmlStreamReader( TEXT_UNICODE, "UTF-16LE" ); + public void testUTF16LEEncoding() throws IOException { + checkXmlStreamReader(TEXT_UNICODE, "UTF-16LE"); } - public void testLatin1Encoding() throws IOException - { - checkXmlStreamReader( TEXT_LATIN1, "ISO-8859-1" ); + public void testLatin1Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN1, "ISO-8859-1"); } - public void testLatin7Encoding() throws IOException - { - checkXmlStreamReader( TEXT_LATIN7, "ISO-8859-7" ); + public void testLatin7Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN7, "ISO-8859-7"); } - public void testLatin15Encoding() throws IOException - { - checkXmlStreamReader( TEXT_LATIN15, "ISO-8859-15" ); + public void testLatin15Encoding() throws IOException { + checkXmlStreamReader(TEXT_LATIN15, "ISO-8859-15"); } - public void testEUC_JPEncoding() throws IOException - { - checkXmlStreamReader( TEXT_EUC_JP, "EUC-JP" ); + public void testEUC_JPEncoding() throws IOException { + checkXmlStreamReader(TEXT_EUC_JP, "EUC-JP"); } - public void testEBCDICEncoding() throws IOException - { - checkXmlStreamReader( "simple text in EBCDIC", "CP1047" ); + public void testEBCDICEncoding() throws IOException { + checkXmlStreamReader("simple text in EBCDIC", "CP1047"); } - public void testInappropriateEncoding() throws IOException - { - try - { - checkXmlStreamReader( TEXT_UNICODE, "ISO-8859-2" ); - fail( "Check should have failed, since some characters are not available in the specified encoding" ); - } - catch ( ComparisonFailure cf ) - { + public void testInappropriateEncoding() throws IOException { + try { + checkXmlStreamReader(TEXT_UNICODE, "ISO-8859-2"); + fail("Check should have failed, since some characters are not available in the specified encoding"); + } catch (ComparisonFailure cf) { // expected failure, since the encoding does not contain some characters } } - public void testEncodingAttribute() throws IOException - { + public void testEncodingAttribute() throws IOException { String xml = ""; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = ""; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = ""; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); xml = "\n"; - checkXmlContent( xml, "US-ASCII" ); + checkXmlContent(xml, "US-ASCII"); xml = "\n"; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); xml = ""; - checkXmlContent( xml, "UTF-8" ); + checkXmlContent(xml, "UTF-8"); } } diff --git a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java index fdc83b0a..7ae03f9d 100644 --- a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.cli; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,14 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasItemInArray; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +package org.apache.maven.shared.utils.cli; import java.util.Arrays; import java.util.HashMap; @@ -34,50 +25,50 @@ import java.util.Properties; import org.apache.maven.shared.utils.Os; - import org.junit.Test; -public class CommandLineUtilsTest -{ +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItemInArray; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class CommandLineUtilsTest { /** * Tests that case-insensitive environment variables are normalized to upper case. */ @Test - public void testGetSystemEnvVarsCaseInsensitive() - { - Properties vars = CommandLineUtils.getSystemEnvVars( false ); - for ( Object o : vars.keySet() ) - { + public void testGetSystemEnvVarsCaseInsensitive() { + Properties vars = CommandLineUtils.getSystemEnvVars(false); + for (Object o : vars.keySet()) { String variable = (String) o; - assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable ); + assertEquals(variable.toUpperCase(Locale.ENGLISH), variable); } } @Test - public void testEnsureCaseSensitivity() - { + public void testEnsureCaseSensitivity() { Map data = new HashMap<>(); - data.put( "abz", "cool" ); - assertTrue( CommandLineUtils.ensureCaseSensitivity( data, false ).containsKey( "ABZ" ) ); - assertTrue( CommandLineUtils.ensureCaseSensitivity( data, true ).containsKey( "abz" ) ); + data.put("abz", "cool"); + assertTrue(CommandLineUtils.ensureCaseSensitivity(data, false).containsKey("ABZ")); + assertTrue(CommandLineUtils.ensureCaseSensitivity(data, true).containsKey("abz")); } /** * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms. */ @Test - public void testGetSystemEnvVarsWindows() - { - if ( !Os.isFamily( Os.FAMILY_WINDOWS ) ) - { + public void testGetSystemEnvVarsWindows() { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { return; } Properties vars = CommandLineUtils.getSystemEnvVars(); - for ( Object o : vars.keySet() ) - { + for (Object o : vars.keySet()) { String variable = (String) o; - assertEquals( variable.toUpperCase( Locale.ENGLISH ), variable ); + assertEquals(variable.toUpperCase(Locale.ENGLISH), variable); } } @@ -85,25 +76,22 @@ public void testGetSystemEnvVarsWindows() * Tests the splitting of a command line into distinct arguments. */ @Test - public void testTranslateCommandline() - throws Exception - { - assertCmdLineArgs( new String[] {}, null ); - assertCmdLineArgs( new String[] {}, "" ); + public void testTranslateCommandline() throws Exception { + assertCmdLineArgs(new String[] {}, null); + assertCmdLineArgs(new String[] {}, ""); - assertCmdLineArgs( new String[] { "foo", "bar" }, "foo bar" ); - assertCmdLineArgs( new String[] { "foo", "bar" }, " foo bar " ); + assertCmdLineArgs(new String[] {"foo", "bar"}, "foo bar"); + assertCmdLineArgs(new String[] {"foo", "bar"}, " foo bar "); - assertCmdLineArgs( new String[] { "foo", " double quotes ", "bar" }, "foo \" double quotes \" bar" ); - assertCmdLineArgs( new String[] { "foo", " single quotes ", "bar" }, "foo ' single quotes ' bar" ); + assertCmdLineArgs(new String[] {"foo", " double quotes ", "bar"}, "foo \" double quotes \" bar"); + assertCmdLineArgs(new String[] {"foo", " single quotes ", "bar"}, "foo ' single quotes ' bar"); - assertCmdLineArgs( new String[] { "foo", " \" ", "bar" }, "foo ' \" ' bar" ); - assertCmdLineArgs( new String[] { "foo", " ' ", "bar" }, "foo \" ' \" bar" ); + assertCmdLineArgs(new String[] {"foo", " \" ", "bar"}, "foo ' \" ' bar"); + assertCmdLineArgs(new String[] {"foo", " ' ", "bar"}, "foo \" ' \" bar"); } @Test - public void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenCommandLineExceptionIsThrown() - { + public void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenCommandLineExceptionIsThrown() { try { new Commandline("echo \"let\"s go\"").execute(); } catch (CommandLineException e) { @@ -113,7 +101,6 @@ public void givenADoubleQuoteMarkInArgument_whenExecutingCode_thenCommandLineExc fail("Exception was not thrown when given invalid (3 unescaped double quote) input"); } - @Test public void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Returned() throws Exception { final Process p = new Commandline("echo \"let's go\"").execute(); @@ -123,47 +110,43 @@ public void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Retur @Test public void givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped() - throws Exception - { + throws Exception { final String command = "echo \"let's go\""; - final String[] expected = new String[] { "echo", "let's go" }; - assertCmdLineArgs( expected, command ); + final String[] expected = new String[] {"echo", "let's go"}; + assertCmdLineArgs(expected, command); } @Test - public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() - throws Exception - { + public void + givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() + throws Exception { final String command = "echo \"let\\\"s go\""; - final String[] expected = new String[] { "echo", "let\\\"s go" }; - assertCmdLineArgs( expected, command ); + final String[] expected = new String[] {"echo", "let\\\"s go"}; + assertCmdLineArgs(expected, command); } @Test - public void givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() - throws Exception - { + public void + givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() + throws Exception { final String command = "echo \"let\\'s go\""; - final String[] expected = new String[] { "echo", "let\\'s go"}; - assertCmdLineArgs( expected, command ); + final String[] expected = new String[] {"echo", "let\\'s go"}; + assertCmdLineArgs(expected, command); } @Test public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenNoExceptionIsThrown() - throws Exception - { - Process p = new Commandline( "echo \"let\\\"s go\"" ).execute(); + throws Exception { + Process p = new Commandline("echo \"let\\\"s go\"").execute(); p.waitFor(); assertEquals(0, p.exitValue()); } - private void assertCmdLineArgs( final String[] expected, final String cmdLine ) - throws Exception - { - String[] actual = CommandLineUtils.translateCommandline( cmdLine ); - assertNotNull( actual ); - assertEquals( expected.length, actual.length ); - assertEquals( Arrays.asList( expected ), Arrays.asList( actual ) ); + private void assertCmdLineArgs(final String[] expected, final String cmdLine) throws Exception { + String[] actual = CommandLineUtils.translateCommandline(cmdLine); + assertNotNull(actual); + assertEquals(expected.length, actual.length); + assertEquals(Arrays.asList(expected), Arrays.asList(actual)); } @Test @@ -174,8 +157,8 @@ public void environmentVariableWithNullShouldNotBeSet() { String[] environmentVariables = commandline.getEnvironmentVariables(); - assertNotNull( environmentVariables ); - assertThat( environmentVariables, not( hasItemInArray( "TEST_NULL_ENV=null" ) ) ); + assertNotNull(environmentVariables); + assertThat(environmentVariables, not(hasItemInArray("TEST_NULL_ENV=null"))); } @Test @@ -186,19 +169,19 @@ public void environmentVariableFromSystemIsCopiedByDefault() { String[] environmentVariables = commandline.getEnvironmentVariables(); assertNotNull(environmentVariables); - assertThat(environmentVariables, hasItemInArray( "TEST_SHARED_ENV=TestValue" ) ); + assertThat(environmentVariables, hasItemInArray("TEST_SHARED_ENV=TestValue")); } @Test public void environmentVariableFromSystemIsNotCopiedIfInheritedIsFalse() { Commandline commandline = new Commandline(); - commandline.setShellEnvironmentInherited( false ); + commandline.setShellEnvironmentInherited(false); String[] environmentVariables = commandline.getEnvironmentVariables(); assertNotNull(environmentVariables); - assertEquals(0, environmentVariables.length ); + assertEquals(0, environmentVariables.length); } @Test @@ -210,7 +193,6 @@ public void environmentVariableFromSystemIsRemoved() { String[] environmentVariables = commandline.getEnvironmentVariables(); assertNotNull(environmentVariables); - assertThat(environmentVariables, not ( hasItemInArray( "TEST_SHARED_ENV=TestValue" ) ) ); + assertThat(environmentVariables, not(hasItemInArray("TEST_SHARED_ENV=TestValue"))); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java index 8032ae2d..c9e9f3c7 100644 --- a/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java +++ b/src/test/java/org/apache/maven/shared/utils/cli/shell/BourneShellTest.java @@ -1,7 +1,3 @@ -package org.apache.maven.shared.utils.cli.shell; - -import java.util.List; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -11,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -20,178 +16,168 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.cli.shell; -import org.apache.maven.shared.utils.StringUtils; -import org.apache.maven.shared.utils.cli.Commandline; +import java.util.List; import junit.framework.TestCase; +import org.apache.maven.shared.utils.StringUtils; +import org.apache.maven.shared.utils.cli.Commandline; -public class BourneShellTest - extends TestCase -{ +public class BourneShellTest extends TestCase { - Shell newShell() - { + Shell newShell() { return new BourneShell(); } - public void testQuoteWorkingDirectoryAndExecutable() - { + public void testQuoteWorkingDirectoryAndExecutable() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/local/bin" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/local/bin"); + sh.setExecutable("chmod"); - String executable = StringUtils.join( sh.getShellCommandLine().iterator(), " " ); + String executable = StringUtils.join(sh.getShellCommandLine().iterator(), " "); - assertEquals( "/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable ); + assertEquals("/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable); } - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() - { + public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/local/'something else'" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/local/'something else'"); + sh.setExecutable("chmod"); - String executable = StringUtils.join( sh.getShellCommandLine().iterator(), " " ); + String executable = StringUtils.join(sh.getShellCommandLine().iterator(), " "); - assertEquals( "/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable ); + assertEquals("/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable); } - public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() - { + public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() { Shell sh = newShell(); - sh.setWorkingDirectory( "\\usr\\local\\'something else'" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("\\usr\\local\\'something else'"); + sh.setExecutable("chmod"); - String executable = StringUtils.join( sh.getShellCommandLine().iterator(), " " ); + String executable = StringUtils.join(sh.getShellCommandLine().iterator(), " "); - assertEquals( "/bin/sh -c cd '\\usr\\local\\'\"'\"'something else'\"'\"'' && 'chmod'", executable ); + assertEquals("/bin/sh -c cd '\\usr\\local\\'\"'\"'something else'\"'\"'' && 'chmod'", executable); } - public void testPreserveSingleQuotesOnArgument() - { + public void testPreserveSingleQuotesOnArgument() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/bin" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/bin"); + sh.setExecutable("chmod"); List shellCommandLine = sh.getShellCommandLine("\"some arg with spaces\""); - String cli = StringUtils.join( shellCommandLine.iterator(), " " ); - assertTrue( cli.endsWith( "'\"some arg with spaces\"'" ) ); + String cli = StringUtils.join(shellCommandLine.iterator(), " "); + assertTrue(cli.endsWith("'\"some arg with spaces\"'")); } - public void testAddSingleQuotesOnArgumentWithSpaces() - { + public void testAddSingleQuotesOnArgumentWithSpaces() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/bin" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/bin"); + sh.setExecutable("chmod"); List shellCommandLine = sh.getShellCommandLine("some arg with spaces"); - String cli = StringUtils.join( shellCommandLine.iterator(), " " ); - assertTrue( cli.endsWith("'some arg with spaces'")); + String cli = StringUtils.join(shellCommandLine.iterator(), " "); + assertTrue(cli.endsWith("'some arg with spaces'")); } - public void testAddArgumentWithSingleQuote() - { + public void testAddArgumentWithSingleQuote() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/bin" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/bin"); + sh.setExecutable("chmod"); List shellCommandLine = sh.getShellCommandLine("arg'withquote"); - assertEquals("cd '/usr/bin' && 'chmod' 'arg'\"'\"'withquote'", shellCommandLine.get(shellCommandLine.size() - 1)); + assertEquals( + "cd '/usr/bin' && 'chmod' 'arg'\"'\"'withquote'", shellCommandLine.get(shellCommandLine.size() - 1)); } - public void testArgumentsWithSemicolon() - { - + public void testArgumentsWithSemicolon() { Shell sh = newShell(); - sh.setWorkingDirectory( "/usr/bin" ); - sh.setExecutable( "chmod" ); + sh.setWorkingDirectory("/usr/bin"); + sh.setExecutable("chmod"); List shellCommandLine = sh.getShellCommandLine(";some&argwithunix$chars"); - String cli = StringUtils.join( shellCommandLine.iterator(), " " ); - assertTrue( cli.endsWith( "';some&argwithunix$chars'" ) ); - - Commandline commandline = new Commandline( newShell() ); - commandline.setExecutable( "chmod" ); - commandline.getShell().setQuotedArgumentsEnabled( true ); - commandline.createArg().setValue( "--password" ); - commandline.createArg().setValue( ";password" ); - - List lines = commandline.getShell().getShellCommandLine( commandline.getArguments() ); - - assertEquals( "/bin/sh", lines.get( 0 ) ); - assertEquals( "-c", lines.get( 1 ) ); - assertEquals( "'chmod' '--password' ';password'", lines.get( 2 ) ); - - commandline = new Commandline( newShell() ); - commandline.setExecutable( "chmod" ); - commandline.getShell().setQuotedArgumentsEnabled( true ); - commandline.createArg().setValue( "--password" ); - commandline.createArg().setValue( ";password" ); - lines = commandline.getShell().getShellCommandLine( commandline.getArguments() ); - - assertEquals( "/bin/sh", lines.get( 0) ); - assertEquals( "-c", lines.get( 1 ) ); - assertEquals( "'chmod' '--password' ';password'", lines.get( 2 ) ); - - commandline = new Commandline( new CmdShell() ); - commandline.getShell().setQuotedArgumentsEnabled( true ); - commandline.createArg().setValue( "--password" ); - commandline.createArg().setValue( ";password" ); - lines = commandline.getShell().getShellCommandLine( commandline.getArguments() ); - - assertEquals( "cmd.exe", lines.get( 0 ) ); - assertEquals( "/X", lines.get( 1 ) ); - assertEquals( "/C", lines.get( 2 ) ); - assertEquals( "\"--password ;password\"", lines.get( 3 ) ); + String cli = StringUtils.join(shellCommandLine.iterator(), " "); + assertTrue(cli.endsWith("';some&argwithunix$chars'")); + + Commandline commandline = new Commandline(newShell()); + commandline.setExecutable("chmod"); + commandline.getShell().setQuotedArgumentsEnabled(true); + commandline.createArg().setValue("--password"); + commandline.createArg().setValue(";password"); + + List lines = commandline.getShell().getShellCommandLine(commandline.getArguments()); + + assertEquals("/bin/sh", lines.get(0)); + assertEquals("-c", lines.get(1)); + assertEquals("'chmod' '--password' ';password'", lines.get(2)); + + commandline = new Commandline(newShell()); + commandline.setExecutable("chmod"); + commandline.getShell().setQuotedArgumentsEnabled(true); + commandline.createArg().setValue("--password"); + commandline.createArg().setValue(";password"); + lines = commandline.getShell().getShellCommandLine(commandline.getArguments()); + + assertEquals("/bin/sh", lines.get(0)); + assertEquals("-c", lines.get(1)); + assertEquals("'chmod' '--password' ';password'", lines.get(2)); + + commandline = new Commandline(new CmdShell()); + commandline.getShell().setQuotedArgumentsEnabled(true); + commandline.createArg().setValue("--password"); + commandline.createArg().setValue(";password"); + lines = commandline.getShell().getShellCommandLine(commandline.getArguments()); + + assertEquals("cmd.exe", lines.get(0)); + assertEquals("/X", lines.get(1)); + assertEquals("/C", lines.get(2)); + assertEquals("\"--password ;password\"", lines.get(3)); } - public void testBourneShellQuotingCharacters() - throws Exception - { + public void testBourneShellQuotingCharacters() throws Exception { // { ' ', '$', ';', '&', '|', '<', '>', '*', '?', '(', ')' }; - // test with values http://steve-parker.org/sh/bourne.shtml Appendix B - Meta-characters and Reserved Words - Commandline commandline = new Commandline( newShell() ); - commandline.setExecutable( "chmod" ); - commandline.getShell().setQuotedArgumentsEnabled( true ); - commandline.createArg().setValue( " " ); - commandline.createArg().setValue( "|" ); - commandline.createArg().setValue( "&&" ); - commandline.createArg().setValue( "||" ); - commandline.createArg().setValue( ";" ); - commandline.createArg().setValue( ";;" ); - commandline.createArg().setValue( "&" ); - commandline.createArg().setValue( "()" ); - commandline.createArg().setValue( "<" ); - commandline.createArg().setValue( "<<" ); - commandline.createArg().setValue( ">" ); - commandline.createArg().setValue( ">>" ); - commandline.createArg().setValue( "*" ); - commandline.createArg().setValue( "?" ); - commandline.createArg().setValue( "[" ); - commandline.createArg().setValue( "]" ); - commandline.createArg().setValue( "{" ); - commandline.createArg().setValue( "}" ); - commandline.createArg().setValue( "`" ); - commandline.createArg().setValue( "#" ); - - List lines = commandline.getShell().getShellCommandLine( commandline.getArguments() ); - - assertEquals( "/bin/sh", lines.get( 0 ) ); - assertEquals( "-c", lines.get( 1 ) ); - assertEquals( "'chmod' ' ' '|' '&&' '||' ';' ';;' '&' '()' '<' '<<' '>' '>>' '*' '?' '[' ']' '{' '}' '`' '#'", - lines.get( 2 ) ); + // test with values https://steve-parker.org/sh/bourne.shtml Appendix B - Meta-characters and Reserved Words + Commandline commandline = new Commandline(newShell()); + commandline.setExecutable("chmod"); + commandline.getShell().setQuotedArgumentsEnabled(true); + commandline.createArg().setValue(" "); + commandline.createArg().setValue("|"); + commandline.createArg().setValue("&&"); + commandline.createArg().setValue("||"); + commandline.createArg().setValue(";"); + commandline.createArg().setValue(";;"); + commandline.createArg().setValue("&"); + commandline.createArg().setValue("()"); + commandline.createArg().setValue("<"); + commandline.createArg().setValue("<<"); + commandline.createArg().setValue(">"); + commandline.createArg().setValue(">>"); + commandline.createArg().setValue("*"); + commandline.createArg().setValue("?"); + commandline.createArg().setValue("["); + commandline.createArg().setValue("]"); + commandline.createArg().setValue("{"); + commandline.createArg().setValue("}"); + commandline.createArg().setValue("`"); + commandline.createArg().setValue("#"); + + List lines = commandline.getShell().getShellCommandLine(commandline.getArguments()); + + assertEquals("/bin/sh", lines.get(0)); + assertEquals("-c", lines.get(1)); + assertEquals( + "'chmod' ' ' '|' '&&' '||' ';' ';;' '&' '()' '<' '<<' '>' '>>' '*' '?' '[' ']' '{' '}' '`' '#'", + lines.get(2)); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java b/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java index 5ccd2e01..3653d78f 100644 --- a/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java +++ b/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.exceptionutils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,39 +16,33 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.exceptionutils; /** * * @author Mark Struberg */ -public class TestException - extends Exception -{ +public class TestException extends Exception { private Throwable cause; private Throwable specialCause; - public TestException() - { + public TestException() { super(); } - public void setSourceException( Throwable cause ) - { + public void setSourceException(Throwable cause) { this.cause = cause; } - public Throwable getSourceException() - { + public Throwable getSourceException() { return cause; } - public Throwable getSpecialCause() - { + public Throwable getSpecialCause() { return specialCause; } - public void setSpecialCause( Throwable specialCause ) - { + public void setSpecialCause(Throwable specialCause) { this.specialCause = specialCause; } } diff --git a/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestExceptionWithDetail.java b/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestExceptionWithDetail.java index 928b18cb..3322ca0e 100644 --- a/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestExceptionWithDetail.java +++ b/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestExceptionWithDetail.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.exceptionutils; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,29 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.exceptionutils; /** * This test exception has a 'detail' field. * * @author Mark Struberg */ -public class TestExceptionWithDetail - extends Exception -{ +public class TestExceptionWithDetail extends Exception { private Throwable detail; - public TestExceptionWithDetail() - { + public TestExceptionWithDetail() { super(); } - public Throwable getDetail() - { + public Throwable getDetail() { return detail; } - public void setDetail( Throwable detail ) - { + public void setDetail(Throwable detail) { this.detail = detail; } } diff --git a/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java index 775ddc48..39138299 100644 --- a/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.introspection; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.introspection; import java.util.ArrayList; import java.util.HashMap; @@ -30,258 +29,226 @@ * @author Jason van Zyl * */ -public class ReflectionValueExtractorTest - extends TestCase -{ +public class ReflectionValueExtractorTest extends TestCase { private Project project; - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); Dependency dependency1 = new Dependency(); - dependency1.setArtifactId( "dep1" ); + dependency1.setArtifactId("dep1"); Dependency dependency2 = new Dependency(); - dependency2.setArtifactId( "dep2" ); + dependency2.setArtifactId("dep2"); project = new Project(); - project.setModelVersion( "4.0.0" ); - project.setGroupId( "org.apache.maven" ); - project.setArtifactId( "maven-core" ); - project.setName( "Maven" ); - project.setVersion( "2.0-SNAPSHOT" ); - project.setScm( new Scm() ); - project.getScm().setConnection( "scm-connection" ); - project.addDependency( dependency1 ); - project.addDependency( dependency2 ); - project.setBuild( new Build() ); + project.setModelVersion("4.0.0"); + project.setGroupId("org.apache.maven"); + project.setArtifactId("maven-core"); + project.setName("Maven"); + project.setVersion("2.0-SNAPSHOT"); + project.setScm(new Scm()); + project.getScm().setConnection("scm-connection"); + project.addDependency(dependency1); + project.addDependency(dependency2); + project.setBuild(new Build()); // Build up an artifactMap - project.addArtifact( new Artifact("g0","a0","v0","e0","c0") ); - project.addArtifact( new Artifact("g1","a1","v1","e1","c1") ); - project.addArtifact( new Artifact("g2","a2","v2","e2","c2") ); + project.addArtifact(new Artifact("g0", "a0", "v0", "e0", "c0")); + project.addArtifact(new Artifact("g1", "a1", "v1", "e1", "c1")); + project.addArtifact(new Artifact("g2", "a2", "v2", "e2", "c2")); } - public void testValueExtraction() - throws Exception - { + public void testValueExtraction() throws Exception { // ---------------------------------------------------------------------- // Top level values // ---------------------------------------------------------------------- - assertEquals( "4.0.0", ReflectionValueExtractor.evaluate( "project.modelVersion", project ) ); + assertEquals("4.0.0", ReflectionValueExtractor.evaluate("project.modelVersion", project)); - assertEquals( "org.apache.maven", ReflectionValueExtractor.evaluate( "project.groupId", project ) ); + assertEquals("org.apache.maven", ReflectionValueExtractor.evaluate("project.groupId", project)); - assertEquals( "maven-core", ReflectionValueExtractor.evaluate( "project.artifactId", project ) ); + assertEquals("maven-core", ReflectionValueExtractor.evaluate("project.artifactId", project)); - assertEquals( "Maven", ReflectionValueExtractor.evaluate( "project.name", project ) ); + assertEquals("Maven", ReflectionValueExtractor.evaluate("project.name", project)); - assertEquals( "2.0-SNAPSHOT", ReflectionValueExtractor.evaluate( "project.version", project ) ); + assertEquals("2.0-SNAPSHOT", ReflectionValueExtractor.evaluate("project.version", project)); // ---------------------------------------------------------------------- // SCM // ---------------------------------------------------------------------- - assertEquals( "scm-connection", ReflectionValueExtractor.evaluate( "project.scm.connection", project ) ); + assertEquals("scm-connection", ReflectionValueExtractor.evaluate("project.scm.connection", project)); // ---------------------------------------------------------------------- // Dependencies // ---------------------------------------------------------------------- - List dependencies = (List) ReflectionValueExtractor.evaluate( "project.dependencies", project ); + List dependencies = (List) ReflectionValueExtractor.evaluate("project.dependencies", project); - assertNotNull( dependencies ); + assertNotNull(dependencies); - assertEquals( 2, dependencies.size() ); + assertEquals(2, dependencies.size()); // ---------------------------------------------------------------------- // Dependencies - using index notation // ---------------------------------------------------------------------- // List - Dependency dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependencies[0]", project ); + Dependency dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependencies[0]", project); - assertNotNull( dependency ); + assertNotNull(dependency); - assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue("dep1".equals(dependency.getArtifactId())); - String artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependencies[1].artifactId", project ); + String artifactId = (String) ReflectionValueExtractor.evaluate("project.dependencies[1].artifactId", project); - assertTrue( "dep2".equals( artifactId ) ); + assertTrue("dep2".equals(artifactId)); // Array - dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[0]", project ); + dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[0]", project); - assertNotNull( dependency ); + assertNotNull(dependency); - assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue("dep1".equals(dependency.getArtifactId())); - artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[1].artifactId", project ); + artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsArray[1].artifactId", project); - assertTrue( "dep2".equals( artifactId ) ); + assertTrue("dep2".equals(artifactId)); // Map - dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep1)", project ); + dependency = (Dependency) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep1)", project); - assertNotNull( dependency ); + assertNotNull(dependency); - assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue("dep1".equals(dependency.getArtifactId())); - artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep2).artifactId", project ); + artifactId = (String) ReflectionValueExtractor.evaluate("project.dependenciesAsMap(dep2).artifactId", project); - assertTrue( "dep2".equals( artifactId ) ); + assertTrue("dep2".equals(artifactId)); // ---------------------------------------------------------------------- // Build // ---------------------------------------------------------------------- - Build build = (Build) ReflectionValueExtractor.evaluate( "project.build", project ); + Build build = (Build) ReflectionValueExtractor.evaluate("project.build", project); - assertNotNull( build ); + assertNotNull(build); } - public void testValueExtractorWithAInvalidExpression() - throws Exception - { - assertNull( ReflectionValueExtractor.evaluate( "project.foo", project ) ); - assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[10]", project ) ); - assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[0].foo", project ) ); + public void testValueExtractorWithAInvalidExpression() throws Exception { + assertNull(ReflectionValueExtractor.evaluate("project.foo", project)); + assertNull(ReflectionValueExtractor.evaluate("project.dependencies[10]", project)); + assertNull(ReflectionValueExtractor.evaluate("project.dependencies[0].foo", project)); } - public void testMappedDottedKey() - throws Exception - { + public void testMappedDottedKey() throws Exception { Map map = new HashMap(); - map.put( "a.b", "a.b-value" ); + map.put("a.b", "a.b-value"); - assertEquals( "a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map)) ); + assertEquals("a.b-value", ReflectionValueExtractor.evaluate("h.value(a.b)", new ValueHolder(map))); } - public void testIndexedMapped() - throws Exception - { + public void testIndexedMapped() throws Exception { Map map = new HashMap(); - map.put( "a", "a-value" ); + map.put("a", "a-value"); List list = new ArrayList(); - list.add( map ); + list.add(map); - assertEquals( "a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list)) ); + assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value[0](a)", new ValueHolder(list))); } - public void testMappedIndexed() - throws Exception - { + public void testMappedIndexed() throws Exception { List list = new ArrayList(); - list.add( "a-value" ); + list.add("a-value"); Map map = new HashMap(); - map.put( "a", list ); - assertEquals( "a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map)) ); + map.put("a", list); + assertEquals("a-value", ReflectionValueExtractor.evaluate("h.value(a)[0]", new ValueHolder(map))); } - public void testMappedMissingDot() - throws Exception - { + public void testMappedMissingDot() throws Exception { Map map = new HashMap(); - map.put( "a", new ValueHolder( "a-value" ) ); - assertNull( ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map)) ); + map.put("a", new ValueHolder("a-value")); + assertNull(ReflectionValueExtractor.evaluate("h.value(a)value", new ValueHolder(map))); } - public void testIndexedMissingDot() - throws Exception - { + public void testIndexedMissingDot() throws Exception { List list = new ArrayList(); - list.add( new ValueHolder( "a-value" ) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list)) ); + list.add(new ValueHolder("a-value")); + assertNull(ReflectionValueExtractor.evaluate("h.value[0]value", new ValueHolder(list))); } - public void testDotDot() - throws Exception - { - assertNull( ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value")) ); + public void testDotDot() throws Exception { + assertNull(ReflectionValueExtractor.evaluate("h..value", new ValueHolder("value"))); } - public void testBadIndexedSyntax() - throws Exception - { + public void testBadIndexedSyntax() throws Exception { List list = new ArrayList(); - list.add( "a-value" ); - Object value = new ValueHolder( list ); - - assertNull( ReflectionValueExtractor.evaluate("h.value[", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[]", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[a]", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[0", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[0)", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value[-1]", value) ); + list.add("a-value"); + Object value = new ValueHolder(list); + + assertNull(ReflectionValueExtractor.evaluate("h.value[", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value[]", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value[a]", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value[0", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value[0)", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value[-1]", value)); } - public void testBadMappedSyntax() - throws Exception - { + public void testBadMappedSyntax() throws Exception { Map map = new HashMap(); - map.put( "a", "a-value" ); - Object value = new ValueHolder( map ); + map.put("a", "a-value"); + Object value = new ValueHolder(map); - assertNull( ReflectionValueExtractor.evaluate("h.value(", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value()", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value(a", value) ); - assertNull( ReflectionValueExtractor.evaluate("h.value(a]", value) ); + assertNull(ReflectionValueExtractor.evaluate("h.value(", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value()", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value(a", value)); + assertNull(ReflectionValueExtractor.evaluate("h.value(a]", value)); } - public void testIllegalIndexedType() - throws Exception - { - try - { + public void testIllegalIndexedType() throws Exception { + try { ReflectionValueExtractor.evaluate("h.value[1]", new ValueHolder("string")); - } - catch ( Exception e ) - { + } catch (Exception e) { // TODO assert exception message } } - public void testIllegalMappedType() - throws Exception - { - try - { + public void testIllegalMappedType() throws Exception { + try { ReflectionValueExtractor.evaluate("h.value(key)", new ValueHolder("string")); - } - catch ( Exception e ) - { + } catch (Exception e) { // TODO assert exception message } } - public void testTrimRootToken() - throws Exception - { - assertNull( ReflectionValueExtractor.evaluate("project", project, true) ); + public void testTrimRootToken() throws Exception { + assertNull(ReflectionValueExtractor.evaluate("project", project, true)); } - public void testArtifactMap() - throws Exception - { - assertEquals( "g0", ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId() ); - assertEquals( "a1", ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g1:a1:c1)", project)).getArtifactId() ); - assertEquals( "c2", ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g2:a2:c2)", project)).getClassifier() ); + public void testArtifactMap() throws Exception { + assertEquals( + "g0", + ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g0:a0:c0)", project)).getGroupId()); + assertEquals( + "a1", + ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g1:a1:c1)", project)) + .getArtifactId()); + assertEquals( + "c2", + ((Artifact) ReflectionValueExtractor.evaluate("project.artifactMap(g2:a2:c2)", project)) + .getClassifier()); } - public static class Artifact - { + public static class Artifact { private String groupId; private String artifactId; private String version; private String extension; private String classifier; - public Artifact( String groupId, String artifactId, String version, String extension, String classifier ) - { + public Artifact(String groupId, String artifactId, String version, String extension, String classifier) { this.groupId = groupId; this.artifactId = artifactId; this.version = version; @@ -289,50 +256,48 @@ public Artifact( String groupId, String artifactId, String version, String exten this.classifier = classifier; } - public String getGroupId() - { + public String getGroupId() { return groupId; } - public void setGroupId( String groupId ) - { + + public void setGroupId(String groupId) { this.groupId = groupId; } - public String getArtifactId() - { + + public String getArtifactId() { return artifactId; } - public void setArtifactId( String artifactId ) - { + + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } - public String getVersion() - { + + public String getVersion() { return version; } - public void setVersion( String version ) - { + + public void setVersion(String version) { this.version = version; } - public String getExtension() - { + + public String getExtension() { return extension; } - public void setExtension( String extension ) - { + + public void setExtension(String extension) { this.extension = extension; } - public String getClassifier() - { + + public String getClassifier() { return classifier; } - public void setClassifier( String classifier ) - { + + public void setClassifier(String classifier) { this.classifier = classifier; } } - public static class Project - { + public static class Project { private String modelVersion; private String groupId; @@ -349,187 +314,148 @@ public static class Project private String version; - private Map artifactMap = new HashMap(); + private Map artifactMap = new HashMap(); private String description; - public void setModelVersion( String modelVersion ) - { + public void setModelVersion(String modelVersion) { this.modelVersion = modelVersion; } - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { this.groupId = groupId; } - public void setScm( Scm scm ) - { + public void setScm(Scm scm) { this.scm = scm; } - public void addDependency( Dependency dependency ) - { - this.dependencies.add( dependency ); + public void addDependency(Dependency dependency) { + this.dependencies.add(dependency); } - public void setBuild( Build build ) - { + public void setBuild(Build build) { this.build = build; } - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } - public void setName( String name ) - { + public void setName(String name) { this.name = name; } - public void setVersion( String version ) - { + public void setVersion(String version) { this.version = version; } - public Scm getScm() - { + public Scm getScm() { return scm; } - public String getModelVersion() - { + public String getModelVersion() { return modelVersion; } - public String getGroupId() - { + public String getGroupId() { return groupId; } - public List getDependencies() - { + public List getDependencies() { return dependencies; } - public Build getBuild() - { + public Build getBuild() { return build; } - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } - public String getName() - { + public String getName() { return name; } - public String getVersion() - { + public String getVersion() { return version; } - public Dependency[] getDependenciesAsArray() - { + public Dependency[] getDependenciesAsArray() { List list = getDependencies(); - return list.toArray( new Dependency[list.size()] ); + return list.toArray(new Dependency[list.size()]); } - public Map getDependenciesAsMap() - { + public Map getDependenciesAsMap() { Map ret = new HashMap(); - for ( Object o : getDependencies() ) - { + for (Object o : getDependencies()) { Dependency dep = (Dependency) o; - ret.put( dep.getArtifactId(), dep ); + ret.put(dep.getArtifactId(), dep); } return ret; } - // ${project.artifactMap(g:a:v)} - public void addArtifact(Artifact a) - { - artifactMap.put( a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getClassifier(), a ); + public void addArtifact(Artifact a) { + artifactMap.put(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getClassifier(), a); } - public Map getArtifactMap() - { + public Map getArtifactMap() { return artifactMap; } - public void setDescription( String description ) - { + public void setDescription(String description) { this.description = description; } - public String getDescription() - { + public String getDescription() { return description; } } + public static class Build {} - public static class Build - { - - } - - public static class Dependency - { + public static class Dependency { private String artifactId; - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } - public void setArtifactId( String id ) - { + public void setArtifactId(String id) { artifactId = id; } } - public static class Scm - { + public static class Scm { private String connection; - public void setConnection( String connection ) - { + public void setConnection(String connection) { this.connection = connection; } - public String getConnection() - { + public String getConnection() { return connection; } } - public static class ValueHolder - { + public static class ValueHolder { private final Object value; - public ValueHolder( Object value ) - { + public ValueHolder(Object value) { this.value = value; } - public Object getValue() - { + public Object getValue() { return value; } } - public void testRootPropertyRegression() - throws Exception - { + public void testRootPropertyRegression() throws Exception { Project project = new Project(); - project.setDescription( "c:\\\\org\\apache\\test" ); - Object evalued = ReflectionValueExtractor.evaluate( "description", project ); - assertNotNull( evalued ); + project.setDescription("c:\\\\org\\apache\\test"); + Object evalued = ReflectionValueExtractor.evaluate("description", project); + assertNotNull(evalued); } } diff --git a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java index 9dffdad5..272cc65e 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/DirectoryScannerTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.io; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.io; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.testhelpers.FileTestHelper; @@ -28,308 +33,303 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; -@SuppressWarnings( "deprecation" ) -public class DirectoryScannerTest -{ +@SuppressWarnings("deprecation") +public class DirectoryScannerTest { private static final String[] NONE = new String[0]; @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); - private void createTestData() - throws IOException - { + private void createTestData() throws IOException { File rootDir = tempFolder.getRoot(); - File folder1 = new File( rootDir, "folder1" ); - if ( !folder1.mkdirs() ) - { + File folder1 = new File(rootDir, "folder1"); + if (!folder1.mkdirs()) { Assert.fail(); } - FileTestHelper.generateTestFile( new File( rootDir, "file1.txt" ), 11 ); - FileTestHelper.generateTestFile( new File( rootDir, "file2.txt" ), 12 ); - FileTestHelper.generateTestFile( new File( rootDir, "file3.dat" ), 13 ); + FileTestHelper.generateTestFile(new File(rootDir, "file1.txt"), 11); + FileTestHelper.generateTestFile(new File(rootDir, "file2.txt"), 12); + FileTestHelper.generateTestFile(new File(rootDir, "file3.dat"), 13); - FileTestHelper.generateTestFile( new File( folder1, "file4.txt" ), 14 ); - FileTestHelper.generateTestFile( new File( folder1, "file5.dat" ), 15 ); + FileTestHelper.generateTestFile(new File(folder1, "file4.txt"), 14); + FileTestHelper.generateTestFile(new File(folder1, "file5.dat"), 15); - File folder2 = new File( folder1, "ignorefolder" ); - if ( !folder2.mkdirs() ) - { + File folder2 = new File(folder1, "ignorefolder"); + if (!folder2.mkdirs()) { Assert.fail(); } - FileTestHelper.generateTestFile( new File( folder2, "file7.txt" ), 17 ); + FileTestHelper.generateTestFile(new File(folder2, "file7.txt"), 17); } @Test - public void testSimpleScan() - throws Exception - { + public void testSimpleScan() throws Exception { createTestData(); - fitScanTest( true, true, true, - /* includes */ null, - /* excludes */ null, + fitScanTest( + true, + true, + true, + /* includes */ null, + /* excludes */ null, /* expInclFiles */ - new String[]{ "file1.txt", "file2.txt", "file3.dat", "folder1/file4.txt", "folder1/file5.dat" }, - /* expInclDirs */ new String[]{ "", "folder1" }, + new String[] {"file1.txt", "file2.txt", "file3.dat", "folder1/file4.txt", "folder1/file5.dat"}, + /* expInclDirs */ new String[] {"", "folder1"}, /* expNotInclFiles */ NONE, /* expNotInclDirs */ NONE, /* expNotExclFiles */ NONE, - /* expNotExclDirs */ NONE ); + /* expNotExclDirs */ NONE); // same without followSymlinks - fitScanTest( true, false, true, - /* includes */ null, - /* excludes */ null, + fitScanTest( + true, + false, + true, + /* includes */ null, + /* excludes */ null, /* expInclFiles */ - new String[]{ "file1.txt", "file2.txt", "file3.dat", "folder1/file4.txt", "folder1/file5.dat" }, - /* expInclDirs */ new String[]{ "", "folder1" }, + new String[] {"file1.txt", "file2.txt", "file3.dat", "folder1/file4.txt", "folder1/file5.dat"}, + /* expInclDirs */ new String[] {"", "folder1"}, /* expNotInclFiles */ NONE, /* expNotInclDirs */ NONE, /* expNotExclFiles */ NONE, - /* expNotExclDirs */ NONE ); + /* expNotExclDirs */ NONE); } @Test - public void testSimpleIncludes() - throws Exception - { + public void testSimpleIncludes() throws Exception { createTestData(); - fitScanTest( true, true, true, - /* includes */ new String[]{ "**/*.dat", "*.somethingelse" }, + fitScanTest( + true, + true, + true, + /* includes */ new String[] {"**/*.dat", "*.somethingelse"}, /* excludes */ null, - /* expInclFiles */ new String[]{ "file3.dat", "folder1/file5.dat" }, + /* expInclFiles */ new String[] {"file3.dat", "folder1/file5.dat"}, /* expInclDirs */ NONE, - /* expNotInclFiles */ new String[]{ "file1.txt", "file2.txt", "folder1/file4.txt" }, - /* expNotInclDirs */ new String[]{ "", "folder1" }, + /* expNotInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"}, + /* expNotInclDirs */ new String[] {"", "folder1"}, /* expExclFiles */ NONE, - /* expExclDirs */ NONE ); + /* expExclDirs */ NONE); // same without followSymlinks - fitScanTest( true, false, true, - /* includes */ new String[]{ "**/*.dat", "*.somethingelse" }, + fitScanTest( + true, + false, + true, + /* includes */ new String[] {"**/*.dat", "*.somethingelse"}, /* excludes */ null, - /* expInclFiles */ new String[]{ "file3.dat", "folder1/file5.dat" }, + /* expInclFiles */ new String[] {"file3.dat", "folder1/file5.dat"}, /* expInclDirs */ NONE, - /* expNotInclFiles */ new String[]{ "file1.txt", "file2.txt", "folder1/file4.txt" }, - /* expNotInclDirs */ new String[]{ "", "folder1" }, + /* expNotInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"}, + /* expNotInclDirs */ new String[] {"", "folder1"}, /* expExclFiles */ NONE, - /* expExclDirs */ NONE ); + /* expExclDirs */ NONE); } @Rule public ExpectedException xcludesNPExRule = ExpectedException.none(); @Test - public void testIncludesWithNull() - throws Exception - { - testXcludesWithNull( new String[]{ null }, null, "includes" ); + public void testIncludesWithNull() throws Exception { + testXcludesWithNull(new String[] {null}, null, "includes"); } @Test - public void testExcludesWithNull() - throws Exception - { - testXcludesWithNull( null, new String[]{ null }, "excludes" ); + public void testExcludesWithNull() throws Exception { + testXcludesWithNull(null, new String[] {null}, "excludes"); } - private void testXcludesWithNull( String[] includes, String[] excludes, String listName ) - throws Exception - { + private void testXcludesWithNull(String[] includes, String[] excludes, String listName) throws Exception { createTestData(); - xcludesNPExRule.expect( NullPointerException.class ); - xcludesNPExRule.expectMessage( "If a non-null " + listName + " list is given, all elements must be non-null" ); + xcludesNPExRule.expect(NullPointerException.class); + xcludesNPExRule.expectMessage("If a non-null " + listName + " list is given, all elements must be non-null"); - fitScanTest( true, true, true, + fitScanTest( + true, + true, + true, /* includes */ includes, /* excludes */ excludes, - /* expInclFiles */ new String[]{ "file3.dat", "folder1/file5.dat" }, + /* expInclFiles */ new String[] {"file3.dat", "folder1/file5.dat"}, /* expInclDirs */ NONE, - /* expNotInclFiles */ new String[]{ "file1.txt", "file2.txt", "folder1/file4.txt" }, - /* expNotInclDirs */ new String[]{ "", "folder1" }, + /* expNotInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"}, + /* expNotInclDirs */ new String[] {"", "folder1"}, /* expExclFiles */ NONE, - /* expExclDirs */ NONE ); + /* expExclDirs */ NONE); } @Test - public void checkSymlinkBehaviour() - { + public void checkSymlinkBehaviour() { DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir( new File( "src/test/resources/symlinks/src" ) ); - ds.setFollowSymlinks( false ); + ds.setBasedir(new File("src/test/resources/symlinks/src")); + ds.setFollowSymlinks(false); ds.scan(); - + String[] includedDirectories = ds.getIncludedDirectories(); // FIXME 3 (Windows) and 5 (Linux) are both wrong. The correct answer is 4. // This method is broken in different ways on different operating systems. - assertTrue( includedDirectories.length == 3 || includedDirectories.length == 5); - + assertTrue(includedDirectories.length == 3 || includedDirectories.length == 5); + String[] files = ds.getIncludedFiles(); - assertAlwaysIncluded( Arrays.asList( files ) ); - + assertAlwaysIncluded(Arrays.asList(files)); + // FIXME getIncludedFiles is broken on Windows; correct answer is 9 - assertTrue("files.length is " + files.length, files.length == 9 || files.length == 11 ); + assertTrue("files.length is " + files.length, files.length == 9 || files.length == 11); } @Test - public void followSymlinksFalse() - throws IOException - { - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + public void followSymlinksFalse() throws IOException { + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); - File testDir = SymlinkTestSetup.createStandardSymlinkTestDir( new File( "target/test/symlinkTestCase" ) ); + File testDir = SymlinkTestSetup.createStandardSymlinkTestDir(new File("target/test/symlinkTestCase")); DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir( testDir ); - ds.setFollowSymlinks( false ); + ds.setBasedir(testDir); + ds.setFollowSymlinks(false); ds.scan(); - List included = Arrays.asList( ds.getIncludedFiles() ); - assertAlwaysIncluded( included ); - assertEquals( 9, included.size() ); - List includedDirs = Arrays.asList( ds.getIncludedDirectories() ); - assertTrue( includedDirs.contains( "" ) ); - assertTrue( includedDirs.contains( "aRegularDir" ) ); - assertTrue( includedDirs.contains( "symDir" ) ); - assertTrue( includedDirs.contains( "symLinkToDirOnTheOutside" ) ); - assertTrue( includedDirs.contains( "targetDir" ) ); - assertEquals( 5, includedDirs.size() ); + List included = Arrays.asList(ds.getIncludedFiles()); + assertAlwaysIncluded(included); + assertEquals(9, included.size()); + List includedDirs = Arrays.asList(ds.getIncludedDirectories()); + assertTrue(includedDirs.contains("")); + assertTrue(includedDirs.contains("aRegularDir")); + assertTrue(includedDirs.contains("symDir")); + assertTrue(includedDirs.contains("symLinkToDirOnTheOutside")); + assertTrue(includedDirs.contains("targetDir")); + assertEquals(5, includedDirs.size()); } - private void assertAlwaysIncluded( List included ) - { - assertTrue( included.contains( "aRegularDir" + File.separator + "aRegularFile.txt" ) ); - assertTrue( included.contains( "targetDir" + File.separator + "targetFile.txt" ) ); - assertTrue( included.contains( "fileR.txt" ) ); - assertTrue( included.contains( "fileW.txt" ) ); - assertTrue( included.contains( "fileX.txt" ) ); - assertTrue( included.contains( "symR" ) ); - assertTrue( included.contains( "symW" ) ); - assertTrue( included.contains( "symX" ) ); - assertTrue( included.contains( "symLinkToFileOnTheOutside" ) ); + private void assertAlwaysIncluded(List included) { + assertTrue(included.contains("aRegularDir" + File.separator + "aRegularFile.txt")); + assertTrue(included.contains("targetDir" + File.separator + "targetFile.txt")); + assertTrue(included.contains("fileR.txt")); + assertTrue(included.contains("fileW.txt")); + assertTrue(included.contains("fileX.txt")); + assertTrue(included.contains("symR")); + assertTrue(included.contains("symW")); + assertTrue(included.contains("symX")); + assertTrue(included.contains("symLinkToFileOnTheOutside")); } @Test - public void followSymlinks() - throws IOException - { - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + public void followSymlinks() throws IOException { + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); DirectoryScanner ds = new DirectoryScanner(); - File testDir = SymlinkTestSetup.createStandardSymlinkTestDir( new File( "target/test/symlinkTestCase" ) ); + File testDir = SymlinkTestSetup.createStandardSymlinkTestDir(new File("target/test/symlinkTestCase")); - ds.setBasedir( testDir ); - ds.setFollowSymlinks( true ); + ds.setBasedir(testDir); + ds.setFollowSymlinks(true); ds.scan(); - List included = Arrays.asList( ds.getIncludedFiles() ); - assertAlwaysIncluded( included ); - assertTrue( included.contains( "symDir/targetFile.txt" ) ); - assertTrue( included.contains( "symLinkToDirOnTheOutside/FileInDirOnTheOutside.txt" ) ); - assertEquals( 11, included.size() ); - - List includedDirs = Arrays.asList( ds.getIncludedDirectories() ); - assertTrue( includedDirs.contains( "" ) ); // w00t ! - assertTrue( includedDirs.contains( "aRegularDir" ) ); - assertTrue( includedDirs.contains( "symDir" ) ); - assertTrue( includedDirs.contains( "symLinkToDirOnTheOutside" ) ); - assertTrue( includedDirs.contains( "targetDir" ) ); - assertEquals( 5, includedDirs.size() ); + List included = Arrays.asList(ds.getIncludedFiles()); + assertAlwaysIncluded(included); + assertTrue(included.contains("symDir/targetFile.txt")); + assertTrue(included.contains("symLinkToDirOnTheOutside/FileInDirOnTheOutside.txt")); + assertEquals(11, included.size()); + + List includedDirs = Arrays.asList(ds.getIncludedDirectories()); + assertTrue(includedDirs.contains("")); // w00t ! + assertTrue(includedDirs.contains("aRegularDir")); + assertTrue(includedDirs.contains("symDir")); + assertTrue(includedDirs.contains("symLinkToDirOnTheOutside")); + assertTrue(includedDirs.contains("targetDir")); + assertEquals(5, includedDirs.size()); } /* - Creates a standard directory layout with symlinks and files. - */ + Creates a standard directory layout with symlinks and files. + */ @Test - public void testSimpleExcludes() - throws Exception - { + public void testSimpleExcludes() throws Exception { createTestData(); - fitScanTest( true, true, true, + fitScanTest( + true, + true, + true, /* includes */ null, - /* excludes */ new String[]{ "**/*.dat", "*.somethingelse" }, - /* expInclFiles */ new String[]{ "file1.txt", "file2.txt", "folder1/file4.txt" }, - /* expInclDirs */ new String[]{ "", "folder1" }, + /* excludes */ new String[] {"**/*.dat", "*.somethingelse"}, + /* expInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"}, + /* expInclDirs */ new String[] {"", "folder1"}, /* expNotInclFiles */ NONE, /* expNotInclDirs */ NONE, - /* expExclFiles */ new String[]{ "file3.dat", "folder1/file5.dat" }, - /* expExclDirs */ NONE ); + /* expExclFiles */ new String[] {"file3.dat", "folder1/file5.dat"}, + /* expExclDirs */ NONE); // same without followSymlinks - fitScanTest( true, false, true, + fitScanTest( + true, + false, + true, /* includes */ null, - /* excludes */ new String[]{ "**/*.dat", "*.somethingelse" }, - /* expInclFiles */ new String[]{ "file1.txt", "file2.txt", "folder1/file4.txt" }, - /* expInclDirs */ new String[]{ "", "folder1" }, + /* excludes */ new String[] {"**/*.dat", "*.somethingelse"}, + /* expInclFiles */ new String[] {"file1.txt", "file2.txt", "folder1/file4.txt"}, + /* expInclDirs */ new String[] {"", "folder1"}, /* expNotInclFiles */ NONE, /* expNotInclDirs */ NONE, - /* expExclFiles */ new String[]{ "file3.dat", "folder1/file5.dat" }, - /* expExclDirs */ NONE ); + /* expExclFiles */ new String[] {"file3.dat", "folder1/file5.dat"}, + /* expExclDirs */ NONE); } - public void testIsSymbolicLink() - throws IOException - { - File file = new File( "." ); + public void testIsSymbolicLink() throws IOException { + File file = new File("."); DirectoryScanner ds = new DirectoryScanner(); - ds.isSymbolicLink( file, "abc" ); + ds.isSymbolicLink(file, "abc"); } /** * Performs a scan and test for the given parameters if not null. */ - private void fitScanTest( boolean caseSensitive, boolean followSymLinks, boolean addDefaultExcludes, - String[] includes, String[] excludes, String[] expectedIncludedFiles, - String[] expectedIncludedDirectories, String[] expectedNotIncludedFiles, - String[] expectedNotIncludedDirectories, String[] expectedExcludedFiles, - String[] expectedExcludedDirectories ) - { + private void fitScanTest( + boolean caseSensitive, + boolean followSymLinks, + boolean addDefaultExcludes, + String[] includes, + String[] excludes, + String[] expectedIncludedFiles, + String[] expectedIncludedDirectories, + String[] expectedNotIncludedFiles, + String[] expectedNotIncludedDirectories, + String[] expectedExcludedFiles, + String[] expectedExcludedDirectories) { DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir( tempFolder.getRoot() ); + ds.setBasedir(tempFolder.getRoot()); - ds.setCaseSensitive( caseSensitive ); - ds.setFollowSymlinks( followSymLinks ); + ds.setCaseSensitive(caseSensitive); + ds.setFollowSymlinks(followSymLinks); - if ( addDefaultExcludes ) - { + if (addDefaultExcludes) { ds.addDefaultExcludes(); } - if ( includes != null ) - { - ds.setIncludes( includes ); + if (includes != null) { + ds.setIncludes(includes); } - if ( excludes != null ) - { - ds.setExcludes( excludes ); + if (excludes != null) { + ds.setExcludes(excludes); } TestScanConductor scanConductor = new TestScanConductor(); - ds.setScanConductor( scanConductor ); + ds.setScanConductor(scanConductor); ds.scan(); - checkFiles( "expectedIncludedFiles", expectedIncludedFiles, ds.getIncludedFiles() ); - checkFiles( "expectedIncludedDirectories", expectedIncludedDirectories, ds.getIncludedDirectories() ); - checkFiles( "expectedNotIncludedFiles", expectedNotIncludedFiles, ds.getNotIncludedFiles() ); - checkFiles( "expectedNotIncludedDirectories", expectedNotIncludedDirectories, ds.getNotIncludedDirectories() ); - checkFiles( "expectedExcludedFiles", expectedExcludedFiles, ds.getExcludedFiles() ); - checkFiles( "expectedExcludedDirectories", expectedExcludedDirectories, ds.getExcludedDirectories() ); - - checkFiles( "visitedFiles", expectedIncludedFiles, - scanConductor.visitedFiles.toArray( new String[scanConductor.visitedFiles.size()] ) ); + checkFiles("expectedIncludedFiles", expectedIncludedFiles, ds.getIncludedFiles()); + checkFiles("expectedIncludedDirectories", expectedIncludedDirectories, ds.getIncludedDirectories()); + checkFiles("expectedNotIncludedFiles", expectedNotIncludedFiles, ds.getNotIncludedFiles()); + checkFiles("expectedNotIncludedDirectories", expectedNotIncludedDirectories, ds.getNotIncludedDirectories()); + checkFiles("expectedExcludedFiles", expectedExcludedFiles, ds.getExcludedFiles()); + checkFiles("expectedExcludedDirectories", expectedExcludedDirectories, ds.getExcludedDirectories()); + + checkFiles( + "visitedFiles", + expectedIncludedFiles, + scanConductor.visitedFiles.toArray(new String[scanConductor.visitedFiles.size()])); } /** @@ -338,72 +338,60 @@ private void fitScanTest( boolean caseSensitive, boolean followSymLinks, boolean * @param expectedFiles * @param resolvedFiles */ - private void checkFiles( String category, String[] expectedFiles, String[] resolvedFiles ) - { - if ( expectedFiles != null ) - { - String msg = category + " expected: " + Arrays.toString( expectedFiles ) + " but got: " + Arrays.toString( - resolvedFiles ); - Assert.assertNotNull( msg, resolvedFiles ); - assertEquals( msg, expectedFiles.length, resolvedFiles.length ); - - Arrays.sort( expectedFiles ); - Arrays.sort( resolvedFiles ); - - for ( int i = 0; i < resolvedFiles.length; i++ ) - { - assertEquals( msg, expectedFiles[i], resolvedFiles[i].replace( "\\", "/" ) ); + private void checkFiles(String category, String[] expectedFiles, String[] resolvedFiles) { + if (expectedFiles != null) { + String msg = category + " expected: " + Arrays.toString(expectedFiles) + " but got: " + + Arrays.toString(resolvedFiles); + Assert.assertNotNull(msg, resolvedFiles); + assertEquals(msg, expectedFiles.length, resolvedFiles.length); + + Arrays.sort(expectedFiles); + Arrays.sort(resolvedFiles); + + for (int i = 0; i < resolvedFiles.length; i++) { + assertEquals(msg, expectedFiles[i], resolvedFiles[i].replace("\\", "/")); } } } - private static class TestScanConductor - implements ScanConductor - { + private static class TestScanConductor implements ScanConductor { final List visitedFiles = new ArrayList(); - public ScanConductor.ScanAction visitDirectory( String name, File directory ) - { - assertTrue( directory.isDirectory() ); + public ScanConductor.ScanAction visitDirectory(String name, File directory) { + assertTrue(directory.isDirectory()); - if ( directory.getName().equals( "ignorefolder" ) ) - { + if (directory.getName().equals("ignorefolder")) { return ScanAction.NO_RECURSE; } return ScanAction.CONTINUE; } - public ScanConductor.ScanAction visitFile( String name, File file ) - { - assertTrue( file.isFile() ); - visitedFiles.add( name ); + public ScanConductor.ScanAction visitFile(String name, File file) { + assertTrue(file.isFile()); + visitedFiles.add(name); return ScanAction.CONTINUE; } } - private void removeAndAddSomeFiles() - throws IOException - { + private void removeAndAddSomeFiles() throws IOException { File rootDir = tempFolder.getRoot(); - File file2 = new File( rootDir, "file2.txt" ); + File file2 = new File(rootDir, "file2.txt"); file2.delete(); - FileTestHelper.generateTestFile( new File( rootDir, "folder1/file9.txt" ), 15 ); + FileTestHelper.generateTestFile(new File(rootDir, "folder1/file9.txt"), 15); - File folder2 = new File( rootDir, "folder1/ignorefolder" ); - FileUtils.deleteDirectory( folder2 ); + File folder2 = new File(rootDir, "folder1/ignorefolder"); + FileUtils.deleteDirectory(folder2); } @Test - public void testScanDiff() - throws Exception - { + public void testScanDiff() throws Exception { createTestData(); DirectoryScanner dss = new DirectoryScanner(); - dss.setBasedir( tempFolder.getRoot() ); - Assert.assertNotNull( dss ); + dss.setBasedir(tempFolder.getRoot()); + Assert.assertNotNull(dss); // we take the initial snapshot dss.scan(); @@ -414,54 +402,49 @@ public void testScanDiff() dss.scan(); - DirectoryScanResult dsr = dss.diffIncludedFiles( oldFiles ); + DirectoryScanResult dsr = dss.diffIncludedFiles(oldFiles); String[] addedFiles = dsr.getFilesAdded(); String[] removedFiles = dsr.getFilesRemoved(); - Assert.assertNotNull( addedFiles ); - Assert.assertNotNull( removedFiles ); - assertEquals( 1, addedFiles.length ); - assertEquals( 2, removedFiles.length ); + Assert.assertNotNull(addedFiles); + Assert.assertNotNull(removedFiles); + assertEquals(1, addedFiles.length); + assertEquals(2, removedFiles.length); } - @Ignore( "Enable this test to run performance checks" ) + @Ignore("Enable this test to run performance checks") @Test - public void performanceTest() - throws Exception - { + public void performanceTest() throws Exception { File rootFolder = tempFolder.getRoot(); // do some warmup - for ( int i = 1; i < 200; i++ ) - { + for (int i = 1; i < 200; i++) { createTestData(); removeAndAddSomeFiles(); - FileUtils.deleteDirectory( rootFolder ); + FileUtils.deleteDirectory(rootFolder); } int cycles = 2000; // and now we take the time _without_ long startTime = System.nanoTime(); - for ( int i = 1; i < cycles; i++ ) - { + for (int i = 1; i < cycles; i++) { createTestData(); removeAndAddSomeFiles(); - FileUtils.deleteDirectory( rootFolder ); + FileUtils.deleteDirectory(rootFolder); rootFolder.mkdir(); } long endTime = System.nanoTime(); long durationEmptyRun = endTime - startTime; - System.out.println( "durationEmptyRun [ns]: " + durationEmptyRun ); + System.out.println("durationEmptyRun [ns]: " + durationEmptyRun); startTime = System.nanoTime(); - for ( int i = 1; i < cycles; i++ ) - { + for (int i = 1; i < cycles; i++) { createTestData(); DirectoryScanner directoryScanner = new DirectoryScanner(); - directoryScanner.setBasedir( rootFolder ); + directoryScanner.setBasedir(rootFolder); directoryScanner.scan(); String[] oldFiles = directoryScanner.getIncludedFiles(); @@ -469,20 +452,19 @@ public void performanceTest() directoryScanner.scan(); - DirectoryScanResult directoryScanResult = directoryScanner.diffIncludedFiles( oldFiles ); - Assert.assertNotNull( directoryScanResult ); + DirectoryScanResult directoryScanResult = directoryScanner.diffIncludedFiles(oldFiles); + Assert.assertNotNull(directoryScanResult); - FileUtils.deleteDirectory( rootFolder ); + FileUtils.deleteDirectory(rootFolder); rootFolder.mkdir(); } endTime = System.nanoTime(); long durationWithSnapshotScanner = endTime - startTime; - System.out.println( "durationWithSnapshotScanner [ns]: " + durationWithSnapshotScanner ); + System.out.println("durationWithSnapshotScanner [ns]: " + durationWithSnapshotScanner); long dirScannerOverhead = durationWithSnapshotScanner - durationEmptyRun; - System.out.println( "Overhead for n cycles [ns]: " + dirScannerOverhead ); + System.out.println("Overhead for n cycles [ns]: " + dirScannerOverhead); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java index 51cfb177..efd49a92 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java @@ -1,30 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.maven.shared.utils.io; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeThat; - -import org.apache.commons.io.IOUtils; -import org.apache.maven.shared.utils.Os; -import org.apache.maven.shared.utils.testhelpers.FileTestHelper; -import org.codehaus.plexus.util.InterpolationFilterReader; -import org.hamcrest.CoreMatchers; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.rules.TestName; - import javax.annotation.Nonnull; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -46,24 +41,29 @@ import java.util.Map; import java.util.concurrent.TimeUnit; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ +import org.apache.commons.io.IOUtils; +import org.apache.maven.shared.utils.Os; +import org.apache.maven.shared.utils.testhelpers.FileTestHelper; +import org.codehaus.plexus.util.InterpolationFilterReader; +import org.hamcrest.CoreMatchers; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.rules.TestName; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeFalse; +import static org.junit.Assume.assumeThat; /** * This is used to test FileUtils for correctness. @@ -75,9 +75,8 @@ * @version $Id: FileUtilsTestCase.java 1081025 2011-03-13 00:45:10Z niallp $ * @see FileUtils */ -@SuppressWarnings( "deprecation" ) -public class FileUtilsTest -{ +@SuppressWarnings("deprecation") +public class FileUtilsTest { // Test data @@ -104,266 +103,227 @@ public class FileUtilsTest * @see junit.framework.TestCase#setUp() */ @Before - public void setUp() - throws Exception - { - testFile1 = tempFolder.newFile( "file1-test.txt" ); - testFile2 = tempFolder.newFile( "file1a-test.txt" ); + public void setUp() throws Exception { + testFile1 = tempFolder.newFile("file1-test.txt"); + testFile2 = tempFolder.newFile("file1a-test.txt"); testFile1Size = (int) testFile1.length(); testFile2Size = (int) testFile2.length(); tempFolder.getRoot().mkdirs(); - createFile( testFile1, testFile1Size ); - createFile( testFile2, testFile2Size ); - FileUtils.deleteDirectory( tempFolder.getRoot() ); + createFile(testFile1, testFile1Size); + createFile(testFile2, testFile2Size); + FileUtils.deleteDirectory(tempFolder.getRoot()); tempFolder.getRoot().mkdirs(); - createFile( testFile1, testFile1Size ); - createFile( testFile2, testFile2Size ); + createFile(testFile1, testFile1Size); + createFile(testFile2, testFile2Size); } - private static void createFile( File file, long size ) - throws IOException - { - if ( !file.getParentFile().exists() ) - { - throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" ); + private static void createFile(File file, long size) throws IOException { + if (!file.getParentFile().exists()) { + throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); } - - try (OutputStream out = new BufferedOutputStream( new FileOutputStream( file ) ) ) - { - FileTestHelper.generateTestData( out, size ); + + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { + FileTestHelper.generateTestData(out, size); } } - /** * Assert that the content of a file is equal to that in a byte[]. */ - private void assertEqualContent( byte[] b0, File file ) - throws IOException - { + private void assertEqualContent(byte[] b0, File file) throws IOException { int count = 0, numRead = 0; byte[] b1 = new byte[b0.length]; - try ( InputStream is = new FileInputStream( file ) ) - { - while ( count < b0.length && numRead >= 0 ) - { - numRead = is.read( b1, count, b0.length ); + try (InputStream is = new FileInputStream(file)) { + while (count < b0.length && numRead >= 0) { + numRead = is.read(b1, count, b0.length); count += numRead; } - assertThat( "Different number of bytes: ", count, is( b0.length ) ); - for ( int i = 0; i < count; i++ ) - { - assertEquals( "byte " + i + " differs", b1[i], b0[i] ); + assertThat("Different number of bytes: ", count, is(b0.length)); + for (int i = 0; i < count; i++) { + assertEquals("byte " + i + " differs", b1[i], b0[i]); } } } - private void deleteFile( File file ) - { - if ( file.exists() ) - { - assertTrue( "Couldn't delete file: " + file, file.delete() ); + private void deleteFile(File file) { + if (file.exists()) { + assertTrue("Couldn't delete file: " + file, file.delete()); } } - - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- @Test - public void toFile1() - throws Exception - { - URL url = new URL( "file", null, "a/b/c/file.txt" ); - File file = FileUtils.toFile( url ); - assertThat( file.toString(), containsString( "file.txt" ) ); + public void toFile1() throws Exception { + URL url = new URL("file", null, "a/b/c/file.txt"); + File file = FileUtils.toFile(url); + assertThat(file.toString(), containsString("file.txt")); } @Test - public void toFile2() - throws Exception - { - URL url = new URL( "file", null, "a/b/c/file%20n%61me%2520.tx%74" ); - File file = FileUtils.toFile( url ); - assertThat( file.toString(), containsString( "file name%20.txt" ) ); + public void toFile2() throws Exception { + URL url = new URL("file", null, "a/b/c/file%20n%61me%2520.tx%74"); + File file = FileUtils.toFile(url); + assertThat(file.toString(), containsString("file name%20.txt")); } @Test - public void toFile3() - throws Exception - { - assertThat( FileUtils.toFile( null ), CoreMatchers.nullValue() ); - assertThat( FileUtils.toFile( new URL( "http://jakarta.apache.org" ) ), CoreMatchers.nullValue() ); + public void toFile3() throws Exception { + assertThat(FileUtils.toFile(null), CoreMatchers.nullValue()); + assertThat(FileUtils.toFile(new URL("http://jakarta.apache.org")), CoreMatchers.nullValue()); } - @Test( expected = NumberFormatException.class ) - public void toFile4() - throws Exception - { - URL url = new URL( "file", null, "a/b/c/file%%20%me.txt%" ); - File file = FileUtils.toFile( url ); - assertThat( file.toString(), containsString( "file% %me.txt%" ) ); + @Test(expected = NumberFormatException.class) + public void toFile4() throws Exception { + URL url = new URL("file", null, "a/b/c/file%%20%me.txt%"); + File file = FileUtils.toFile(url); + assertThat(file.toString(), containsString("file% %me.txt%")); } /** * IO-252 */ @Test - public void toFile5() - throws Exception - { - URL url = new URL( "file", null, "both%20are%20100%20%25%20true" ); - File file = FileUtils.toFile( url ); - assertThat( file.toString(), is( "both are 100 % true" ) ); + public void toFile5() throws Exception { + URL url = new URL("file", null, "both%20are%20100%20%25%20true"); + File file = FileUtils.toFile(url); + assertThat(file.toString(), is("both are 100 % true")); } @Test - public void toFileUtf8() - throws Exception - { - URL url = new URL( "file", null, "/home/%C3%A4%C3%B6%C3%BC%C3%9F" ); - File file = FileUtils.toFile( url ); - assertThat( file.toString(), not( containsString( "\u00E4\u00F6\u00FC\u00DF" ) ) ); + public void toFileUtf8() throws Exception { + URL url = new URL("file", null, "/home/%C3%A4%C3%B6%C3%BC%C3%9F"); + File file = FileUtils.toFile(url); + assertThat(file.toString(), not(containsString("\u00E4\u00F6\u00FC\u00DF"))); } // toURLs @Test - public void toURLs1() - throws Exception - { - File[] files = new File[]{ new File( tempFolder.getRoot(), "file1.txt" ), new File( tempFolder.getRoot(), "file2.txt" ), - new File( tempFolder.getRoot(), "test file.txt" ), }; - URL[] urls = FileUtils.toURLs( files ); + public void toURLs1() throws Exception { + File[] files = new File[] { + new File(tempFolder.getRoot(), "file1.txt"), + new File(tempFolder.getRoot(), "file2.txt"), + new File(tempFolder.getRoot(), "test file.txt"), + }; + URL[] urls = FileUtils.toURLs(files); - assertThat( urls.length, is( files.length ) ); - assertThat( urls[0].toExternalForm().startsWith( "file:" ), is( true ) ); - assertThat( urls[0].toExternalForm().contains( "file1.txt" ), is( true ) ); - assertThat( urls[1].toExternalForm().startsWith( "file:" ), is( true ) ); - assertThat( urls[1].toExternalForm(), containsString( "file2.txt" ) ); + assertThat(urls.length, is(files.length)); + assertThat(urls[0].toExternalForm().startsWith("file:"), is(true)); + assertThat(urls[0].toExternalForm().contains("file1.txt"), is(true)); + assertThat(urls[1].toExternalForm().startsWith("file:"), is(true)); + assertThat(urls[1].toExternalForm(), containsString("file2.txt")); // Test escaped char - assertThat( urls[2].toExternalForm().startsWith( "file:" ), is( true ) ); - assertThat( urls[2].toExternalForm(), containsString( "test%20file.txt" ) ); + assertThat(urls[2].toExternalForm().startsWith("file:"), is(true)); + assertThat(urls[2].toExternalForm(), containsString("test%20file.txt")); } // contentEquals @Test - public void contentEquals() - throws Exception - { + public void contentEquals() throws Exception { // Non-existent files - File file = new File( tempFolder.getRoot(), name.getMethodName() ); - File file2 = new File( tempFolder.getRoot(), name.getMethodName() + "2" ); + File file = new File(tempFolder.getRoot(), name.getMethodName()); + File file2 = new File(tempFolder.getRoot(), name.getMethodName() + "2"); // both don't exist - assertThat( FileUtils.contentEquals( file, file ), is( true ) ); - assertThat( FileUtils.contentEquals( file, file2 ), is( true ) ); - assertThat( FileUtils.contentEquals( file2, file2 ), is( true ) ); - assertThat( FileUtils.contentEquals( file2, file ), is( true ) ); + assertThat(FileUtils.contentEquals(file, file), is(true)); + assertThat(FileUtils.contentEquals(file, file2), is(true)); + assertThat(FileUtils.contentEquals(file2, file2), is(true)); + assertThat(FileUtils.contentEquals(file2, file), is(true)); // Directories - FileUtils.contentEquals( tempFolder.getRoot(), tempFolder.getRoot() ); + FileUtils.contentEquals(tempFolder.getRoot(), tempFolder.getRoot()); // Different files - File objFile1 = new File( tempFolder.getRoot(), name.getMethodName() + ".object" ); + File objFile1 = new File(tempFolder.getRoot(), name.getMethodName() + ".object"); objFile1.deleteOnExit(); - FileUtils.copyURLToFile( getClass().getResource( "/java/lang/Object.class" ), objFile1 ); + FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1); - File objFile1b = new File( tempFolder.getRoot(), name.getMethodName() + ".object2" ); + File objFile1b = new File(tempFolder.getRoot(), name.getMethodName() + ".object2"); objFile1.deleteOnExit(); - FileUtils.copyURLToFile( getClass().getResource( "/java/lang/Object.class" ), objFile1b ); + FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1b); - File objFile2 = new File( tempFolder.getRoot(), name.getMethodName() + ".collection" ); + File objFile2 = new File(tempFolder.getRoot(), name.getMethodName() + ".collection"); objFile2.deleteOnExit(); - FileUtils.copyURLToFile( getClass().getResource( "/java/util/Collection.class" ), objFile2 ); + FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2); - assertThat( FileUtils.contentEquals( objFile1, objFile2 ), is( false ) ); - assertThat( FileUtils.contentEquals( objFile1b, objFile2 ), is( false ) ); - assertThat( FileUtils.contentEquals( objFile1, objFile1b ), is( true ) ); + assertThat(FileUtils.contentEquals(objFile1, objFile2), is(false)); + assertThat(FileUtils.contentEquals(objFile1b, objFile2), is(false)); + assertThat(FileUtils.contentEquals(objFile1, objFile1b), is(true)); - assertThat( FileUtils.contentEquals( objFile1, objFile1 ), is( true ) ); - assertThat( FileUtils.contentEquals( objFile1b, objFile1b ), is( true ) ); - assertThat( FileUtils.contentEquals( objFile2, objFile2 ), is( true ) ); + assertThat(FileUtils.contentEquals(objFile1, objFile1), is(true)); + assertThat(FileUtils.contentEquals(objFile1b, objFile1b), is(true)); + assertThat(FileUtils.contentEquals(objFile2, objFile2), is(true)); // Equal files file.createNewFile(); file2.createNewFile(); - assertThat( FileUtils.contentEquals( file, file ), is( true ) ); - assertThat( FileUtils.contentEquals( file, file2 ), is( true ) ); + assertThat(FileUtils.contentEquals(file, file), is(true)); + assertThat(FileUtils.contentEquals(file, file2), is(true)); } // copyURLToFile @Test - public void copyURLToFile() - throws Exception - { + public void copyURLToFile() throws Exception { // Creates file - File file = new File( tempFolder.getRoot(), name.getMethodName() ); + File file = new File(tempFolder.getRoot(), name.getMethodName()); file.deleteOnExit(); // Loads resource String resourceName = "/java/lang/Object.class"; - FileUtils.copyURLToFile( getClass().getResource( resourceName ), file ); + FileUtils.copyURLToFile(getClass().getResource(resourceName), file); // Tests that resource was copied correctly - try ( FileInputStream fis = new FileInputStream( file ) ) - { - assertThat( "Content is not equal.", - IOUtil.contentEquals( getClass().getResourceAsStream( resourceName ), fis ), is( true ) ); + try (FileInputStream fis = new FileInputStream(file)) { + assertThat( + "Content is not equal.", + IOUtil.contentEquals(getClass().getResourceAsStream(resourceName), fis), + is(true)); } - //TODO Maybe test copy to itself like for copyFile() + // TODO Maybe test copy to itself like for copyFile() } // forceMkdir @Test - public void forceMkdir() - throws Exception - { + public void forceMkdir() throws Exception { // Tests with existing directory - FileUtils.forceMkdir( tempFolder.getRoot() ); + FileUtils.forceMkdir(tempFolder.getRoot()); // Creates test file - File testFile = new File( tempFolder.getRoot(), name.getMethodName() ); + File testFile = new File(tempFolder.getRoot(), name.getMethodName()); testFile.deleteOnExit(); testFile.createNewFile(); - assertThat( "Test file does not exist.", testFile.exists(), is( true ) ); + assertThat("Test file does not exist.", testFile.exists(), is(true)); // Tests with existing file - try - { - FileUtils.forceMkdir( testFile ); - fail( "Exception expected." ); - } - catch ( IOException ex ) - { + try { + FileUtils.forceMkdir(testFile); + fail("Exception expected."); + } catch (IOException ex) { } testFile.delete(); // Tests with non-existent directory - FileUtils.forceMkdir( testFile ); - assertThat( "Directory was not created.", testFile.exists(), is( true ) ); + FileUtils.forceMkdir(testFile); + assertThat("Directory was not created.", testFile.exists(), is(true)); } // sizeOfDirectory @Test - public void sizeOfDirectory() - throws Exception - { - File file = new File( tempFolder.getRoot(), name.getMethodName() ); + public void sizeOfDirectory() throws Exception { + File file = new File(tempFolder.getRoot(), name.getMethodName()); // Non-existent file - try - { - FileUtils.sizeOfDirectory( file ); - fail( "Exception expected." ); - } - catch ( IllegalArgumentException ex ) - { + try { + FileUtils.sizeOfDirectory(file); + fail("Exception expected."); + } catch (IllegalArgumentException ex) { } // Creates file @@ -371,643 +331,436 @@ public void sizeOfDirectory() file.deleteOnExit(); // Existing file - try - { - FileUtils.sizeOfDirectory( file ); - fail( "Exception expected." ); - } - catch ( IllegalArgumentException ex ) - { + try { + FileUtils.sizeOfDirectory(file); + fail("Exception expected."); + } catch (IllegalArgumentException ex) { } // Existing directory file.delete(); file.mkdir(); - assertThat( "Unexpected directory size", FileUtils.sizeOfDirectory( file ), is( (long) TEST_DIRECTORY_SIZE ) ); + assertThat("Unexpected directory size", FileUtils.sizeOfDirectory(file), is((long) TEST_DIRECTORY_SIZE)); } // copyFile @Test - public void copyFile1() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy1.txt" ); + public void copyFile1() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy1.txt"); - //Thread.sleep(LAST_MODIFIED_DELAY); - //This is to slow things down so we can catch if - //the lastModified date is not ok + // Thread.sleep(LAST_MODIFIED_DELAY); + // This is to slow things down so we can catch if + // the lastModified date is not ok - FileUtils.copyFile( testFile1, destination ); - assertThat( "Check Exist", destination.exists(), is( true ) ); - assertThat( "Check Full copy", destination.length(), is( testFile1Size ) ); + FileUtils.copyFile(testFile1, destination); + assertThat("Check Exist", destination.exists(), is(true)); + assertThat("Check Full copy", destination.length(), is(testFile1Size)); /* disabled: Thread.sleep doesn't work reliantly for this case assertTrue("Check last modified date preserved", testFile1.lastModified() == destination.lastModified());*/ } /** A time today, rounded down to the previous minute */ - private static long MODIFIED_TODAY = (System.currentTimeMillis() / TimeUnit.MINUTES.toMillis( 1 )) * TimeUnit.MINUTES.toMillis( 1 ); + private static long MODIFIED_TODAY = + (System.currentTimeMillis() / TimeUnit.MINUTES.toMillis(1)) * TimeUnit.MINUTES.toMillis(1); /** A time yesterday, rounded down to the previous minute */ - private static long MODIFIED_YESTERDAY = MODIFIED_TODAY - TimeUnit.DAYS.toMillis( 1 ); + private static long MODIFIED_YESTERDAY = MODIFIED_TODAY - TimeUnit.DAYS.toMillis(1); /** A time last week, rounded down to the previous minute */ - private static long MODIFIED_LAST_WEEK = MODIFIED_TODAY - TimeUnit.DAYS.toMillis( 7 ); - - @Test - public void copyFileWithNoFiltersAndNoDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello World!" - ); - File to = new File( - tempFolder.getRoot(), - "to.txt" - ); - - FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null ); - - assertTrue( - "to.txt did not exist so should have been written", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello World!" ); - } - - @Test - public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello World!" - ); - File to = new File( - tempFolder.getRoot(), - "to.txt" - ); - - from.setLastModified( 0 ); - FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null ); - - assertTrue( - "to.txt did not exist so should have been written", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello World!" ); - } - - @Test - public void copyFileWithNoFiltersAndOutdatedDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello World!" - ); - File to = write( - "to.txt", - MODIFIED_LAST_WEEK, - "Older content" - ); - - FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null ); - - assertTrue( - "to.txt was outdated so should have been overwritten", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello World!" ); - } - - @Test - public void copyFileWithNoFiltersAndNewerDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_LAST_WEEK, - "Hello World!" - ); - File to = write( - "to.txt", - MODIFIED_YESTERDAY, - "Older content" - ); - - FileUtils.copyFile( from, to, null, (FileUtils.FilterWrapper[]) null ); - - assertTrue( - "to.txt was newer so should have been left alone", - to.lastModified() < MODIFIED_TODAY - ); - assertFileContent( to, "Older content" ); - } - - @Test - public void copyFileWithNoFiltersAndNewerDestinationButForcedOverwrite() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_LAST_WEEK, - "Hello World!" - ); - File to = write( - "to.txt", - MODIFIED_YESTERDAY, - "Older content" - ); - - FileUtils.copyFile( from, to, null, null, true ); - - assertTrue( - "to.txt was newer but the overwrite should have been forced", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello World!" ); - } - - @Test - public void copyFileWithFilteringButNoFilters() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello ${name}!" - ); - File to = write( - "to.txt", - MODIFIED_LAST_WEEK, - "Older content" - ); - - FileUtils.copyFile( from, to, null ); - - assertTrue( - "to.txt was outdated so should have been overwritten", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello ${name}!" ); - } - - @Test - public void copyFileWithFilteringAndNoDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello ${name}!" - ); - File to = new File( - tempFolder.getRoot(), - "to.txt" - ); - - FileUtils.copyFile( from, to, null, wrappers( "name", "Bob" ) ); - - assertTrue( - "to.txt did not exist so should have been written", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello Bob!" ); - } - - @Test - public void copyFileWithFilteringAndOutdatedDestination() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_YESTERDAY, - "Hello ${name}!" - ); - File to = write( - "to.txt", - MODIFIED_LAST_WEEK, - "Older content" - ); - - FileUtils.copyFile( from, to, null, wrappers( "name", "Bob" ) ); - - assertTrue( - "to.txt was outdated so should have been overwritten", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello Bob!" ); - } - - @Test - public void copyFileWithFilteringAndNewerDestinationButForcedOverwrite() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_LAST_WEEK, - "Hello ${name}!" - ); - File to = write( - "to.txt", - MODIFIED_YESTERDAY, - "Older content" - ); - - FileUtils.copyFile( from, to, null, wrappers( "name", "Bob" ), true ); - - assertTrue( - "to.txt was newer but the overwrite should have been forced", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello Bob!" ); - } - - @Test - public void copyFileWithFilteringAndNewerDestinationButModifiedContent() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_LAST_WEEK, - "Hello ${name}!" - ); - File to = write( - "to.txt", - MODIFIED_YESTERDAY, - "Hello Charlie!" - ); - - FileUtils.copyFile( from, to, null, wrappers( "name", "Bob" ) ); - - assertTrue( - "to.txt was outdated so should have been overwritten", - to.lastModified() >= MODIFIED_TODAY - ); - assertFileContent( to, "Hello Bob!" ); - } - - @Test - public void copyFileWithFilteringAndNewerDestinationAndMatchingContent() - throws Exception - { - File from = write( - "from.txt", - MODIFIED_LAST_WEEK, - "Hello ${name}!" - ); - File to = write( - "to.txt", - MODIFIED_YESTERDAY, - "Hello Bob!" - ); - - FileUtils.copyFile( from, to, null, wrappers( "name", "Bob" ) ); - - assertFileContent( to, "Hello Bob!" ); - assertTrue( - "to.txt content should be unchanged and have been left alone", - to.lastModified() < MODIFIED_TODAY - ); - } - - private static FileUtils.FilterWrapper[] wrappers( String key, String value ) - { + private static long MODIFIED_LAST_WEEK = MODIFIED_TODAY - TimeUnit.DAYS.toMillis(7); + + @Test + public void copyFileWithNoFiltersAndNoDestination() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!"); + File to = new File(tempFolder.getRoot(), "to.txt"); + + FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null); + + assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello World!"); + } + + @Test + public void copyFileWithNoFiltersAndLastModifiedDateOfZeroAndNoDestination() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!"); + File to = new File(tempFolder.getRoot(), "to.txt"); + + from.setLastModified(0); + FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null); + + assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello World!"); + } + + @Test + public void copyFileWithNoFiltersAndOutdatedDestination() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello World!"); + File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content"); + + FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null); + + assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello World!"); + } + + @Test + public void copyFileWithNoFiltersAndNewerDestination() throws Exception { + File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello World!"); + File to = write("to.txt", MODIFIED_YESTERDAY, "Older content"); + + FileUtils.copyFile(from, to, null, (FileUtils.FilterWrapper[]) null); + + assertTrue("to.txt was newer so should have been left alone", to.lastModified() < MODIFIED_TODAY); + assertFileContent(to, "Older content"); + } + + @Test + public void copyFileWithNoFiltersAndNewerDestinationButForcedOverwrite() throws Exception { + File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello World!"); + File to = write("to.txt", MODIFIED_YESTERDAY, "Older content"); + + FileUtils.copyFile(from, to, null, null, true); + + assertTrue("to.txt was newer but the overwrite should have been forced", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello World!"); + } + + @Test + public void copyFileWithFilteringButNoFilters() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!"); + File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content"); + + FileUtils.copyFile(from, to, null); + + assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello ${name}!"); + } + + @Test + public void copyFileWithFilteringAndNoDestination() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!"); + File to = new File(tempFolder.getRoot(), "to.txt"); + + FileUtils.copyFile(from, to, null, wrappers("name", "Bob")); + + assertTrue("to.txt did not exist so should have been written", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello Bob!"); + } + + @Test + public void copyFileWithFilteringAndOutdatedDestination() throws Exception { + File from = write("from.txt", MODIFIED_YESTERDAY, "Hello ${name}!"); + File to = write("to.txt", MODIFIED_LAST_WEEK, "Older content"); + + FileUtils.copyFile(from, to, null, wrappers("name", "Bob")); + + assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello Bob!"); + } + + @Test + public void copyFileWithFilteringAndNewerDestinationButForcedOverwrite() throws Exception { + File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!"); + File to = write("to.txt", MODIFIED_YESTERDAY, "Older content"); + + FileUtils.copyFile(from, to, null, wrappers("name", "Bob"), true); + + assertTrue("to.txt was newer but the overwrite should have been forced", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello Bob!"); + } + + @Test + public void copyFileWithFilteringAndNewerDestinationButModifiedContent() throws Exception { + File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!"); + File to = write("to.txt", MODIFIED_YESTERDAY, "Hello Charlie!"); + + FileUtils.copyFile(from, to, null, wrappers("name", "Bob")); + + assertTrue("to.txt was outdated so should have been overwritten", to.lastModified() >= MODIFIED_TODAY); + assertFileContent(to, "Hello Bob!"); + } + + @Test + public void copyFileWithFilteringAndNewerDestinationAndMatchingContent() throws Exception { + File from = write("from.txt", MODIFIED_LAST_WEEK, "Hello ${name}!"); + File to = write("to.txt", MODIFIED_YESTERDAY, "Hello Bob!"); + + FileUtils.copyFile(from, to, null, wrappers("name", "Bob")); + + assertFileContent(to, "Hello Bob!"); + assertTrue("to.txt content should be unchanged and have been left alone", to.lastModified() < MODIFIED_TODAY); + } + + private static FileUtils.FilterWrapper[] wrappers(String key, String value) { final Map map = new HashMap<>(); - map.put( key, value ); - return new FileUtils.FilterWrapper[] - { - new FileUtils.FilterWrapper() - { - @Override - public Reader getReader( Reader reader ) - { - return new InterpolationFilterReader( reader, map ); - } + map.put(key, value); + return new FileUtils.FilterWrapper[] { + new FileUtils.FilterWrapper() { + @Override + public Reader getReader(Reader reader) { + return new InterpolationFilterReader(reader, map); } - }; + } + }; } - private File write( @Nonnull String name, long lastModified, @Nonnull String text ) throws IOException - { - final File file = new File( tempFolder.getRoot(), name ); - try ( final Writer writer = new FileWriter( file ) ) { + private File write(@Nonnull String name, long lastModified, @Nonnull String text) throws IOException { + final File file = new File(tempFolder.getRoot(), name); + try (final Writer writer = new FileWriter(file)) { writer.write(text); } - assertTrue( file.setLastModified( lastModified ) ); - assertEquals( "Failed to set lastModified date on " + file.getPath(), lastModified, file.lastModified() ); + assertTrue(file.setLastModified(lastModified)); + assertEquals("Failed to set lastModified date on " + file.getPath(), lastModified, file.lastModified()); return file; } - private static void assertFileContent( @Nonnull File file, @Nonnull String expected ) throws IOException - { - try ( Reader in = new FileReader( file )) - { - assertEquals( - "Expected " + file.getPath() + " to contain: " + expected, - expected, - IOUtils.toString( in ) - ); + private static void assertFileContent(@Nonnull File file, @Nonnull String expected) throws IOException { + try (Reader in = new FileReader(file)) { + assertEquals("Expected " + file.getPath() + " to contain: " + expected, expected, IOUtils.toString(in)); } } @Test - public void copyFileThatIsSymlink() - throws Exception - { - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + public void copyFileThatIsSymlink() throws Exception { + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); - File destination = new File( tempFolder.getRoot(), "symCopy.txt" ); + File destination = new File(tempFolder.getRoot(), "symCopy.txt"); - File testDir = SymlinkTestSetup.createStandardSymlinkTestDir( new File( "target/test/symlinkCopy" ) ); + File testDir = SymlinkTestSetup.createStandardSymlinkTestDir(new File("target/test/symlinkCopy")); - FileUtils.copyFile( new File( testDir, "symR" ), destination ); + FileUtils.copyFile(new File(testDir, "symR"), destination); - assertTrue( Files.isSymbolicLink( destination.toPath() ) ); + assertTrue(Files.isSymbolicLink(destination.toPath())); } - @Test - public void deleteFile() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy1.txt" ); - FileUtils.copyFile( testFile1, destination ); - FileUtils.delete( destination ); - assertThat( "Check Exist", destination.exists(), is( false ) ); + public void deleteFile() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy1.txt"); + FileUtils.copyFile(testFile1, destination); + FileUtils.delete(destination); + assertThat("Check Exist", destination.exists(), is(false)); } - @Test( expected = IOException.class ) - public void deleteFileNofile() - throws Exception - { - File destination = new File( "abc/cde" ); - FileUtils.delete( destination ); + @Test(expected = IOException.class) + public void deleteFileNofile() throws Exception { + File destination = new File("abc/cde"); + FileUtils.delete(destination); } @Test - public void deleteFileLegacy() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy1.txt" ); - FileUtils.copyFile( testFile1, destination ); - assertTrue( FileUtils.deleteLegacyStyle( destination ) ); + public void deleteFileLegacy() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy1.txt"); + FileUtils.copyFile(testFile1, destination); + assertTrue(FileUtils.deleteLegacyStyle(destination)); } @Test - public void deleteFileLegacyNofile() - throws Exception - { - File destination = new File( "abc/cde" ); - assertFalse( FileUtils.deleteLegacyStyle( destination ) ); + public void deleteFileLegacyNofile() throws Exception { + File destination = new File("abc/cde"); + assertFalse(FileUtils.deleteLegacyStyle(destination)); } @Test - public void copyFileWithPermissions() - throws Exception - { - File source = new File( "src/test/resources/executable" ); - source.setExecutable( true ); - assumeThat( "Need an existing file to copy", source.exists(), is( true ) ); - assumeThat( "Need an executable file to copy", source.canExecute(), is( true ) ); + public void copyFileWithPermissions() throws Exception { + File source = new File("src/test/resources/executable"); + source.setExecutable(true); + assumeThat("Need an existing file to copy", source.exists(), is(true)); + assumeThat("Need an executable file to copy", source.canExecute(), is(true)); - File destination = new File( tempFolder.getRoot(), "executable-copy" ); + File destination = new File(tempFolder.getRoot(), "executable-copy"); - FileUtils.copyFile( source, destination ); + FileUtils.copyFile(source, destination); - assertThat( "destination not exists: " + destination.getAbsolutePath() - + ", directory content: " + Arrays.asList( destination.getParentFile().list() ), - Files.exists( destination.toPath() ), is( true ) ); + assertThat( + "destination not exists: " + destination.getAbsolutePath() + ", directory content: " + + Arrays.asList(destination.getParentFile().list()), + Files.exists(destination.toPath()), + is(true)); - assertThat( "Check copy executable", destination.canExecute(), is( true ) ); + assertThat("Check copy executable", destination.canExecute(), is(true)); } @Test - public void copyFile2() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy2.txt" ); + public void copyFile2() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy2.txt"); - //Thread.sleep(LAST_MODIFIED_DELAY); - //This is to slow things down so we can catch if - //the lastModified date is not ok + // Thread.sleep(LAST_MODIFIED_DELAY); + // This is to slow things down so we can catch if + // the lastModified date is not ok - FileUtils.copyFile( testFile1, destination ); - assertThat( "Check Exist", destination.exists(), is( true ) ); - assertThat( "Check Full copy", destination.length(), is( testFile2Size ) ); + FileUtils.copyFile(testFile1, destination); + assertThat("Check Exist", destination.exists(), is(true)); + assertThat("Check Full copy", destination.length(), is(testFile2Size)); /* disabled: Thread.sleep doesn't work reliably for this case assertTrue("Check last modified date preserved", testFile1.lastModified() == destination.lastModified());*/ } @Test - public void copyToSelf() throws IOException - { - File destination = new File( tempFolder.getRoot(), "copy3.txt" ); - //Prepare a test file - FileUtils.copyFile( testFile1, destination ); + public void copyToSelf() throws IOException { + File destination = new File(tempFolder.getRoot(), "copy3.txt"); + // Prepare a test file + FileUtils.copyFile(testFile1, destination); - FileUtils.copyFile( destination, destination ); + FileUtils.copyFile(destination, destination); } @Test - public void copyDirectoryToNonExistingDest() - throws Exception - { - createFile( testFile1, 1234 ); - createFile( testFile2, 4321 ); + public void copyDirectoryToNonExistingDest() throws Exception { + createFile(testFile1, 1234); + createFile(testFile2, 4321); File srcDir = tempFolder.getRoot(); - File subDir = new File( srcDir, "sub" ); + File subDir = new File(srcDir, "sub"); subDir.mkdir(); - File subFile = new File( subDir, "A.txt" ); - FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" ); - File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" ); - FileUtils.deleteDirectory( destDir ); + File subFile = new File(subDir, "A.txt"); + FileUtils.fileWrite(subFile, "UTF8", "HELLO WORLD"); + File destDir = new File(System.getProperty("java.io.tmpdir"), "tmp-FileUtilsTestCase"); + FileUtils.deleteDirectory(destDir); - FileUtils.copyDirectory( srcDir, destDir ); + FileUtils.copyDirectory(srcDir, destDir); - assertTrue( destDir.exists() ); - assertEquals( FileUtils.sizeOfDirectory( destDir ), FileUtils.sizeOfDirectory( srcDir ) ); - assertTrue( new File( destDir, "sub/A.txt" ).exists() ); - FileUtils.deleteDirectory( destDir ); + assertTrue(destDir.exists()); + assertEquals(FileUtils.sizeOfDirectory(destDir), FileUtils.sizeOfDirectory(srcDir)); + assertTrue(new File(destDir, "sub/A.txt").exists()); + FileUtils.deleteDirectory(destDir); } @Test - public void copyDirectoryToExistingDest() throws IOException - { - createFile( testFile1, 1234 ); - createFile( testFile2, 4321 ); + public void copyDirectoryToExistingDest() throws IOException { + createFile(testFile1, 1234); + createFile(testFile2, 4321); File srcDir = tempFolder.getRoot(); - File subDir = new File( srcDir, "sub" ); - assertTrue( subDir.mkdir() ); - File subFile = new File( subDir, "A.txt" ); - FileUtils.fileWrite( subFile, "UTF8", "HELLO WORLD" ); - File destDir = new File( System.getProperty( "java.io.tmpdir" ), "tmp-FileUtilsTestCase" ); - FileUtils.deleteDirectory( destDir ); - assertTrue ( destDir.mkdirs() ); + File subDir = new File(srcDir, "sub"); + assertTrue(subDir.mkdir()); + File subFile = new File(subDir, "A.txt"); + FileUtils.fileWrite(subFile, "UTF8", "HELLO WORLD"); + File destDir = new File(System.getProperty("java.io.tmpdir"), "tmp-FileUtilsTestCase"); + FileUtils.deleteDirectory(destDir); + assertTrue(destDir.mkdirs()); - FileUtils.copyDirectory( srcDir, destDir ); + FileUtils.copyDirectory(srcDir, destDir); - assertEquals( FileUtils.sizeOfDirectory( destDir ), FileUtils.sizeOfDirectory( srcDir ) ); - assertTrue( new File( destDir, "sub/A.txt" ).exists() ); + assertEquals(FileUtils.sizeOfDirectory(destDir), FileUtils.sizeOfDirectory(srcDir)); + assertTrue(new File(destDir, "sub/A.txt").exists()); } @Test public void copyDirectoryErrors_nullDestination() throws IOException { - try - { - FileUtils.copyDirectory( new File( "a" ), null ); + try { + FileUtils.copyDirectory(new File("a"), null); fail(); - } - catch ( NullPointerException ex ) - { + } catch (NullPointerException ex) { } } @Test public void copyDirectoryErrors_copyToSelf() { - try - { - FileUtils.copyDirectory( tempFolder.getRoot(), tempFolder.getRoot() ); + try { + FileUtils.copyDirectory(tempFolder.getRoot(), tempFolder.getRoot()); fail(); - } - catch ( IOException ex ) - { + } catch (IOException ex) { } } @Test - public void copyDirectoryErrors() - throws IOException - { - try - { - FileUtils.copyDirectory( null, null ); + public void copyDirectoryErrors() throws IOException { + try { + FileUtils.copyDirectory(null, null); fail(); + } catch (NullPointerException ex) { } - catch ( NullPointerException ex ) - { - } - try - { - FileUtils.copyDirectory( null, new File( "a" ) ); + try { + FileUtils.copyDirectory(null, new File("a")); fail(); + } catch (NullPointerException ex) { } - catch ( NullPointerException ex ) - { - } - try - { - FileUtils.copyDirectory( tempFolder.getRoot(), testFile1 ); + try { + FileUtils.copyDirectory(tempFolder.getRoot(), testFile1); fail(); - } - catch ( IOException ex ) - { + } catch (IOException ex) { } } // forceDelete @Test - public void forceDeleteAFile1() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy1.txt" ); + public void forceDeleteAFile1() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy1.txt"); destination.createNewFile(); - assertTrue( "Copy1.txt doesn't exist to delete", destination.exists() ); - FileUtils.forceDelete( destination ); - assertFalse( destination.exists() ); + assertTrue("Copy1.txt doesn't exist to delete", destination.exists()); + FileUtils.forceDelete(destination); + assertFalse(destination.exists()); } @Test - public void forceDeleteAFile2() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "copy2.txt" ); + public void forceDeleteAFile2() throws Exception { + File destination = new File(tempFolder.getRoot(), "copy2.txt"); destination.createNewFile(); - assertThat( "Copy2.txt doesn't exist to delete", destination.exists(), is( true ) ); - FileUtils.forceDelete( destination ); - assertThat( "Check No Exist", !destination.exists(), is( true ) ); - } - - @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void forceDeleteAFile3() - throws Exception - { - File destination = new File( tempFolder.getRoot(), "no_such_file" ); - assertThat( "Check No Exist", !destination.exists(), is( true ) ); - try - { - FileUtils.forceDelete( destination ); - fail( "Should generate FileNotFoundException" ); - } - catch ( FileNotFoundException ignored ) - { + assertThat("Copy2.txt doesn't exist to delete", destination.exists(), is(true)); + FileUtils.forceDelete(destination); + assertThat("Check No Exist", !destination.exists(), is(true)); + } + + @Test + @Ignore("Commons test case that is failing for plexus") + public void forceDeleteAFile3() throws Exception { + File destination = new File(tempFolder.getRoot(), "no_such_file"); + assertThat("Check No Exist", !destination.exists(), is(true)); + try { + FileUtils.forceDelete(destination); + fail("Should generate FileNotFoundException"); + } catch (FileNotFoundException ignored) { } } // copyFileToDirectory @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void copyFile1ToDir() - throws Exception - { - File directory = new File( tempFolder.getRoot(), "subdir" ); - if ( !directory.exists() ) - { + @Ignore("Commons test case that is failing for plexus") + public void copyFile1ToDir() throws Exception { + File directory = new File(tempFolder.getRoot(), "subdir"); + if (!directory.exists()) { directory.mkdirs(); } - File destination = new File( directory, testFile1.getName() ); + File destination = new File(directory, testFile1.getName()); - //Thread.sleep(LAST_MODIFIED_DELAY); - //This is to slow things down so we can catch if - //the lastModified date is not ok + // Thread.sleep(LAST_MODIFIED_DELAY); + // This is to slow things down so we can catch if + // the lastModified date is not ok - FileUtils.copyFileToDirectory( testFile1, directory ); - assertThat( "Check Exist", destination.exists(), is( true ) ); - assertThat( "Check Full copy", destination.length(), is( testFile1Size ) ); + FileUtils.copyFileToDirectory(testFile1, directory); + assertThat("Check Exist", destination.exists(), is(true)); + assertThat("Check Full copy", destination.length(), is(testFile1Size)); /* disabled: Thread.sleep doesn't work reliantly for this case assertTrue("Check last modified date preserved", testFile1.lastModified() == destination.lastModified());*/ - try - { - FileUtils.copyFileToDirectory( destination, directory ); - fail( "Should not be able to copy a file into the same directory as itself" ); - } - catch ( IOException ioe ) - { - //we want that, cannot copy to the same directory as the original file + try { + FileUtils.copyFileToDirectory(destination, directory); + fail("Should not be able to copy a file into the same directory as itself"); + } catch (IOException ioe) { + // we want that, cannot copy to the same directory as the original file } } @Test - public void copyFile2ToDir() - throws Exception - { - File directory = new File( tempFolder.getRoot(), "subdir" ); - if ( !directory.exists() ) - { + public void copyFile2ToDir() throws Exception { + File directory = new File(tempFolder.getRoot(), "subdir"); + if (!directory.exists()) { directory.mkdirs(); } - File destination = new File( directory, testFile1.getName() ); + File destination = new File(directory, testFile1.getName()); - //Thread.sleep(LAST_MODIFIED_DELAY); - //This is to slow things down so we can catch if - //the lastModified date is not ok + // Thread.sleep(LAST_MODIFIED_DELAY); + // This is to slow things down so we can catch if + // the lastModified date is not ok - FileUtils.copyFileToDirectory( testFile1, directory ); - assertThat( "Check Exist", destination.exists(), is( true ) ); - assertThat( "Check Full copy", destination.length(), is( testFile2Size ) ); + FileUtils.copyFileToDirectory(testFile1, directory); + assertThat("Check Exist", destination.exists(), is(true)); + assertThat("Check Full copy", destination.length(), is(testFile2Size)); /* disabled: Thread.sleep doesn't work reliantly for this case assertTrue("Check last modified date preserved", testFile1.lastModified() == destination.lastModified());*/ @@ -1016,672 +769,559 @@ public void copyFile2ToDir() // forceDelete @Test - public void forceDeleteDir() - throws Exception - { - File testDirectory = tempFolder.newFolder( name.getMethodName() ); - FileUtils.forceDelete( testDirectory.getParentFile() ); - assertThat( "Check No Exist", !testDirectory.getParentFile().exists(), is( true ) ); + public void forceDeleteDir() throws Exception { + File testDirectory = tempFolder.newFolder(name.getMethodName()); + FileUtils.forceDelete(testDirectory.getParentFile()); + assertThat("Check No Exist", !testDirectory.getParentFile().exists(), is(true)); } /** * Test the FileUtils implementation. */ @Test - public void fileUtils() - throws Exception - { + public void fileUtils() throws Exception { // Loads file from classpath - File file1 = new File( tempFolder.getRoot(), "test.txt" ); + File file1 = new File(tempFolder.getRoot(), "test.txt"); String filename = file1.getAbsolutePath(); - //Create test file on-the-fly - try ( OutputStream out = new java.io.FileOutputStream( file1 ) ) - { - out.write( "This is a test".getBytes( "UTF-8" ) ); + // Create test file on-the-fly + try (OutputStream out = new java.io.FileOutputStream(file1)) { + out.write("This is a test".getBytes("UTF-8")); } - File file2 = new File( tempFolder.getRoot(), "test2.txt" ); + File file2 = new File(tempFolder.getRoot(), "test2.txt"); - FileUtils.fileWrite( file2, "UTF-8", filename ); - assertThat( file2.exists(), is( true ) ); - assertThat( file2.length() > 0, is( true ) ); + FileUtils.fileWrite(file2, "UTF-8", filename); + assertThat(file2.exists(), is(true)); + assertThat(file2.length() > 0, is(true)); - String file2contents = FileUtils.fileRead( file2, "UTF-8" ); - assertThat( "Second file's contents correct", filename.equals( file2contents ), is( true ) ); + String file2contents = FileUtils.fileRead(file2, "UTF-8"); + assertThat("Second file's contents correct", filename.equals(file2contents), is(true)); - assertThat( file2.delete(), is( true ) ); - - String contents = FileUtils.fileRead( new File( filename ), "UTF-8" ); - assertThat( "FileUtils.fileRead()", contents.equals( "This is a test" ), is( true ) ); + assertThat(file2.delete(), is(true)); + String contents = FileUtils.fileRead(new File(filename), "UTF-8"); + assertThat("FileUtils.fileRead()", contents.equals("This is a test"), is(true)); } @Test - public void fileReadWithDefaultEncoding() - throws Exception - { - File file = new File( tempFolder.getRoot(), "read.obj" ); - FileOutputStream out = new FileOutputStream( file ); + public void fileReadWithDefaultEncoding() throws Exception { + File file = new File(tempFolder.getRoot(), "read.obj"); + FileOutputStream out = new FileOutputStream(file); byte[] text = "Hello /u1234".getBytes(); - out.write( text ); + out.write(text); out.close(); - String data = FileUtils.fileRead( file ); - assertThat( data, is( "Hello /u1234" ) ); + String data = FileUtils.fileRead(file); + assertThat(data, is("Hello /u1234")); } @Test - public void fileReadWithEncoding() - throws Exception - { - File file = new File( tempFolder.getRoot(), "read.obj" ); - FileOutputStream out = new FileOutputStream( file ); - byte[] text = "Hello /u1234".getBytes( "UTF8" ); - out.write( text ); + public void fileReadWithEncoding() throws Exception { + File file = new File(tempFolder.getRoot(), "read.obj"); + FileOutputStream out = new FileOutputStream(file); + byte[] text = "Hello /u1234".getBytes("UTF8"); + out.write(text); out.close(); - String data = FileUtils.fileRead( file, "UTF8" ); - assertThat( data, is( "Hello /u1234" ) ); + String data = FileUtils.fileRead(file, "UTF8"); + assertThat(data, is("Hello /u1234")); } @Test - @Ignore( "Commons test case that is failing for plexus" ) - public void readLines() - throws Exception - { - File file = FileTestHelper.newFile( tempFolder, "lines.txt" ); - try - { - String[] data = new String[]{ "hello", "/u1234", "", "this is", "some text" }; - FileTestHelper.createLineBasedFile( file, data ); + @Ignore("Commons test case that is failing for plexus") + public void readLines() throws Exception { + File file = FileTestHelper.newFile(tempFolder, "lines.txt"); + try { + String[] data = new String[] {"hello", "/u1234", "", "this is", "some text"}; + FileTestHelper.createLineBasedFile(file, data); - List lines = FileUtils.loadFile( file ); - assertThat( lines, is( Arrays.asList( data ) ) ); - } - finally - { - deleteFile( file ); + List lines = FileUtils.loadFile(file); + assertThat(lines, is(Arrays.asList(data))); + } finally { + deleteFile(file); } } @Test - public void writeStringToFile1() - throws Exception - { - File file = new File( tempFolder.getRoot(), "write.txt" ); - FileUtils.fileWrite( file, "UTF8", "Hello /u1234" ); - byte[] text = "Hello /u1234".getBytes( "UTF8" ); - assertEqualContent( text, file ); + public void writeStringToFile1() throws Exception { + File file = new File(tempFolder.getRoot(), "write.txt"); + FileUtils.fileWrite(file, "UTF8", "Hello /u1234"); + byte[] text = "Hello /u1234".getBytes("UTF8"); + assertEqualContent(text, file); } @Test - public void writeStringToFile2() - throws Exception - { - File file = new File( tempFolder.getRoot(), "write.txt" ); - FileUtils.fileWrite( file, null, "Hello /u1234" ); + public void writeStringToFile2() throws Exception { + File file = new File(tempFolder.getRoot(), "write.txt"); + FileUtils.fileWrite(file, null, "Hello /u1234"); byte[] text = "Hello /u1234".getBytes(); - assertEqualContent( text, file ); + assertEqualContent(text, file); } @Test - public void writeCharSequence1() - throws Exception - { - File file = new File( tempFolder.getRoot(), "write.txt" ); - FileUtils.fileWrite( file, "UTF8", "Hello /u1234" ); - byte[] text = "Hello /u1234".getBytes( "UTF8" ); - assertEqualContent( text, file ); + public void writeCharSequence1() throws Exception { + File file = new File(tempFolder.getRoot(), "write.txt"); + FileUtils.fileWrite(file, "UTF8", "Hello /u1234"); + byte[] text = "Hello /u1234".getBytes("UTF8"); + assertEqualContent(text, file); } @Test - public void writeCharSequence2() - throws Exception - { - File file = new File( tempFolder.getRoot(), "write.txt" ); - FileUtils.fileWrite( file, null, "Hello /u1234" ); + public void writeCharSequence2() throws Exception { + File file = new File(tempFolder.getRoot(), "write.txt"); + FileUtils.fileWrite(file, null, "Hello /u1234"); byte[] text = "Hello /u1234".getBytes(); - assertEqualContent( text, file ); + assertEqualContent(text, file); } - @Test - public void writeStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() - throws Exception - { - File file = FileTestHelper.newFile( tempFolder, "lines.txt" ); - FileUtils.fileWrite( file, null, "This line was there before you..." ); + public void writeStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { + File file = FileTestHelper.newFile(tempFolder, "lines.txt"); + FileUtils.fileWrite(file, null, "This line was there before you..."); - FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" ); + FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data"); String expected = "This line was there before you..." + "this is brand new data"; - String actual = FileUtils.fileRead( file ); - assertThat( actual, is( expected ) ); + String actual = FileUtils.fileRead(file); + assertThat(actual, is(expected)); } @Test - public void writeStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() - throws Exception - { - File file = FileTestHelper.newFile( tempFolder, "lines.txt" ); - FileUtils.fileWrite( file, null, "This line was there before you..." ); + public void writeStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { + File file = FileTestHelper.newFile(tempFolder, "lines.txt"); + FileUtils.fileWrite(file, null, "This line was there before you..."); - FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" ); + FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data"); String expected = "This line was there before you..." + "this is brand new data"; - String actual = FileUtils.fileRead( file ); - assertThat( actual, is( expected ) ); + String actual = FileUtils.fileRead(file); + assertThat(actual, is(expected)); } @Test - public void writeStringArrayToFile() - throws Exception - { - File file = new File( tempFolder.getRoot(), "writeArray.txt" ); - FileUtils.fileWriteArray( file, new String[]{"line1", "line2", "line3"} ); + public void writeStringArrayToFile() throws Exception { + File file = new File(tempFolder.getRoot(), "writeArray.txt"); + FileUtils.fileWriteArray(file, new String[] {"line1", "line2", "line3"}); - byte[] text = "line1\nline2\nline3".getBytes( "UTF8" ); - assertEqualContent( text, file ); + byte[] text = "line1\nline2\nline3".getBytes("UTF8"); + assertEqualContent(text, file); } @Test - public void writeStringArrayToFileWithEncoding() - throws Exception - { - File file = new File( tempFolder.getRoot(), "writeArray.txt" ); - FileUtils.fileWriteArray( file, "UTF8", new String[]{"line1", "line2", "line3"} ); + public void writeStringArrayToFileWithEncoding() throws Exception { + File file = new File(tempFolder.getRoot(), "writeArray.txt"); + FileUtils.fileWriteArray(file, "UTF8", new String[] {"line1", "line2", "line3"}); - byte[] text = "line1\nline2\nline3".getBytes( "UTF8" ); - assertEqualContent( text, file ); + byte[] text = "line1\nline2\nline3".getBytes("UTF8"); + assertEqualContent(text, file); } - @Test - public void writeWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() - throws Exception - { - File file = FileTestHelper.newFile( tempFolder, "lines.txt" ); - FileUtils.fileWrite( file, "UTF-8", "This line was there before you..." ); + public void writeWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { + File file = FileTestHelper.newFile(tempFolder, "lines.txt"); + FileUtils.fileWrite(file, "UTF-8", "This line was there before you..."); - FileUtils.fileAppend( file.getAbsolutePath(), "UTF-8", "this is brand new data" ); + FileUtils.fileAppend(file.getAbsolutePath(), "UTF-8", "this is brand new data"); String expected = "This line was there before you..." + "this is brand new data"; - String actual = FileUtils.fileRead( file ); - assertThat( actual, is( expected ) ); + String actual = FileUtils.fileRead(file); + assertThat(actual, is(expected)); } @Test - public void write_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() - throws Exception - { - File file = FileTestHelper.newFile( tempFolder, "lines.txt" ); - FileUtils.fileWrite( file, null, "This line was there before you..." ); + public void write_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { + File file = FileTestHelper.newFile(tempFolder, "lines.txt"); + FileUtils.fileWrite(file, null, "This line was there before you..."); - FileUtils.fileAppend( file.getAbsolutePath(), "this is brand new data" ); + FileUtils.fileAppend(file.getAbsolutePath(), "this is brand new data"); String expected = "This line was there before you..." + "this is brand new data"; - String actual = FileUtils.fileRead( file ); - assertThat( actual, is( expected ) ); + String actual = FileUtils.fileRead(file); + assertThat(actual, is(expected)); } - @Test( expected = NullPointerException.class ) - public void blowUpOnNull() - throws IOException - { - FileUtils.deleteDirectory( (File) null ); + @Test(expected = NullPointerException.class) + public void blowUpOnNull() throws IOException { + FileUtils.deleteDirectory((File) null); } @Test - public void deleteQuietlyDir() - throws IOException - { - File testDirectory = new File( tempFolder.getRoot(), "testDeleteQuietlyDir" ); - File testFile = new File( testDirectory, "testDeleteQuietlyFile" ); + public void deleteQuietlyDir() throws IOException { + File testDirectory = new File(tempFolder.getRoot(), "testDeleteQuietlyDir"); + File testFile = new File(testDirectory, "testDeleteQuietlyFile"); testDirectory.mkdirs(); - createFile( testFile, 0 ); + createFile(testFile, 0); - assertThat( testDirectory.exists(), is( true ) ); - assertThat( testFile.exists(), is( true ) ); - FileUtils.deleteDirectory( testDirectory ); - assertThat( "Check No Exist", testDirectory.exists(), is( false ) ); - assertThat( "Check No Exist", testFile.exists(), is( false ) ); + assertThat(testDirectory.exists(), is(true)); + assertThat(testFile.exists(), is(true)); + FileUtils.deleteDirectory(testDirectory); + assertThat("Check No Exist", testDirectory.exists(), is(false)); + assertThat("Check No Exist", testFile.exists(), is(false)); } @Test - public void deleteQuietlyFile() - throws IOException - { - File testFile = new File( tempFolder.getRoot(), "testDeleteQuietlyFile" ); - createFile( testFile, 0 ); + public void deleteQuietlyFile() throws IOException { + File testFile = new File(tempFolder.getRoot(), "testDeleteQuietlyFile"); + createFile(testFile, 0); - assertThat( testFile.exists(), is( true ) ); - FileUtils.deleteDirectory( testFile ); - assertThat( "Check No Exist", testFile.exists(), is( false ) ); + assertThat(testFile.exists(), is(true)); + FileUtils.deleteDirectory(testFile); + assertThat("Check No Exist", testFile.exists(), is(false)); } @Test - public void deleteQuietlyNonExistent() - throws IOException - { - File testFile = new File( tempFolder.getRoot(), "testDeleteQuietlyNonExistent" ); - assertThat( testFile.exists(), is( false ) ); + public void deleteQuietlyNonExistent() throws IOException { + File testFile = new File(tempFolder.getRoot(), "testDeleteQuietlyNonExistent"); + assertThat(testFile.exists(), is(false)); - FileUtils.deleteDirectory( testFile ); + FileUtils.deleteDirectory(testFile); } - //// getDefaultExcludes @Test - public void getDefaultExcludes() - throws Exception - { - assertThat( Arrays.asList( FileUtils.getDefaultExcludes() ), hasItems( MINIMUM_DEFAULT_EXCLUDES ) ); + public void getDefaultExcludes() throws Exception { + assertThat(Arrays.asList(FileUtils.getDefaultExcludes()), hasItems(MINIMUM_DEFAULT_EXCLUDES)); } - //// getDefaultExcludesAsList @Test - public void getDefaultExcludesAsList() - throws Exception - { - assertThat( FileUtils.getDefaultExcludesAsList(), hasItems( MINIMUM_DEFAULT_EXCLUDES ) ); + public void getDefaultExcludesAsList() throws Exception { + assertThat(FileUtils.getDefaultExcludesAsList(), hasItems(MINIMUM_DEFAULT_EXCLUDES)); } - //// getDefaultExcludesAsString @Test - public void getDefaultExcludesAsString() - throws Exception - { - assertThat( new HashSet( Arrays.asList( FileUtils.getDefaultExcludesAsString().split( "," ) ) ), - hasItems( MINIMUM_DEFAULT_EXCLUDES ) ); + public void getDefaultExcludesAsString() throws Exception { + assertThat( + new HashSet( + Arrays.asList(FileUtils.getDefaultExcludesAsString().split(","))), + hasItems(MINIMUM_DEFAULT_EXCLUDES)); } - - //// dirname(String) @SuppressWarnings("ConstantConditions") - @Test( expected = NullPointerException.class ) - public void nlowUpOnDirnameNull() - throws Exception - { - FileUtils.dirname( null ); + @Test(expected = NullPointerException.class) + public void nlowUpOnDirnameNull() throws Exception { + FileUtils.dirname(null); } @Test - public void dirnameEmpty() - throws Exception - { - assertThat( FileUtils.dirname( "" ), is( "" ) ); + public void dirnameEmpty() throws Exception { + assertThat(FileUtils.dirname(""), is("")); } @Test - public void dirnameFilename() - throws Exception - { - assertThat( FileUtils.dirname( "foo.bar.txt" ), is( "" ) ); + public void dirnameFilename() throws Exception { + assertThat(FileUtils.dirname("foo.bar.txt"), is("")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void dirnameWindowsRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.dirname( "C:\\foo.bar.txt" ), is( "" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void dirnameWindowsRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.dirname("C:\\foo.bar.txt"), is("")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void dirnameWindowsNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.dirname( "C:\\test\\foo.bar.txt" ), is( "" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void dirnameWindowsNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt"), is("")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void dirnameUnixRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.dirname( "/foo.bar.txt" ), is( "" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void dirnameUnixRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.dirname("/foo.bar.txt"), is("")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void dirnameUnixNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.dirname( "/test/foo.bar.txt" ), is( "" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void dirnameUnixNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.dirname("/test/foo.bar.txt"), is("")); } @Test - public void dirnameWindowsRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.dirname( "C:\\foo.bar.txt" ), is( "C:" ) ); + public void dirnameWindowsRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.dirname("C:\\foo.bar.txt"), is("C:")); } @Test - public void dirnameWindowsNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.dirname( "C:\\test\\foo.bar.txt" ), is( "C:\\test" ) ); + public void dirnameWindowsNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.dirname("C:\\test\\foo.bar.txt"), is("C:\\test")); } @Test - public void dirnameUnixRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.dirname( "/foo.bar.txt" ), is( "" ) ); + public void dirnameUnixRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.dirname("/foo.bar.txt"), is("")); } @Test - public void dirnameUnixNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.dirname( "/test/foo.bar.txt" ), is( "/test" ) ); + public void dirnameUnixNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.dirname("/test/foo.bar.txt"), is("/test")); } //// filename(String) @SuppressWarnings("ConstantConditions") - @Test( expected = NullPointerException.class ) - public void blowUpOnFilenameNull() - throws Exception - { - FileUtils.filename( null ); + @Test(expected = NullPointerException.class) + public void blowUpOnFilenameNull() throws Exception { + FileUtils.filename(null); } @Test - public void filenameEmpty() - throws Exception - { - assertThat( FileUtils.filename( "" ), is( "" ) ); + public void filenameEmpty() throws Exception { + assertThat(FileUtils.filename(""), is("")); } @Test - public void filenameFilename() - throws Exception - { - assertThat( FileUtils.filename( "foo.bar.txt" ), is( "foo.bar.txt" ) ); + public void filenameFilename() throws Exception { + assertThat(FileUtils.filename("foo.bar.txt"), is("foo.bar.txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void filenameWindowsRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.filename( "C:\\foo.bar.txt" ), is( "C:\\foo.bar.txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void filenameWindowsRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.filename("C:\\foo.bar.txt"), is("C:\\foo.bar.txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void filenameWindowsNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.filename( "C:\\test\\foo.bar.txt" ), is( "C:\\test\\foo.bar.txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void filenameWindowsNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.filename("C:\\test\\foo.bar.txt"), is("C:\\test\\foo.bar.txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void filenameUnixRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.filename( "/foo.bar.txt" ), is( "/foo.bar.txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void filenameUnixRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.filename("/foo.bar.txt"), is("/foo.bar.txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void filenameUnixNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.filename( "/test/foo.bar.txt" ), is( "/test/foo.bar.txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void filenameUnixNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.filename("/test/foo.bar.txt"), is("/test/foo.bar.txt")); } @Test - public void filenameWindowsRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.filename( "C:\\foo.bar.txt" ), is( "foo.bar.txt" ) ); + public void filenameWindowsRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.filename("C:\\foo.bar.txt"), is("foo.bar.txt")); } @Test - public void filenameWindowsNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.filename( "C:\\test\\foo.bar.txt" ), is( "foo.bar.txt" ) ); + public void filenameWindowsNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.filename("C:\\test\\foo.bar.txt"), is("foo.bar.txt")); } @Test - public void filenameUnixRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.filename( "/foo.bar.txt" ), is( "foo.bar.txt" ) ); + public void filenameUnixRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.filename("/foo.bar.txt"), is("foo.bar.txt")); } @Test - public void filenameUnixNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.filename( "/test/foo.bar.txt" ), is( "foo.bar.txt" ) ); + public void filenameUnixNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.filename("/test/foo.bar.txt"), is("foo.bar.txt")); } //// extension(String) @SuppressWarnings("ConstantConditions") - @Test( expected = NullPointerException.class ) - public void blowUpOnNullExtension() - throws Exception - { - FileUtils.extension( null ); + @Test(expected = NullPointerException.class) + public void blowUpOnNullExtension() throws Exception { + FileUtils.extension(null); } @Test - public void extensionEmpty() - throws Exception - { - assertThat( FileUtils.extension( "" ), is( "" ) ); + public void extensionEmpty() throws Exception { + assertThat(FileUtils.extension(""), is("")); } @Test - public void extensionFileName() - throws Exception - { - assertThat( FileUtils.extension( "foo.bar.txt" ), is( "txt" ) ); + public void extensionFileName() throws Exception { + assertThat(FileUtils.extension("foo.bar.txt"), is("txt")); } @Test - public void extensionFileNameNoExtension() - throws Exception - { - assertThat( FileUtils.extension( "foo_bar_txt" ), is( "" ) ); + public void extensionFileNameNoExtension() throws Exception { + assertThat(FileUtils.extension("foo_bar_txt"), is("")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void extensionWindowsRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void extensionWindowsRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.extension("C:\\foo.bar.txt"), is("txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void extensionWindowsNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void extensionWindowsNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.extension("C:\\test\\foo.bar.txt"), is("txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void extensionUnixRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void extensionUnixRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.extension("/foo.bar.txt"), is("txt")); } @Test - //X @ReproducesPlexusBug( "assumes that the path is a local path" ) - public void extensionUnixNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) ); + // X @ReproducesPlexusBug( "assumes that the path is a local path" ) + public void extensionUnixNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.extension("/test/foo.bar.txt"), is("txt")); } @Test - public void extensionWindowsRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.extension( "C:\\foo.bar.txt" ), is( "txt" ) ); + public void extensionWindowsRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.extension("C:\\foo.bar.txt"), is("txt")); } @Test - public void extensionWindowsNonRootPathOnWindows() - throws Exception - { - assumeThat( File.separatorChar, is( '\\' ) ); - assertThat( FileUtils.extension( "C:\\test\\foo.bar.txt" ), is( "txt" ) ); + public void extensionWindowsNonRootPathOnWindows() throws Exception { + assumeThat(File.separatorChar, is('\\')); + assertThat(FileUtils.extension("C:\\test\\foo.bar.txt"), is("txt")); } @Test - @Ignore( "Wait until we can run with assembly 2.5 which will support symlinks properly" ) - public void isASymbolicLink() - throws IOException - { + @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly") + public void isASymbolicLink() throws IOException { // This testcase will pass when running under java7 or higher - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); - File file = new File( "src/test/resources/symlinks/src/symDir" ); - assertTrue( FileUtils.isSymbolicLink( file ) ); + File file = new File("src/test/resources/symlinks/src/symDir"); + assertTrue(FileUtils.isSymbolicLink(file)); } @Test - @Ignore( "Wait until we can run with assembly 2.5 which will support symlinks properly" ) - public void notASymbolicLink() - throws IOException - { - File file = new File( "src/test/resources/symlinks/src/" ); - assertFalse( FileUtils.isSymbolicLink( file ) ); + @Ignore("Wait until we can run with assembly 2.5 which will support symlinks properly") + public void notASymbolicLink() throws IOException { + File file = new File("src/test/resources/symlinks/src/"); + assertFalse(FileUtils.isSymbolicLink(file)); } @Test - public void extensionUnixRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.extension( "/foo.bar.txt" ), is( "txt" ) ); + public void extensionUnixRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.extension("/foo.bar.txt"), is("txt")); } @Test - public void extensionUnixNonRootPathOnUnix() - throws Exception - { - assumeThat( File.separatorChar, is( '/' ) ); - assertThat( FileUtils.extension( "/test/foo.bar.txt" ), is( "txt" ) ); + public void extensionUnixNonRootPathOnUnix() throws Exception { + assumeThat(File.separatorChar, is('/')); + assertThat(FileUtils.extension("/test/foo.bar.txt"), is("txt")); } @Test - public void createAndReadSymlink() - throws Exception - { - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + public void createAndReadSymlink() throws Exception { + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); - File file = new File( "target/fzz" ); - FileUtils.createSymbolicLink( file, new File("../target") ); + File file = new File("target/fzz"); + FileUtils.createSymbolicLink(file, new File("../target")); - final File file1 = Files.readSymbolicLink( file.toPath() ).toFile(); - assertEquals( "target", file1.getName() ); - Files.delete( file.toPath() ); + final File file1 = Files.readSymbolicLink(file.toPath()).toFile(); + assertEquals("target", file1.getName()); + Files.delete(file.toPath()); } @Test - public void createSymbolicLinkWithDifferentTargetOverwritesSymlink() - throws Exception - { - assumeFalse( Os.isFamily( Os.FAMILY_WINDOWS ) ); + public void createSymbolicLinkWithDifferentTargetOverwritesSymlink() throws Exception { + assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS)); // Arrange - final File symlink1 = new File( tempFolder.getRoot(), "symlink" ); + final File symlink1 = new File(tempFolder.getRoot(), "symlink"); - FileUtils.createSymbolicLink( symlink1, testFile1 ); + FileUtils.createSymbolicLink(symlink1, testFile1); // Act - final File symlink2 = FileUtils.createSymbolicLink( symlink1, testFile2 ); + final File symlink2 = FileUtils.createSymbolicLink(symlink1, testFile2); // Assert - assertThat( - Files.readSymbolicLink( symlink2.toPath() ).toFile(), - CoreMatchers.equalTo( testFile2 ) - ); + assertThat(Files.readSymbolicLink(symlink2.toPath()).toFile(), CoreMatchers.equalTo(testFile2)); } //// constants for testing private static final String[] MINIMUM_DEFAULT_EXCLUDES = { // Miscellaneous typical temporary files - "**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*", + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", // CVS - "**/CVS", "**/CVS/**", "**/.cvsignore", + "**/CVS", + "**/CVS/**", + "**/.cvsignore", // Subversion - "**/.svn", "**/.svn/**", + "**/.svn", + "**/.svn/**", // Arch - "**/.arch-ids", "**/.arch-ids/**", + "**/.arch-ids", + "**/.arch-ids/**", - //Bazaar - "**/.bzr", "**/.bzr/**", + // Bazaar + "**/.bzr", + "**/.bzr/**", - //SurroundSCM + // SurroundSCM "**/.MySCMServerInfo", // Mac "**/.DS_Store", // Serena Dimensions Version 10 - "**/.metadata", "**/.metadata/**", + "**/.metadata", + "**/.metadata/**", // Mercurial - "**/.hg", "**/.hg/**", + "**/.hg", + "**/.hg/**", // git - "**/.git", "**/.git/**", + "**/.git", + "**/.git/**", // BitKeeper - "**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet", "**/ChangeSet/**", + "**/BitKeeper", + "**/BitKeeper/**", + "**/ChangeSet", + "**/ChangeSet/**", // darcs - "**/_darcs", "**/_darcs/**", "**/.darcsrepo", "**/.darcsrepo/**", "**/-darcs-backup*", "**/.darcs-temp-mail" }; - + "**/_darcs", + "**/_darcs/**", + "**/.darcsrepo", + "**/.darcsrepo/**", + "**/-darcs-backup*", + "**/.darcs-temp-mail" + }; } diff --git a/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java b/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java index a8b6b31a..06d04d9e 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/IOUtilTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.io; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import org.junit.Test; +package org.apache.maven.shared.utils.io; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -37,2343 +34,1778 @@ import java.io.Writer; import java.util.concurrent.atomic.AtomicBoolean; +import org.junit.Test; + import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -@SuppressWarnings( "deprecation" ) -public class IOUtilTest -{ +@SuppressWarnings("deprecation") +public class IOUtilTest { private static final long INFINITE_LOOP_TIMEOUT = 500; @Test - public void closeReaderWithNull() - throws Exception - { - IOUtil.close( (Reader) null ); + public void closeReaderWithNull() throws Exception { + IOUtil.close((Reader) null); } @Test - public void closeWriterWithNull() - throws Exception - { - IOUtil.close( (Writer) null ); + public void closeWriterWithNull() throws Exception { + IOUtil.close((Writer) null); } @Test - public void closeInputStreamWithNull() - throws Exception - { - IOUtil.close( nullInputStream() ); + public void closeInputStreamWithNull() throws Exception { + IOUtil.close(nullInputStream()); } @Test - public void closeOutputStreamWithNull() - throws Exception - { - IOUtil.close( nullOutputStream() ); + public void closeOutputStreamWithNull() throws Exception { + IOUtil.close(nullOutputStream()); } @Test - public void closeReaderWithIOE() - throws Exception - { - IOUtil.close( new BufferedReader( new StringReader( emptyString() ) ) - { + public void closeReaderWithIOE() throws Exception { + IOUtil.close(new BufferedReader(new StringReader(emptyString())) { @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); - throw new IOException( "don't bomb out" ); + throw new IOException("don't bomb out"); } - } ); + }); } @Test - public void closeWriterWithIOE() - throws Exception - { - IOUtil.close( new BufferedWriter( new StringWriter() ) - { + public void closeWriterWithIOE() throws Exception { + IOUtil.close(new BufferedWriter(new StringWriter()) { @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); - throw new IOException( "don't bomb out" ); + throw new IOException("don't bomb out"); } - } ); + }); } @Test - public void closeInputStreamWithIOE() - throws Exception - { - IOUtil.close( new BufferedInputStream( emptyInputStream() ) - { + public void closeInputStreamWithIOE() throws Exception { + IOUtil.close(new BufferedInputStream(emptyInputStream()) { @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); - throw new IOException( "don't bomb out" ); + throw new IOException("don't bomb out"); } - } ); + }); } @Test - public void closeOutputStreamWithIOE() - throws Exception - { - IOUtil.close( new BufferedOutputStream( new ByteArrayOutputStream() ) - { + public void closeOutputStreamWithIOE() throws Exception { + IOUtil.close(new BufferedOutputStream(new ByteArrayOutputStream()) { @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); - throw new IOException( "don't bomb out" ); + throw new IOException("don't bomb out"); } - } ); + }); } @Test - public void closeReaderCloses() - throws Exception - { - final AtomicBoolean closed = new AtomicBoolean( false ); - IOUtil.close( new BufferedReader( new StringReader( emptyString() ) ) - { + public void closeReaderCloses() throws Exception { + final AtomicBoolean closed = new AtomicBoolean(false); + IOUtil.close(new BufferedReader(new StringReader(emptyString())) { @Override - public void close() - throws IOException - { - closed.set( true ); + public void close() throws IOException { + closed.set(true); super.close(); } - } ); - assertThat( closed.get(), is( true ) ); + }); + assertThat(closed.get(), is(true)); } @Test - public void closeWriterCloses() - throws Exception - { - final AtomicBoolean closed = new AtomicBoolean( false ); - IOUtil.close( new BufferedWriter( new StringWriter() ) - { + public void closeWriterCloses() throws Exception { + final AtomicBoolean closed = new AtomicBoolean(false); + IOUtil.close(new BufferedWriter(new StringWriter()) { @Override - public void close() - throws IOException - { - closed.set( true ); + public void close() throws IOException { + closed.set(true); super.close(); } - } ); - assertThat( closed.get(), is( true ) ); + }); + assertThat(closed.get(), is(true)); } @Test - public void closeInputStreamCloses() - throws Exception - { - final AtomicBoolean closed = new AtomicBoolean( false ); - IOUtil.close( new BufferedInputStream( emptyInputStream() ) - { + public void closeInputStreamCloses() throws Exception { + final AtomicBoolean closed = new AtomicBoolean(false); + IOUtil.close(new BufferedInputStream(emptyInputStream()) { @Override - public void close() - throws IOException - { - closed.set( true ); + public void close() throws IOException { + closed.set(true); super.close(); } - } ); - assertThat( closed.get(), is( true ) ); + }); + assertThat(closed.get(), is(true)); } @Test - public void closeOutputStreamCloses() - throws Exception - { - final AtomicBoolean closed = new AtomicBoolean( false ); - IOUtil.close( new BufferedOutputStream( new ByteArrayOutputStream() ) - { + public void closeOutputStreamCloses() throws Exception { + final AtomicBoolean closed = new AtomicBoolean(false); + IOUtil.close(new BufferedOutputStream(new ByteArrayOutputStream()) { @Override - public void close() - throws IOException - { - closed.set( true ); + public void close() throws IOException { + closed.set(true); super.close(); } - } ); - assertThat( closed.get(), is( true ) ); + }); + assertThat(closed.get(), is(true)); } @Test - public void toByteArrayFromString() - throws Exception - { + public void toByteArrayFromString() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( probe ), is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(probe), is(probe.getBytes())); } @Test - public void toByteArrayFromReader() - throws Exception - { + public void toByteArrayFromReader() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new StringReader( probe ) ), is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(new StringReader(probe)), is(probe.getBytes())); } @Test - public void toByteArrayFromInputStream() - throws Exception - { + public void toByteArrayFromInputStream() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ) ), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe))), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullString() - throws Exception - { - IOUtil.toByteArray( (String) null ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullString() throws Exception { + IOUtil.toByteArray((String) null); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullReader() - throws Exception - { - IOUtil.toByteArray( (Reader) null ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullReader() throws Exception { + IOUtil.toByteArray((Reader) null); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullInputStream() - throws Exception - { - IOUtil.toByteArray( nullInputStream() ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullInputStream() throws Exception { + IOUtil.toByteArray(nullInputStream()); } - @Test( expected = IOException.class ) - public void contentEqualNullNull() - throws Exception - { - IOUtil.contentEquals( null, null ); + @Test(expected = IOException.class) + public void contentEqualNullNull() throws Exception { + IOUtil.contentEquals(null, null); } - @Test( expected = IOException.class ) - public void contentEqualNonNullNull() - throws Exception - { - IOUtil.contentEquals( new DontCloseByteArrayInputStream( emptyByteArray() ), null ); + @Test(expected = IOException.class) + public void contentEqualNonNullNull() throws Exception { + IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null); } - @Test( expected = IOException.class ) - public void contentEqualNullNonNull() - throws Exception - { - IOUtil.contentEquals( new DontCloseByteArrayInputStream( emptyByteArray() ), null ); + @Test(expected = IOException.class) + public void contentEqualNullNonNull() throws Exception { + IOUtil.contentEquals(new DontCloseByteArrayInputStream(emptyByteArray()), null); } @Test - public void contentEqualEmptyEmpty() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( emptyByteArray() ), - new DontCloseByteArrayInputStream( emptyByteArray() ) ), is( true ) ); + public void contentEqualEmptyEmpty() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(emptyByteArray()), + new DontCloseByteArrayInputStream(emptyByteArray())), + is(true)); } @Test - public void contentEqualNonEmptyEmpty() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( new byte[1] ), - new DontCloseByteArrayInputStream( emptyByteArray() ) ), is( false ) ); + public void contentEqualNonEmptyEmpty() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(new byte[1]), + new DontCloseByteArrayInputStream(emptyByteArray())), + is(false)); } @Test - public void contentEqualEmptyNonEmpty() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( emptyByteArray() ), - new DontCloseByteArrayInputStream( new byte[1] ) ), is( false ) ); + public void contentEqualEmptyNonEmpty() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(emptyByteArray()), + new DontCloseByteArrayInputStream(new byte[1])), + is(false)); } @Test - public void contentEqualNonEmptyNonEmpty() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( new byte[1] ), - new DontCloseByteArrayInputStream( new byte[1] ) ), is( true ) ); + public void contentEqualNonEmptyNonEmpty() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(new byte[1]), new DontCloseByteArrayInputStream(new byte[1])), + is(true)); } @Test - public void contentEqualMostlySame() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( new byte[]{ 1, 2, 3, 4, 5, 6 } ), - new DontCloseByteArrayInputStream( new byte[]{ 1, 2, 3, 4, 5, 7 } ) ), - is( false ) ); + public void contentEqualMostlySame() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6}), + new DontCloseByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 7})), + is(false)); } @Test - public void contentEqualLargeSame() - throws Exception - { - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( new byte[8192] ), - new DontCloseByteArrayInputStream( new byte[8192] ) ), is( true ) ); + public void contentEqualLargeSame() throws Exception { + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(new byte[8192]), + new DontCloseByteArrayInputStream(new byte[8192])), + is(true)); } @Test - public void contentEqualLargeDifferent() - throws Exception - { + public void contentEqualLargeDifferent() throws Exception { byte[] buf = new byte[8192]; buf[8191] = 1; - assertThat( IOUtil.contentEquals( new DontCloseByteArrayInputStream( new byte[8192] ), - new DontCloseByteArrayInputStream( buf ) ), is( false ) ); + assertThat( + IOUtil.contentEquals( + new DontCloseByteArrayInputStream(new byte[8192]), new DontCloseByteArrayInputStream(buf)), + is(false)); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArray() - throws Exception - { - IOUtil.toString( nullByteArray() ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArray() throws Exception { + IOUtil.toString(nullByteArray()); } @Test - public void toStringEmptyByteArray() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray() ), is( emptyString() ) ); + public void toStringEmptyByteArray() throws Exception { + assertThat(IOUtil.toString(emptyByteArray()), is(emptyString())); } @Test - public void toStringByteArray() - throws Exception - { + public void toStringByteArray() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes() ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes()).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayNegBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayNegBufSz() throws Exception { + IOUtil.toString(nullByteArray(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringEmptyByteArrayNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), -1 ), is( emptyString() ) ); + @Test(expected = NegativeArraySizeException.class) + public void toStringEmptyByteArrayNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), -1), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringByteArrayNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toStringByteArrayNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), -1 ), is( probe ) ); + assertThat(IOUtil.toString(probe.getBytes(), -1), is(probe)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullByteArrayZeroBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullByteArrayZeroBufSz() throws Exception { + IOUtil.toString(nullByteArray(), 0); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayPosBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), 1 ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayPosBufSz() throws Exception { + IOUtil.toString(nullByteArray(), 1); } @Test - public void toStringEmptyByteArrayPosBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), 1 ), is( emptyString() ) ); + public void toStringEmptyByteArrayPosBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), 1), is(emptyString())); } @Test - public void toStringByteArrayPosBufSz() - throws Exception - { + public void toStringByteArrayPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), 1 ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), 1).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayNullEncoding() - throws Exception - { - IOUtil.toString( nullByteArray(), null ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayNullEncoding() throws Exception { + IOUtil.toString(nullByteArray(), null); } - @Test( expected = NullPointerException.class ) - public void toStringEmptyByteArrayNullEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), null ), is( emptyString() ) ); + @Test(expected = NullPointerException.class) + public void toStringEmptyByteArrayNullEncoding() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), null), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void toStringByteArrayNullEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void toStringByteArrayNullEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), null ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), null).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayJunkEncoding() - throws Exception - { - IOUtil.toString( nullByteArray(), "junk" ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayJunkEncoding() throws Exception { + IOUtil.toString(nullByteArray(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringEmptyByteArrayJunkEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), "junk" ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class) + public void toStringEmptyByteArrayJunkEncoding() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), "junk"), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringByteArrayJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void toStringByteArrayJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), "junk" ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), "junk").getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayValidEncoding() - throws Exception - { - IOUtil.toString( nullByteArray(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayValidEncoding() throws Exception { + IOUtil.toString(nullByteArray(), "utf-16"); } @Test - public void toStringEmptyByteArrayValidEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), "utf-16" ), is( emptyString() ) ); + public void toStringEmptyByteArrayValidEncoding() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), "utf-16"), is(emptyString())); } @Test - public void toStringByteArrayValidEncoding() - throws Exception - { + public void toStringByteArrayValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes( "utf-16" ), "utf-16" ).getBytes( "utf-8" ), - is( probe.getBytes( "utf-8" ) ) ); + assertThat(IOUtil.toString(probe.getBytes("utf-16"), "utf-16").getBytes("utf-8"), is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayNullEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), null, -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayNullEncodingNegBufSz() throws Exception { + IOUtil.toString(nullByteArray(), null, -1); } - @Test( expected = NullPointerException.class ) - public void toStringEmptyByteArrayNullEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), null, -1 ), is( emptyString() ) ); + @Test(expected = NullPointerException.class) + public void toStringEmptyByteArrayNullEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), null, -1), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void toStringByteArrayNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void toStringByteArrayNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), null, -1 ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), null, -1).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayJunkEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayJunkEncodingNegBufSz() throws Exception { + IOUtil.toString(nullByteArray(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringEmptyByteArrayJunkEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), "junk", -1 ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class) + public void toStringEmptyByteArrayJunkEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), "junk", -1), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringByteArrayJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void toStringByteArrayJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), "junk", -1 ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), "junk", -1).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullByteArrayValidEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullByteArrayValidEncodingNegBufSz() throws Exception { + IOUtil.toString(nullByteArray(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringEmptyByteArrayValidEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), "utf-16", -1 ), is( emptyString() ) ); + @Test(expected = NegativeArraySizeException.class) + public void toStringEmptyByteArrayValidEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), "utf-16", -1), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringByteArrayValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toStringByteArrayValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes( "utf-16" ), "utf-16", -1 ).getBytes( "utf-8" ), - is( probe.getBytes( "utf-8" ) ) ); + assertThat( + IOUtil.toString(probe.getBytes("utf-16"), "utf-16", -1).getBytes("utf-8"), is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullByteArrayNullEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullByteArrayNullEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullByteArray(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringEmptyByteArrayNullEncodingZeroBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), null, 0 ), is( emptyString() ) ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringEmptyByteArrayNullEncodingZeroBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), null, 0), is(emptyString())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringByteArrayNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringByteArrayNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), null, 0 ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), null, 0).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullByteArrayJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullByteArrayJunkEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullByteArray(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringEmptyByteArrayJunkEncodingZeroBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyByteArray(), "junk", 0 ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringEmptyByteArrayJunkEncodingZeroBufSz() throws Exception { + assertThat(IOUtil.toString(emptyByteArray(), "junk", 0), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringByteArrayJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringByteArrayJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( probe.getBytes(), "junk", 0 ).getBytes(), is( probe.getBytes() ) ); + assertThat(IOUtil.toString(probe.getBytes(), "junk", 0).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullByteArrayValidEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullByteArray(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullByteArrayValidEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullByteArray(), "utf-16", 0); } /* * copy(byte[],OutputStream) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullOutputStream() - throws Exception - { - IOUtil.copy( nullByteArray(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullOutputStream() throws Exception { + IOUtil.copy(nullByteArray(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidOutputStream() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidOutputStream() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullOutputStream() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullOutputStream() throws Exception { + IOUtil.copy(emptyByteArray(), nullOutputStream()); } @Test - public void copyEmptyByteArrayValidOutputStream() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream() ); + public void copyEmptyByteArrayValidOutputStream() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream()); } @Test - public void copyByteArrayValidOutputStream() - throws Exception - { + public void copyByteArrayValidOutputStream() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream ); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(input, outputStream); + assertThat(outputStream.toByteArray(), is(input)); } /* * copy(byte[],OutputStream,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullOutputStream()); } @Test - public void copyEmptyByteArrayValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); + public void copyEmptyByteArrayValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream()); } @Test - public void copyByteArrayValidOutputStreamNegBufSz() - throws Exception - { + public void copyByteArrayValidOutputStreamNegBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(input, outputStream); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullOutputStream()); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullOutputStream()); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayValidOutputStreamZeroBufSz() - throws Exception - { + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayValidOutputStreamZeroBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(input, outputStream); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullOutputStream()); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseByteArrayOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullOutputStream()); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullOutputStream()); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseByteArrayOutputStream()); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseByteArrayOutputStream()); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayValidOutputStreamPosBufSz() - throws Exception - { + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayValidOutputStreamPosBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( input, outputStream); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(input, outputStream); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullOutputStream() - throws Exception - { - IOUtil.copy( nullInputStream(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullOutputStream() throws Exception { + IOUtil.copy(nullInputStream(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidOutputStream() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseByteArrayOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidOutputStream() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream()); } @Test - public void copyEmptyInputStreamNullOutputStream() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), nullOutputStream() ); + public void copyEmptyInputStreamNullOutputStream() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream()); } @Test - public void copyEmptyInputStreamValidOutputStream() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), new DontCloseByteArrayOutputStream() ); + public void copyEmptyInputStreamValidOutputStream() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream()); } @Test - public void copyInputStreamValidOutputStream() - throws Exception - { + public void copyInputStreamValidOutputStream() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( new DontCloseByteArrayInputStream( input ), outputStream ); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NegativeArraySizeException.class ) - public void copyNullInputStreamNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullOutputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyNullInputStreamNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyNullInputStreamValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseByteArrayOutputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyNullInputStreamValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseByteArrayOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), nullOutputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), new DontCloseByteArrayOutputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyInputStreamValidOutputStreamNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyInputStreamValidOutputStreamNegBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( new DontCloseByteArrayInputStream( input ), outputStream, -1 ); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, -1); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new ByteArrayOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 0); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), nullOutputStream(), 0 ); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), 0); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), new DontCloseByteArrayOutputStream(), 0 ); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullOutputStream(), 1 ); + + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullOutputStream(), 1); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new ByteArrayOutputStream(), 1 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new ByteArrayOutputStream(), 1); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), nullOutputStream(), 1 ); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), nullOutputStream(), 1); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( new DontCloseByteArrayInputStream( emptyByteArray() ), new DontCloseByteArrayOutputStream(), 1 ); + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(new DontCloseByteArrayInputStream(emptyByteArray()), new DontCloseByteArrayOutputStream(), 1); } - @Test( timeout = INFINITE_LOOP_TIMEOUT ) - public void copyInputStreamValidOutputStreamPosBufSz() - throws Exception - { + @Test(timeout = INFINITE_LOOP_TIMEOUT) + public void copyInputStreamValidOutputStreamPosBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); - byte[] input = { 1, 2, 3, 4, 5, 6 }; - IOUtil.copy( new DontCloseByteArrayInputStream( input ), outputStream, 1 ); - assertThat( outputStream.toByteArray(), is( input ) ); + byte[] input = {1, 2, 3, 4, 5, 6}; + IOUtil.copy(new DontCloseByteArrayInputStream(input), outputStream, 1); + assertThat(outputStream.toByteArray(), is(input)); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStream() - throws Exception - { - IOUtil.toString( nullInputStream() ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStream() throws Exception { + IOUtil.toString(nullInputStream()); } @Test - public void toStringEmptyInputStream() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream() ), is( emptyString() ) ); + public void toStringEmptyInputStream() throws Exception { + assertThat(IOUtil.toString(emptyInputStream()), is(emptyString())); } @Test - public void toStringInputStream() - throws Exception - { + public void toStringInputStream() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ) ).getBytes(), - is( probe.getBytes() ) ); + assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes())).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamNegBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamNegBufSz() throws Exception { + IOUtil.toString(nullInputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringEmptyInputStreamNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), -1 ), is( emptyString() ) ); + @Test(expected = NegativeArraySizeException.class) + public void toStringEmptyInputStreamNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), -1), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringInputStreamNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toStringInputStreamNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), -1 ), is( probe ) ); + assertThat(IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), -1), is(probe)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullInputStreamZeroBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullInputStreamZeroBufSz() throws Exception { + IOUtil.toString(nullInputStream(), 0); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamPosBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamPosBufSz() throws Exception { + IOUtil.toString(nullInputStream(), 1); } @Test - public void toStringEmptyInputStreamPosBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), 1 ), is( emptyString() ) ); + public void toStringEmptyInputStreamPosBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), 1), is(emptyString())); } @Test - public void toStringInputStreamPosBufSz() - throws Exception - { + public void toStringInputStreamPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), 1 ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), 1).getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamNullEncoding() - throws Exception - { - IOUtil.toString( nullInputStream(), null ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamNullEncoding() throws Exception { + IOUtil.toString(nullInputStream(), null); } - @Test( expected = NullPointerException.class ) - public void toStringEmptyInputStreamNullEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), null ), is( emptyString() ) ); + @Test(expected = NullPointerException.class) + public void toStringEmptyInputStreamNullEncoding() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), null), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void toStringInputStreamNullEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void toStringInputStreamNullEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), null ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null) + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamJunkEncoding() - throws Exception - { - IOUtil.toString( nullInputStream(), "junk" ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamJunkEncoding() throws Exception { + IOUtil.toString(nullInputStream(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringEmptyInputStreamJunkEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), "junk" ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class) + public void toStringEmptyInputStreamJunkEncoding() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), "junk"), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringInputStreamJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void toStringInputStreamJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), "junk" ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk") + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamValidEncoding() - throws Exception - { - IOUtil.toString( nullInputStream(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamValidEncoding() throws Exception { + IOUtil.toString(nullInputStream(), "utf-16"); } @Test - public void toStringEmptyInputStreamValidEncoding() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), "utf-16" ), is( emptyString() ) ); + public void toStringEmptyInputStreamValidEncoding() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), "utf-16"), is(emptyString())); } @Test - public void toStringInputStreamValidEncoding() - throws Exception - { + public void toStringInputStreamValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; assertThat( - IOUtil.toString( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), "utf-16" ).getBytes( "utf-8" ), - is( probe.getBytes( "utf-8" ) ) ); + IOUtil.toString(new ByteArrayInputStream(probe.getBytes("utf-16")), "utf-16") + .getBytes("utf-8"), + is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamNullEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), null, -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamNullEncodingNegBufSz() throws Exception { + IOUtil.toString(nullInputStream(), null, -1); } - @Test( expected = NullPointerException.class ) - public void toStringEmptyInputStreamNullEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), null, -1 ), is( emptyString() ) ); + @Test(expected = NullPointerException.class) + public void toStringEmptyInputStreamNullEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), null, -1), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void toStringInputStreamNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void toStringInputStreamNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), null, -1 ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, -1) + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamJunkEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamJunkEncodingNegBufSz() throws Exception { + IOUtil.toString(nullInputStream(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringEmptyInputStreamJunkEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), "junk", -1 ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class) + public void toStringEmptyInputStreamJunkEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), "junk", -1), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void toStringInputStreamJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void toStringInputStreamJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), "junk", -1 ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", -1) + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toStringNullInputStreamValidEncodingNegBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void toStringNullInputStreamValidEncodingNegBufSz() throws Exception { + IOUtil.toString(nullInputStream(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringEmptyInputStreamValidEncodingNegBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), "utf-16", -1 ), is( emptyString() ) ); + @Test(expected = NegativeArraySizeException.class) + public void toStringEmptyInputStreamValidEncodingNegBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), "utf-16", -1), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringInputStreamValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toStringInputStreamValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; assertThat( - IOUtil.toString( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), "utf-16", -1 ).getBytes( "utf-8" ), - is( probe.getBytes( "utf-8" ) ) ); + IOUtil.toString(new ByteArrayInputStream(probe.getBytes("utf-16")), "utf-16", -1) + .getBytes("utf-8"), + is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullInputStreamNullEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullInputStreamNullEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullInputStream(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringEmptyInputStreamNullEncodingZeroBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), null, 0 ), is( emptyString() ) ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringEmptyInputStreamNullEncodingZeroBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), null, 0), is(emptyString())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringInputStreamNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringInputStreamNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), null, 0 ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), null, 0) + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullInputStreamJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullInputStreamJunkEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullInputStream(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringEmptyInputStreamJunkEncodingZeroBufSz() - throws Exception - { - assertThat( IOUtil.toString( emptyInputStream(), "junk", 0 ), is( emptyString() ) ); + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringEmptyInputStreamJunkEncodingZeroBufSz() throws Exception { + assertThat(IOUtil.toString(emptyInputStream(), "junk", 0), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringInputStreamJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringInputStreamJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new ByteArrayInputStream( probe.getBytes() ), "junk", 0 ).getBytes(), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toString(new ByteArrayInputStream(probe.getBytes()), "junk", 0) + .getBytes(), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void toStringNullInputStreamValidEncodingZeroBufSz() - throws Exception - { - IOUtil.toString( nullInputStream(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void toStringNullInputStreamValidEncodingZeroBufSz() throws Exception { + IOUtil.toString(nullInputStream(), "utf-16", 0); } /* * copy(InputStream,Writer) */ - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriter() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriter() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamNullWriter() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamNullWriter() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter()); } @Test - public void copyEmptyInputStreamValidWriter() - throws Exception - { + public void copyEmptyInputStreamValidWriter() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyInputStreamNullWriter() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyInputStreamNullWriter() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter() ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter()); } @Test - public void copyInputStreamValidWriter() - throws Exception - { + public void copyInputStreamValidWriter() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } /* * copy(InputStream,Writer,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamNullWriterNegBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamValidWriterNegBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamValidWriterNegBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyInputStreamNullWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyInputStreamNullWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), -1 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyInputStreamValidWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyInputStreamValidWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullWriterZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidWriterZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamNullWriterZeroBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), 0); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterPosBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterPosBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamNullWriterPosBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), 1); } @Test - public void copyEmptyInputStreamValidWriterPosBufSz() - throws Exception - { + public void copyEmptyInputStreamValidWriterPosBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, 1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, 1); + assertThat(writer.toString(), is(emptyString())); } @Test - public void copyInputStreamValidWriterPosBufSz() - throws Exception - { + public void copyInputStreamValidWriterPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, 1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, 1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } /* * copy(InputStream,Writer,String) */ - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterNullEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterNullEncoding() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterNullEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterNullEncoding() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamNullWriterNullEncoding() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamNullWriterNullEncoding() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamValidWriterNullEncoding() - throws Exception - { - IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamValidWriterNullEncoding() throws Exception { + IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyInputStreamNullEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyInputStreamNullEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, null ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterJunkEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "junk" ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterJunkEncoding() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "junk"); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterJunkEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "junk" ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterJunkEncoding() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyInputStreamNullWriterJunkEncoding() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), "junk" ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyInputStreamNullWriterJunkEncoding() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyInputStreamValidWriterJunkEncoding() - throws Exception - { - IOUtil.copy( emptyInputStream(), new DontCloseStringWriter(), "junk" ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyInputStreamValidWriterJunkEncoding() throws Exception { + IOUtil.copy(emptyInputStream(), new DontCloseStringWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyInputStreamNullWriterJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyInputStreamNullWriterJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), "junk" ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyInputStreamValidWriterJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyInputStreamValidWriterJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, "junk" ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk"); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterValidEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterValidEncoding() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "utf-16"); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamNullWriterValidEncoding() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamNullWriterValidEncoding() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16"); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterValidEncoding() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterValidEncoding() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16"); } @Test - public void copyEmptyInputStreamValidWriterValidEncoding() - throws Exception - { + public void copyEmptyInputStreamValidWriterValidEncoding() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, "utf-16" ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, "utf-16"); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyInputStreamNullWriterValidEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyInputStreamNullWriterValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), nullWriter(), "utf-16" ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), nullWriter(), "utf-16"); } @Test - public void copyInputStreamValidWriterValidEncoding() - throws Exception - { + public void copyInputStreamValidWriterValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), writer, "utf-16" ); - assertThat( writer.toString().getBytes( "utf-8" ), is( probe.getBytes( "utf-8" ) ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), writer, "utf-16"); + assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8"))); } /* * copy(InputStream,Writer,String,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamNullWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyEmptyInputStreamValidWriterNullEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, null, -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, null, -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyInputStreamNullWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyInputStreamNullWriterNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), null, -1 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyInputStreamValidWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyInputStreamValidWriterNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, null, -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "junk", -1); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), "junk", -1 ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyInputStreamJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyInputStreamJunkEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, "junk", -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, "junk", -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyInputStreamNullWriterJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyInputStreamNullWriterJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), "junk", -1 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyInputStreamValidWriterJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyInputStreamValidWriterJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, "junk", -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamNullWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamNullWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", -1); } - @Test( expected = NullPointerException.class ) - public void copyNullInputStreamValidWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullInputStreamValidWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), "utf-16", -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamNullWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyInputStreamValidWriterValidEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, "utf-16", -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, "utf-16", -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void copyInputStreamNullWriterValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyInputStreamNullWriterValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), nullWriter(), -1 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyInputStreamValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyInputStreamValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes( "utf-16" ) ), writer, "utf-16", -1 ); - assertThat( writer.toString().getBytes( "utf-8" ), is( probe.getBytes( "utf-8" ) ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes("utf-16")), writer, "utf-16", -1); + assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamNullWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamValidWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, null, 0 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, null, 0); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyInputStreamNullWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyInputStreamNullWriterNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), null, 0 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyInputStreamValidWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyInputStreamValidWriterNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, null, 0 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, null, 0); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "junk", 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamNullWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( emptyInputStream(), nullWriter(), "junk", 0 ); + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(emptyInputStream(), nullWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyInputStreamValidWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyInputStream(), writer, "junk", 0 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyInputStream(), writer, "junk", 0); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyInputStreamNullWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyInputStreamNullWriterJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), nullWriter(), "junk", 0 ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), nullWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyInputStreamValidWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyInputStreamValidWriterJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new ByteArrayInputStream( probe.getBytes() ), writer, "junk", 0 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(new ByteArrayInputStream(probe.getBytes()), writer, "junk", 0); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamNullWriterValidEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), nullWriter(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamNullWriterValidEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), nullWriter(), "utf-16", 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullInputStreamValidWriterValidEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullInputStream(), new DontCloseStringWriter(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullInputStreamValidWriterValidEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullInputStream(), new DontCloseStringWriter(), "utf-16", 0); } /* * copy(String,Writer) */ - @Test( expected = NullPointerException.class ) - public void copyNullStringNullWriter() - throws Exception - { - IOUtil.copy( nullString(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyNullStringNullWriter() throws Exception { + IOUtil.copy(nullString(), nullWriter()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyStringNullWriter() - throws Exception - { - IOUtil.copy( emptyString(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyEmptyStringNullWriter() throws Exception { + IOUtil.copy(emptyString(), nullWriter()); } @Test - public void copyNullStringValidWriter() - throws Exception - { - IOUtil.copy( nullString(), new DontCloseStringWriter() ); + public void copyNullStringValidWriter() throws Exception { + IOUtil.copy(nullString(), new DontCloseStringWriter()); } @Test - public void copyEmptyStringValidWriter() - throws Exception - { + public void copyEmptyStringValidWriter() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyString(), writer ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyString(), writer); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyStringNullWriter() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyStringNullWriter() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe, nullWriter() ); + IOUtil.copy(probe, nullWriter()); } @Test - public void copyStringValidWriter() - throws Exception - { + public void copyStringValidWriter() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe, writer ); - assertThat( writer.toString(), is( probe ) ); + IOUtil.copy(probe, writer); + assertThat(writer.toString(), is(probe)); } - @Test( expected = NullPointerException.class ) - public void copyNullStringNullOutputStream() - throws Exception - { - IOUtil.copy( nullString(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullStringNullOutputStream() throws Exception { + IOUtil.copy(nullString(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyStringNullOutputStream() - throws Exception - { - IOUtil.copy( emptyString(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyEmptyStringNullOutputStream() throws Exception { + IOUtil.copy(emptyString(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyNullStringValidOutputStream() - throws Exception - { - IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullStringValidOutputStream() throws Exception { + IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream()); } @Test - public void copyEmptyStringValidOutputStream() - throws Exception - { + public void copyEmptyStringValidOutputStream() throws Exception { ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( emptyString(), OutputStream ); - assertThat( OutputStream.toByteArray(), is( emptyString().getBytes() ) ); + IOUtil.copy(emptyString(), OutputStream); + assertThat(OutputStream.toByteArray(), is(emptyString().getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyStringNullOutputStream() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyStringNullOutputStream() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe, nullOutputStream() ); + IOUtil.copy(probe, nullOutputStream()); } @Test - public void copyStringValidOutputStream() - throws Exception - { + public void copyStringValidOutputStream() throws Exception { String probe = "A string \u2345\u00ef"; ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( probe, OutputStream ); - assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) ); + IOUtil.copy(probe, OutputStream); + assertThat(OutputStream.toByteArray(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullStringNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullString(), nullOutputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void copyNullStringNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullString(), nullOutputStream(), -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyStringNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( emptyString(), nullOutputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyStringNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(emptyString(), nullOutputStream(), -1); } - @Test( expected = NullPointerException.class ) - public void copyNullStringValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void copyNullStringValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyStringValidOutputStreamNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyStringValidOutputStreamNegBufSz() throws Exception { ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( emptyString(), OutputStream, -1 ); - assertThat( OutputStream.toByteArray(), is( emptyString().getBytes() ) ); + IOUtil.copy(emptyString(), OutputStream, -1); + assertThat(OutputStream.toByteArray(), is(emptyString().getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyStringNullOutputStreamNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyStringNullOutputStreamNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe, nullOutputStream(), -1 ); + IOUtil.copy(probe, nullOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyStringValidOutputStreamNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyStringValidOutputStreamNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( probe, OutputStream, -1 ); - assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) ); + IOUtil.copy(probe, OutputStream, -1); + assertThat(OutputStream.toByteArray(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullStringNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullString(), nullOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullStringNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullString(), nullOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyStringNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( emptyString(), nullOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyStringNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(emptyString(), nullOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullStringValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullStringValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 0); } - @Test( expected = NullPointerException.class ) - public void copyNullStringNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullString(), nullOutputStream(), 1 ); + + @Test(expected = NullPointerException.class) + public void copyNullStringNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullString(), nullOutputStream(), 1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyStringNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( emptyString(), nullOutputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyStringNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(emptyString(), nullOutputStream(), 1); } - @Test( expected = NullPointerException.class ) - public void copyNullStringValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullString(), new DontCloseByteArrayOutputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullStringValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullString(), new DontCloseByteArrayOutputStream(), 1); } @Test - public void copyEmptyStringValidOutputStreamPosBufSz() - throws Exception - { + public void copyEmptyStringValidOutputStreamPosBufSz() throws Exception { ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( emptyString(), OutputStream, 1 ); - assertThat( OutputStream.toByteArray(), is( emptyString().getBytes() ) ); + IOUtil.copy(emptyString(), OutputStream, 1); + assertThat(OutputStream.toByteArray(), is(emptyString().getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyStringNullOutputStreamPosBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyStringNullOutputStreamPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe, nullOutputStream(), 1 ); + IOUtil.copy(probe, nullOutputStream(), 1); } @Test - public void copyStringValidOutputStreamPosBufSz() - throws Exception - { + public void copyStringValidOutputStreamPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; ByteArrayOutputStream OutputStream = new DontCloseByteArrayOutputStream(); - IOUtil.copy( probe, OutputStream, 1 ); - assertThat( OutputStream.toByteArray(), is( probe.getBytes() ) ); + IOUtil.copy(probe, OutputStream, 1); + assertThat(OutputStream.toByteArray(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderNullWriter() - throws Exception - { - IOUtil.copy( nullReader(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyNullReaderNullWriter() throws Exception { + IOUtil.copy(nullReader(), nullWriter()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyReaderNullWriter() - throws Exception - { - IOUtil.copy( emptyReader(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyEmptyReaderNullWriter() throws Exception { + IOUtil.copy(emptyReader(), nullWriter()); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderValidWriter() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseStringWriter() ); + @Test(expected = NullPointerException.class) + public void copyNullReaderValidWriter() throws Exception { + IOUtil.copy(nullReader(), new DontCloseStringWriter()); } @Test - public void copyEmptyReaderValidWriter() - throws Exception - { + public void copyEmptyReaderValidWriter() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyReader(), writer ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyReader(), writer); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyReaderNullWriter() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyReaderNullWriter() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new StringReader( probe ), nullWriter() ); + IOUtil.copy(new StringReader(probe), nullWriter()); } @Test - public void copyReaderValidWriter() - throws Exception - { + public void copyReaderValidWriter() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new StringReader( probe ), writer ); - assertThat( writer.toString(), is( probe ) ); + IOUtil.copy(new StringReader(probe), writer); + assertThat(writer.toString(), is(probe)); } /* * copy(Reader,Writer,int) */ - @Test( expected = NegativeArraySizeException.class ) - public void copyNullReaderNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyNullReaderNullWriterNegBufSz() throws Exception { + IOUtil.copy(nullReader(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyReaderNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyReaderNullWriterNegBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyNullReaderValidWriterNegBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseStringWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyNullReaderValidWriterNegBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseStringWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyReaderValidWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyReaderValidWriterNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyReader(), writer, -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyReader(), writer, -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void copyReaderNullWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyReaderNullWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new StringReader( probe ), nullWriter(), -1 ); + IOUtil.copy(new StringReader(probe), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyReaderValidWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyReaderValidWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new StringReader( probe ), writer, -1 ); - assertThat( writer.toString(), is( probe ) ); + IOUtil.copy(new StringReader(probe), writer, -1); + assertThat(writer.toString(), is(probe)); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullReaderNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullReaderNullWriterZeroBufSz() throws Exception { + IOUtil.copy(nullReader(), nullWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyReaderNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyReaderNullWriterZeroBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullReaderValidWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseStringWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullReaderValidWriterZeroBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseStringWriter(), 0); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullReaderNullWriterPosBufSz() throws Exception { + IOUtil.copy(nullReader(), nullWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyReaderNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyReaderNullWriterPosBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderValidWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseStringWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullReaderValidWriterPosBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseStringWriter(), 1); } @Test - public void copyEmptyReaderValidWriterPosBufSz() - throws Exception - { + public void copyEmptyReaderValidWriterPosBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyReader(), writer, 1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyReader(), writer, 1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyReaderNullWriterPosBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyReaderNullWriterPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( new StringReader( probe ), nullWriter(), 1 ); + IOUtil.copy(new StringReader(probe), nullWriter(), 1); } @Test - public void copyReaderValidWriterPosBufSz() - throws Exception - { + public void copyReaderValidWriterPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( new StringReader( probe ), writer, 1 ); - assertThat( writer.toString(), is( probe ) ); + IOUtil.copy(new StringReader(probe), writer, 1); + assertThat(writer.toString(), is(probe)); } /* * toByteArray(InputStream,int) */ - @Test( expected = NegativeArraySizeException.class ) - public void toByteArrayFromInputStreamNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toByteArrayFromInputStreamNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ), -1 ), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), -1), + is(probe.getBytes())); } - @Test( expected = NegativeArraySizeException.class ) - public void toByteArrayNullInputStreamNegBufSz() - throws Exception - { - IOUtil.toByteArray( nullInputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void toByteArrayNullInputStreamNegBufSz() throws Exception { + IOUtil.toByteArray(nullInputStream(), -1); } @Test - public void toByteArrayFromInputStreamPosBufSz() - throws Exception - { + public void toByteArrayFromInputStreamPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new DontCloseByteArrayInputStream( IOUtil.toByteArray( probe ) ), +1 ), - is( probe.getBytes() ) ); + assertThat( + IOUtil.toByteArray(new DontCloseByteArrayInputStream(IOUtil.toByteArray(probe)), +1), + is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullInputStreamPosBufSz() - throws Exception - { - IOUtil.toByteArray( nullInputStream(), +1 ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullInputStreamPosBufSz() throws Exception { + IOUtil.toByteArray(nullInputStream(), +1); } /* * toByteArray(Reader,int) */ - @Test( expected = NegativeArraySizeException.class ) - public void toByteArrayFromReaderNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toByteArrayFromReaderNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new DontCloseStringReader( probe ), -1 ), - is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), -1), is(probe.getBytes())); } - @Test( expected = NegativeArraySizeException.class ) - public void toByteArrayNullReaderNegBufSz() - throws Exception - { - IOUtil.toByteArray( nullReader(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void toByteArrayNullReaderNegBufSz() throws Exception { + IOUtil.toByteArray(nullReader(), -1); } @Test - public void toByteArrayFromReaderPosBufSz() - throws Exception - { + public void toByteArrayFromReaderPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( new DontCloseStringReader( probe ), +1 ), - is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(new DontCloseStringReader(probe), +1), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullReaderPosBufSz() - throws Exception - { - IOUtil.toByteArray( nullReader(), +1 ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullReaderPosBufSz() throws Exception { + IOUtil.toByteArray(nullReader(), +1); } /* * toByteArray(String,int) */ - @Test( expected = NegativeArraySizeException.class ) - public void toByteArrayFromStringNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toByteArrayFromStringNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( probe, -1 ), is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(probe, -1), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullStringNegBufSz() - throws Exception - { - IOUtil.toByteArray( nullString(), -1 ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullStringNegBufSz() throws Exception { + IOUtil.toByteArray(nullString(), -1); } @Test - public void toByteArrayFromStringPosBufSz() - throws Exception - { + public void toByteArrayFromStringPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toByteArray( probe, +1 ), is( probe.getBytes() ) ); + assertThat(IOUtil.toByteArray(probe, +1), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void toByteArrayNullStringPosBufSz() - throws Exception - { - IOUtil.toByteArray( nullString(), +1 ); + @Test(expected = NullPointerException.class) + public void toByteArrayNullStringPosBufSz() throws Exception { + IOUtil.toByteArray(nullString(), +1); } /* * toString(Reader,int) */ - @Test( expected = NegativeArraySizeException.class ) - public void toStringFromReaderNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void toStringFromReaderNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new DontCloseStringReader( probe ), -1 ), - is( probe) ); + assertThat(IOUtil.toString(new DontCloseStringReader(probe), -1), is(probe)); } - @Test( expected = NegativeArraySizeException.class ) - public void toStringNullReaderNegBufSz() - throws Exception - { - IOUtil.toString( nullReader(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void toStringNullReaderNegBufSz() throws Exception { + IOUtil.toString(nullReader(), -1); } @Test - public void toStringFromReaderPosBufSz() - throws Exception - { + public void toStringFromReaderPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - assertThat( IOUtil.toString( new DontCloseStringReader( probe ), +1 ), - is( probe) ); + assertThat(IOUtil.toString(new DontCloseStringReader(probe), +1), is(probe)); } - @Test( expected = NullPointerException.class ) - public void toStringNullReaderPosBufSz() - throws Exception - { - IOUtil.toString( nullReader(), +1 ); + @Test(expected = NullPointerException.class) + public void toStringNullReaderPosBufSz() throws Exception { + IOUtil.toString(nullReader(), +1); } /* * copy(Reader,OutputStream) */ - @Test( expected = NullPointerException.class ) - public void copyNullReaderNullOutputStream() - throws Exception - { - IOUtil.copy( nullReader(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullReaderNullOutputStream() throws Exception { + IOUtil.copy(nullReader(), nullOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderValidOutputStream() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseByteArrayOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyNullReaderValidOutputStream() throws Exception { + IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyReaderNullOutputStream() - throws Exception - { - IOUtil.copy( emptyReader(), nullOutputStream() ); + @Test(expected = NullPointerException.class) + public void copyEmptyReaderNullOutputStream() throws Exception { + IOUtil.copy(emptyReader(), nullOutputStream()); } @Test - public void copyEmptyReaderValidOutputStream() - throws Exception - { - IOUtil.copy( emptyReader(), new DontCloseByteArrayOutputStream() ); + public void copyEmptyReaderValidOutputStream() throws Exception { + IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream()); } @Test - public void copyReaderValidOutputStream() - throws Exception - { + public void copyReaderValidOutputStream() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); String probe = "A string \u2345\u00ef"; - IOUtil.copy( new DontCloseStringReader( probe ), outputStream ); - assertThat( outputStream.toByteArray(), is( probe.getBytes()) ); + IOUtil.copy(new DontCloseStringReader(probe), outputStream); + assertThat(outputStream.toByteArray(), is(probe.getBytes())); } /* * copy(Reader,OutputStream,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullReaderNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullOutputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void copyNullReaderNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullReader(), nullOutputStream(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyNullReaderValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseByteArrayOutputStream(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyNullReaderValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyReaderNullOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullOutputStream(), -1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyReaderNullOutputStreamNegBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullOutputStream(), -1); } @Test(expected = NegativeArraySizeException.class) - public void copyEmptyReaderValidOutputStreamNegBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), new DontCloseByteArrayOutputStream(), -1 ); + public void copyEmptyReaderValidOutputStreamNegBufSz() throws Exception { + IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream(), -1); } @Test(expected = NegativeArraySizeException.class) - public void copyReaderValidOutputStreamNegBufSz() - throws Exception - { + public void copyReaderValidOutputStreamNegBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); String probe = "A string \u2345\u00ef"; - IOUtil.copy( new DontCloseStringReader( probe ), outputStream, -1 ); - assertThat( outputStream.toByteArray(), is( probe.getBytes()) ); + IOUtil.copy(new DontCloseStringReader(probe), outputStream, -1); + assertThat(outputStream.toByteArray(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullReaderNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullReaderNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullReader(), nullOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullReaderValidOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseByteArrayOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullReaderValidOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyReaderNullOutputStreamZeroBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullOutputStream(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyReaderNullOutputStreamZeroBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullOutputStream(), 0); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullReader(), nullOutputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullReaderNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullReader(), nullOutputStream(), 1); } - @Test( expected = NullPointerException.class ) - public void copyNullReaderValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( nullReader(), new DontCloseByteArrayOutputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullReaderValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(nullReader(), new DontCloseByteArrayOutputStream(), 1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyReaderNullOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), nullOutputStream(), 1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyReaderNullOutputStreamPosBufSz() throws Exception { + IOUtil.copy(emptyReader(), nullOutputStream(), 1); } @Test - public void copyEmptyReaderValidOutputStreamPosBufSz() - throws Exception - { - IOUtil.copy( emptyReader(), new DontCloseByteArrayOutputStream(), 1 ); + public void copyEmptyReaderValidOutputStreamPosBufSz() throws Exception { + IOUtil.copy(emptyReader(), new DontCloseByteArrayOutputStream(), 1); } @Test - public void copyReaderValidOutputStreamPosBufSz() - throws Exception - { + public void copyReaderValidOutputStreamPosBufSz() throws Exception { ByteArrayOutputStream outputStream = new DontCloseByteArrayOutputStream(); String probe = "A string \u2345\u00ef"; - IOUtil.copy( new DontCloseStringReader( probe ), outputStream, 1 ); - assertThat( outputStream.toByteArray(), is( probe.getBytes()) ); + IOUtil.copy(new DontCloseStringReader(probe), outputStream, 1); + assertThat(outputStream.toByteArray(), is(probe.getBytes())); } /* @@ -2395,649 +1827,488 @@ public void copyReaderValidOutputStreamPosBufSz() * copy(byte[],Writer) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriter() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriter() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter()); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullWriter() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter() ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullWriter() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter()); } @Test - public void copyEmptyByteArrayValidWriter() - throws Exception - { + public void copyEmptyByteArrayValidWriter() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyByteArrayNullWriter() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyByteArrayNullWriter() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter() ); + IOUtil.copy(probe.getBytes(), nullWriter()); } @Test - public void copyByteArrayValidWriter() - throws Exception - { + public void copyByteArrayValidWriter() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } /* * copy(byte[],Writer,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyByteArrayNullWriterNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyByteArrayNullWriterNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyByteArrayValidWriterNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseStringWriter(), -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyByteArrayValidWriterNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyByteArrayNullWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyByteArrayNullWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), -1 ); + IOUtil.copy(probe.getBytes(), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyByteArrayValidWriterNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyByteArrayValidWriterNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullWriterZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidWriterZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidWriterZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayNullWriterZeroBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayNullWriterZeroBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), 0); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterPosBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterPosBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterPosBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), 1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullWriterPosBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), 1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullWriterPosBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), 1); } @Test - public void copyEmptyByteArrayValidWriterPosBufSz() - throws Exception - { + public void copyEmptyByteArrayValidWriterPosBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, 1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, 1); + assertThat(writer.toString(), is(emptyString())); } @Test - public void copyByteArrayValidWriterPosBufSz() - throws Exception - { + public void copyByteArrayValidWriterPosBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, 1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, 1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } /* * copy(byte[],Writer,String) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterNullEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterNullEncoding() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterNullEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterNullEncoding() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullWriterNullEncoding() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullWriterNullEncoding() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayValidWriterNullEncoding() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseStringWriter(), null ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayValidWriterNullEncoding() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), null); } - @Test( expected = NullPointerException.class ) - public void copyByteArrayNullEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyByteArrayNullEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, null ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, null); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterJunkEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "junk" ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterJunkEncoding() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "junk"); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterJunkEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "junk" ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterJunkEncoding() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyByteArrayNullWriterJunkEncoding() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), "junk" ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyByteArrayNullWriterJunkEncoding() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyByteArrayValidWriterJunkEncoding() - throws Exception - { - IOUtil.copy( emptyByteArray(), new DontCloseStringWriter(), "junk" ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyByteArrayValidWriterJunkEncoding() throws Exception { + IOUtil.copy(emptyByteArray(), new DontCloseStringWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyByteArrayNullWriterJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyByteArrayNullWriterJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), "junk" ); + IOUtil.copy(probe.getBytes(), nullWriter(), "junk"); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyByteArrayValidWriterJunkEncoding() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyByteArrayValidWriterJunkEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, "junk" ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, "junk"); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterValidEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterValidEncoding() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "utf-16"); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullWriterValidEncoding() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullWriterValidEncoding() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16"); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterValidEncoding() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "utf-16" ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterValidEncoding() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16"); } @Test - public void copyEmptyByteArrayValidWriterValidEncoding() - throws Exception - { + public void copyEmptyByteArrayValidWriterValidEncoding() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, "utf-16" ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, "utf-16"); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyByteArrayNullWriterValidEncoding() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyByteArrayNullWriterValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes( "utf-16" ), nullWriter(), "utf-16" ); + IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), "utf-16"); } @Test - public void copyByteArrayValidWriterValidEncoding() - throws Exception - { + public void copyByteArrayValidWriterValidEncoding() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes( "utf-16" ), writer, "utf-16" ); - assertThat( writer.toString().getBytes( "utf-8" ), is( probe.getBytes( "utf-8" ) ) ); + IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16"); + assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8"))); } /* * copy(byte[],Writer,String,int) */ - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), null, -1 ); + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayNullWriterNullEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyEmptyByteArrayValidWriterNullEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, null, -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, null, -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class ) - public void copyByteArrayNullWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyByteArrayNullWriterNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), null, -1 ); + IOUtil.copy(probe.getBytes(), nullWriter(), null, -1); } - @Test( expected = NullPointerException.class ) - public void copyByteArrayValidWriterNullEncodingNegBufSz() - throws Exception - { + @Test(expected = NullPointerException.class) + public void copyByteArrayValidWriterNullEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, null, -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, null, -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "junk", -1); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "junk", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), "junk", -1 ); + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyEmptyByteArrayJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyEmptyByteArrayJunkEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, "junk", -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, "junk", -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyByteArrayNullWriterJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyByteArrayNullWriterJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), "junk", -1 ); + IOUtil.copy(probe.getBytes(), nullWriter(), "junk", -1); } - @Test( expected = UnsupportedEncodingException.class ) - public void copyByteArrayValidWriterJunkEncodingNegBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class) + public void copyByteArrayValidWriterJunkEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, "junk", -1 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, "junk", -1); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayNullWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayNullWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", -1); } - @Test( expected = NullPointerException.class ) - public void copyNullByteArrayValidWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "utf-16", -1 ); + @Test(expected = NullPointerException.class) + public void copyNullByteArrayValidWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), "utf-16", -1 ); + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyByteArrayNullWriterValidEncodingNegBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), "utf-16", -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyEmptyByteArrayValidWriterValidEncodingNegBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, "utf-16", -1 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, "utf-16", -1); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NegativeArraySizeException.class ) - public void copyByteArrayNullWriterValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyByteArrayNullWriterValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes( "utf-16" ), nullWriter(), -1 ); + IOUtil.copy(probe.getBytes("utf-16"), nullWriter(), -1); } - @Test( expected = NegativeArraySizeException.class ) - public void copyByteArrayValidEncodingNegBufSz() - throws Exception - { + @Test(expected = NegativeArraySizeException.class) + public void copyByteArrayValidEncodingNegBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes( "utf-16" ), writer, "utf-16", -1 ); - assertThat( writer.toString().getBytes( "utf-8" ), is( probe.getBytes( "utf-8" ) ) ); + IOUtil.copy(probe.getBytes("utf-16"), writer, "utf-16", -1); + assertThat(writer.toString().getBytes("utf-8"), is(probe.getBytes("utf-8"))); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayNullWriterNullEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), null, 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayValidWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, null, 0 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, null, 0); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayNullWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayNullWriterNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), null, 0 ); + IOUtil.copy(probe.getBytes(), nullWriter(), null, 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayValidWriterNullEncodingZeroBufSz() - throws Exception - { + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayValidWriterNullEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, null, 0 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, null, 0); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "junk", 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "junk", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayNullWriterJunkEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( emptyByteArray(), nullWriter(), "junk", 0 ); + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception { + IOUtil.copy(emptyByteArray(), nullWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyEmptyByteArrayValidWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyEmptyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception { StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( emptyByteArray(), writer, "junk", 0 ); - assertThat( writer.toString(), is( emptyString() ) ); + IOUtil.copy(emptyByteArray(), writer, "junk", 0); + assertThat(writer.toString(), is(emptyString())); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayNullWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayNullWriterJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; - IOUtil.copy( probe.getBytes(), nullWriter(), "junk", 0 ); + IOUtil.copy(probe.getBytes(), nullWriter(), "junk", 0); } - @Test( expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyByteArrayValidWriterJunkEncodingZeroBufSz() - throws Exception - { + @Test(expected = UnsupportedEncodingException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyByteArrayValidWriterJunkEncodingZeroBufSz() throws Exception { String probe = "A string \u2345\u00ef"; StringWriter writer = new DontCloseStringWriter(); - IOUtil.copy( probe.getBytes(), writer, "junk", 0 ); - assertThat( writer.toString().getBytes(), is( probe.getBytes() ) ); + IOUtil.copy(probe.getBytes(), writer, "junk", 0); + assertThat(writer.toString().getBytes(), is(probe.getBytes())); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayNullWriterValidEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), nullWriter(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayNullWriterValidEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), nullWriter(), "utf-16", 0); } - @Test( expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT ) - public void copyNullByteArrayValidWriterValidEncodingZeroBufSz() - throws Exception - { - IOUtil.copy( nullByteArray(), new DontCloseStringWriter(), "utf-16", 0 ); + @Test(expected = NullPointerException.class, timeout = INFINITE_LOOP_TIMEOUT) + public void copyNullByteArrayValidWriterValidEncodingZeroBufSz() throws Exception { + IOUtil.copy(nullByteArray(), new DontCloseStringWriter(), "utf-16", 0); } /* * Utility methods */ - private static byte[] nullByteArray() - { + private static byte[] nullByteArray() { return null; } - private static String nullString() - { + private static String nullString() { return null; } - private static OutputStream nullOutputStream() - { + private static OutputStream nullOutputStream() { return null; } - private static InputStream nullInputStream() - { + private static InputStream nullInputStream() { return null; } - private static Writer nullWriter() - { + private static Writer nullWriter() { return null; } - private static Reader nullReader() - { + private static Reader nullReader() { return null; } - private static ByteArrayInputStream emptyInputStream() - { - return new ByteArrayInputStream( emptyByteArray() ); + private static ByteArrayInputStream emptyInputStream() { + return new ByteArrayInputStream(emptyByteArray()); } - private static Reader emptyReader() - { - return new StringReader( emptyString() ); + private static Reader emptyReader() { + return new StringReader(emptyString()); } - private static String emptyString() - { + private static String emptyString() { return ""; } - private static byte[] emptyByteArray() - { + private static byte[] emptyByteArray() { return new byte[0]; } - private static class DontCloseStringWriter - extends StringWriter - { + private static class DontCloseStringWriter extends StringWriter { @Override - public void close() - throws IOException - { - throw new UnsupportedOperationException( "should not be called" ); + public void close() throws IOException { + throw new UnsupportedOperationException("should not be called"); } } - private static class DontCloseStringReader - extends StringReader - { + private static class DontCloseStringReader extends StringReader { - public DontCloseStringReader( String s ) - { - super( s ); + public DontCloseStringReader(String s) { + super(s); } @Override - public void close() - { - throw new UnsupportedOperationException( "should not be called" ); + public void close() { + throw new UnsupportedOperationException("should not be called"); } } - private static class DontCloseByteArrayInputStream - extends ByteArrayInputStream - { - public DontCloseByteArrayInputStream( byte[] input ) - { - super( input ); + private static class DontCloseByteArrayInputStream extends ByteArrayInputStream { + public DontCloseByteArrayInputStream(byte[] input) { + super(input); } @Override - public void close() - throws IOException - { - throw new UnsupportedOperationException( "should not be called" ); + public void close() throws IOException { + throw new UnsupportedOperationException("should not be called"); } } - private static class DontCloseByteArrayOutputStream - extends ByteArrayOutputStream - { + private static class DontCloseByteArrayOutputStream extends ByteArrayOutputStream { @Override - public void close() - throws IOException - { - throw new UnsupportedOperationException( "should not be called" ); + public void close() throws IOException { + throw new UnsupportedOperationException("should not be called"); } } } diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java index 6c7e11d3..57157870 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.io; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,21 +16,20 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.io; import org.junit.Test; + import static org.junit.Assert.*; /** * @author Kristian Rosenvold */ -@SuppressWarnings( "deprecation" ) -public class MatchPatternTest -{ +@SuppressWarnings("deprecation") +public class MatchPatternTest { @Test - public void matchPath() - { - MatchPattern mp = MatchPattern.fromString( "ABC*" ); - assertTrue( mp.matchPath( "ABCD", true ) ); + public void matchPath() { + MatchPattern mp = MatchPattern.fromString("ABC*"); + assertTrue(mp.matchPath("ABCD", true)); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java index 84b41f96..8919d065 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.io; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.io; import org.junit.Test; @@ -26,15 +25,13 @@ /** * @author Kristian Rosenvold */ -@SuppressWarnings( "deprecation" ) -public class MatchPatternsTest -{ +@SuppressWarnings("deprecation") +public class MatchPatternsTest { @Test - public void matches() - { - MatchPatterns from = MatchPatterns.from( "ABC**", "CDE**" ); - assertTrue( from.matches( "ABCDE", true ) ); - assertTrue( from.matches( "CDEF", true ) ); - assertFalse( from.matches( "XYZ", true ) ); + public void matches() { + MatchPatterns from = MatchPatterns.from("ABC**", "CDE**"); + assertTrue(from.matches("ABCDE", true)); + assertTrue(from.matches("CDEF", true)); + assertFalse(from.matches("XYZ", true)); } } diff --git a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java index 750015a7..3b246361 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.io; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,67 +16,62 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.*; +package org.apache.maven.shared.utils.io; import java.io.File; import org.junit.Test; +import static org.junit.Assert.*; + /** * Test the {@link SelectorUtils} class. */ -@SuppressWarnings( "deprecation" ) -public class SelectorUtilsTest -{ +@SuppressWarnings("deprecation") +public class SelectorUtilsTest { - @Test( expected = NullPointerException.class ) - public void testMatchPatternStart() - { - SelectorUtils.matchPatternStart( null, null ); + @Test(expected = NullPointerException.class) + public void testMatchPatternStart() { + SelectorUtils.matchPatternStart(null, null); } @Test - public void testEmptyStrings() - { - assertTrue( SelectorUtils.matchPatternStart( "", "" ) ); + public void testEmptyStrings() { + assertTrue(SelectorUtils.matchPatternStart("", "")); } @Test - public void testRegexPrefix() - throws Exception - { - assertEquals( true, - SelectorUtils.matchPatternStart( SelectorUtils.REGEX_HANDLER_PREFIX + File.separator + "aaa" - + SelectorUtils.PATTERN_HANDLER_SUFFIX, "" ) ); + public void testRegexPrefix() throws Exception { + assertEquals( + true, + SelectorUtils.matchPatternStart( + SelectorUtils.REGEX_HANDLER_PREFIX + File.separator + "aaa" + + SelectorUtils.PATTERN_HANDLER_SUFFIX, + "")); } @Test - public void testAntPatternStrings() - { - assertAntDoesNotMatch( "/aaa", "" ); - assertAntDoesNotMatch( "\\aaa", "" ); - assertAntMatch( "aaa", "" ); - assertAntMatch( "/aaa/bbb", "/aaa/bbb" ); - assertAntMatch( "/aaa/**", "/aaa/bbb" ); - assertAntDoesNotMatch( "/aaa/**", "/ccc/bbb" ); - assertAntMatch( "/aaa/**", "\\aaa\\bbb" ); - assertAntDoesNotMatch( "/aaa/**", "\\ccc\\bbb" ); - assertAntDoesNotMatch( "/aaa/", "\\aaa\\bbb" ); + public void testAntPatternStrings() { + assertAntDoesNotMatch("/aaa", ""); + assertAntDoesNotMatch("\\aaa", ""); + assertAntMatch("aaa", ""); + assertAntMatch("/aaa/bbb", "/aaa/bbb"); + assertAntMatch("/aaa/**", "/aaa/bbb"); + assertAntDoesNotMatch("/aaa/**", "/ccc/bbb"); + assertAntMatch("/aaa/**", "\\aaa\\bbb"); + assertAntDoesNotMatch("/aaa/**", "\\ccc\\bbb"); + assertAntDoesNotMatch("/aaa/", "\\aaa\\bbb"); } - private void assertAntDoesNotMatch( String pattern, String target ) - { - assertEquals( false, SelectorUtils.matchPatternStart( wrapWithAntHandler( pattern ), target ) ); + private void assertAntDoesNotMatch(String pattern, String target) { + assertEquals(false, SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target)); } - private void assertAntMatch( String pattern, String target ) - { - assertEquals( true, SelectorUtils.matchPatternStart( wrapWithAntHandler( pattern ), target ) ); + private void assertAntMatch(String pattern, String target) { + assertEquals(true, SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target)); } - private String wrapWithAntHandler( String val ) - { + private String wrapWithAntHandler(String val) { return SelectorUtils.ANT_HANDLER_PREFIX + val + SelectorUtils.PATTERN_HANDLER_SUFFIX; } } diff --git a/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java b/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java index 9283c970..f6a4fa5b 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java +++ b/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java @@ -1,12 +1,3 @@ -package org.apache.maven.shared.utils.io; - - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import static org.apache.commons.io.FileUtils.write; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -25,38 +16,46 @@ * specific language governing permissions and limitations * under the License. */ -public class SymlinkTestSetup -{ +package org.apache.maven.shared.utils.io; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import static org.apache.commons.io.FileUtils.write; + +public class SymlinkTestSetup { /** * Creates a standard directory layout with symlinks and files. */ - public static File createStandardSymlinkTestDir( File root ) - throws IOException - { - File srcDir = new File( root, "/src" ); + public static File createStandardSymlinkTestDir(File root) throws IOException { + File srcDir = new File(root, "/src"); srcDir.mkdirs(); - File target = new File( srcDir, "targetDir" ); + File target = new File(srcDir, "targetDir"); target.mkdirs(); - write( new File( target, "targetFile.txt" ), "a regular File payload", StandardCharsets.UTF_8 ); - File aRegularDir = new File( srcDir, "aRegularDir" ); + write(new File(target, "targetFile.txt"), "a regular File payload", StandardCharsets.UTF_8); + File aRegularDir = new File(srcDir, "aRegularDir"); aRegularDir.mkdirs(); - write( new File( aRegularDir, "aRegularFile.txt" ), "a regular File payload", StandardCharsets.UTF_8 ); + write(new File(aRegularDir, "aRegularFile.txt"), "a regular File payload", StandardCharsets.UTF_8); - File dirOnTheOutside = new File( root, "dirOnTheOutside" ); + File dirOnTheOutside = new File(root, "dirOnTheOutside"); dirOnTheOutside.mkdirs(); - write( new File( dirOnTheOutside, "FileInDirOnTheOutside.txt" ), "a file in dir on the outside", StandardCharsets.UTF_8 ); - write( new File( root, "onTheOutside.txt" ), "A file on the outside", StandardCharsets.UTF_8 ); - write( new File( srcDir, "fileR.txt" ), "FileR payload", StandardCharsets.UTF_8 ); - write( new File( srcDir, "fileW.txt" ), "FileW payload", StandardCharsets.UTF_8 ); - write( new File( srcDir, "fileX.txt" ), "FileX payload", StandardCharsets.UTF_8 ); + write( + new File(dirOnTheOutside, "FileInDirOnTheOutside.txt"), + "a file in dir on the outside", + StandardCharsets.UTF_8); + write(new File(root, "onTheOutside.txt"), "A file on the outside", StandardCharsets.UTF_8); + write(new File(srcDir, "fileR.txt"), "FileR payload", StandardCharsets.UTF_8); + write(new File(srcDir, "fileW.txt"), "FileW payload", StandardCharsets.UTF_8); + write(new File(srcDir, "fileX.txt"), "FileX payload", StandardCharsets.UTF_8); // todo: set file attributes (not used here) - FileUtils.createSymbolicLink( new File( srcDir, "symDir" ), new File( "targetDir" ) ); - FileUtils.createSymbolicLink( new File( srcDir, "symLinkToDirOnTheOutside" ), new File( "../dirOnTheOutside" ) ); - FileUtils.createSymbolicLink( new File( srcDir, "symLinkToFileOnTheOutside" ), new File( "../onTheOutside.txt" ) ); - FileUtils.createSymbolicLink( new File( srcDir, "symR" ), new File( "fileR.txt" ) ); - FileUtils.createSymbolicLink( new File( srcDir, "symW" ), new File( "fileW.txt" ) ); - FileUtils.createSymbolicLink( new File( srcDir, "symX" ), new File( "fileX.txt" ) ); + FileUtils.createSymbolicLink(new File(srcDir, "symDir"), new File("targetDir")); + FileUtils.createSymbolicLink(new File(srcDir, "symLinkToDirOnTheOutside"), new File("../dirOnTheOutside")); + FileUtils.createSymbolicLink(new File(srcDir, "symLinkToFileOnTheOutside"), new File("../onTheOutside.txt")); + FileUtils.createSymbolicLink(new File(srcDir, "symR"), new File("fileR.txt")); + FileUtils.createSymbolicLink(new File(srcDir, "symW"), new File("fileW.txt")); + FileUtils.createSymbolicLink(new File(srcDir, "symX"), new File("fileX.txt")); return srcDir; } } diff --git a/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java index 2c580e2a..030b2a42 100644 --- a/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.logging; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils; import org.junit.Before; import org.junit.Test; @@ -25,87 +24,75 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; -public class AnsiMessageBuilderTest -{ +public class AnsiMessageBuilderTest { private AnsiMessageBuilder ansiMessageBuilder; @Before - public void initializeAnsiMessageBuffer() - { + public void initializeAnsiMessageBuffer() { this.ansiMessageBuilder = new AnsiMessageBuilder(); } @Test - public void should_color_debug() - { - ansiMessageBuilder.debug( "DEBUG" ); + public void should_color_debug() { + ansiMessageBuilder.debug("DEBUG"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;36mDEBUG\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;36mDEBUG\u001B[m")); } @Test - public void should_color_info() - { - ansiMessageBuilder.info( "INFO" ); + public void should_color_info() { + ansiMessageBuilder.info("INFO"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;34mINFO\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;34mINFO\u001B[m")); } @Test - public void should_color_warning_and_reset() - { - ansiMessageBuilder.warning( "WARNING" ); + public void should_color_warning_and_reset() { + ansiMessageBuilder.warning("WARNING"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;33mWARNING\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;33mWARNING\u001B[m")); } @Test - public void should_color_error() - { - ansiMessageBuilder.error( "ERROR" ); + public void should_color_error() { + ansiMessageBuilder.error("ERROR"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;31mERROR\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31mERROR\u001B[m")); } @Test - public void should_color_success_with_message() - { - ansiMessageBuilder.success( "a success message" ); + public void should_color_success_with_message() { + ansiMessageBuilder.success("a success message"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;32ma success message\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;32ma success message\u001B[m")); } @Test - public void should_color_failure_and_reset() - { - ansiMessageBuilder.failure( "a failure message" ); + public void should_color_failure_and_reset() { + ansiMessageBuilder.failure("a failure message"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1;31ma failure message\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31ma failure message\u001B[m")); } @Test - public void should_color_strong_and_reset() - { - ansiMessageBuilder.strong( "a strong message" ); + public void should_color_strong_and_reset() { + ansiMessageBuilder.strong("a strong message"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[1ma strong message\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1ma strong message\u001B[m")); } @Test - public void should_color_mojo_and_reset() - { - ansiMessageBuilder.mojo( "a mojo" ); + public void should_color_mojo_and_reset() { + ansiMessageBuilder.mojo("a mojo"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[32ma mojo\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[32ma mojo\u001B[m")); } @Test - public void should_color_project_and_reset() - { - ansiMessageBuilder.project( "a project" ); + public void should_color_project_and_reset() { + ansiMessageBuilder.project("a project"); - assertThat( ansiMessageBuilder.toString(), equalTo( "\u001B[36ma project\u001B[m" ) ); + assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[36ma project\u001B[m")); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java index 972ceaee..8ca3a8c8 100644 --- a/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.java @@ -1,109 +1,95 @@ -package org.apache.maven.shared.utils.logging; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeNoException; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.nio.charset.StandardCharsets; - -import org.fusesource.jansi.AnsiColors; -import org.fusesource.jansi.AnsiConsole; -import org.fusesource.jansi.AnsiMode; -import org.fusesource.jansi.AnsiPrintStream; -import org.fusesource.jansi.AnsiType; -import org.fusesource.jansi.io.AnsiOutputStream; -import org.junit.Test; - -public class MessageUtilsTest -{ - @Test - public void testSystem() - { - PrintStream currentOut = System.out; - try - { - MessageUtils.systemInstall(); - assertThat( System.out, not( sameInstance( currentOut ) ) ); - } - catch( LinkageError e ) - { - assumeNoException( "JAnsi not supported for this platform", e ); - } - finally - { - try - { - // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242 - // but might throw exceptions - MessageUtils.systemUninstall(); - } - catch ( Throwable t ) - { - // ignore any thrown exception like NPE here - } - } - assertThat( System.out, sameInstance( currentOut ) ); - } - - @Test - public void testTerminalWidth() - { - AnsiOutputStream.WidthSupplier width = new AnsiOutputStream.WidthSupplier() - { - @Override - public int getTerminalWidth() - { - return 33; - } - }; - AnsiOutputStream aos = new AnsiOutputStream( new ByteArrayOutputStream(), width, AnsiMode.Default, - null, AnsiType.Emulation, AnsiColors.Colors256, StandardCharsets.UTF_8, - null, null, false ); - try - { - AnsiConsole.systemInstall(); - AnsiConsole.out = new AnsiPrintStream( aos, true ); - assertEquals( 33, MessageUtils.getTerminalWidth() ); - } - catch( LinkageError e ) - { - assumeNoException( "JAnsi not supported for this platform", e ); - } - finally - { - try - { - // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242 - // but might throw exceptions - AnsiConsole.systemUninstall(); - } - catch ( Throwable t ) - { - // ignore any thrown exception like NPE here - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.shared.utils; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; + +import org.fusesource.jansi.AnsiColors; +import org.fusesource.jansi.AnsiConsole; +import org.fusesource.jansi.AnsiMode; +import org.fusesource.jansi.AnsiPrintStream; +import org.fusesource.jansi.AnsiType; +import org.fusesource.jansi.io.AnsiOutputStream; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assume.assumeNoException; + +public class MessageUtilsTest { + @Test + public void testSystem() { + PrintStream currentOut = System.out; + try { + MessageUtils.systemInstall(); + assertThat(System.out, not(sameInstance(currentOut))); + } catch (LinkageError e) { + assumeNoException("JAnsi not supported for this platform", e); + } finally { + try { + // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242 + // but might throw exceptions + MessageUtils.systemUninstall(); + } catch (Throwable t) { + // ignore any thrown exception like NPE here + } + } + assertThat(System.out, sameInstance(currentOut)); + } + + @Test + public void testTerminalWidth() { + AnsiOutputStream.WidthSupplier width = new AnsiOutputStream.WidthSupplier() { + @Override + public int getTerminalWidth() { + return 33; + } + }; + AnsiOutputStream aos = new AnsiOutputStream( + new ByteArrayOutputStream(), + width, + AnsiMode.Default, + null, + AnsiType.Emulation, + AnsiColors.Colors256, + StandardCharsets.UTF_8, + null, + null, + false); + try { + AnsiConsole.systemInstall(); + AnsiConsole.out = new AnsiPrintStream(aos, true); + assertEquals(33, MessageUtils.getTerminalWidth()); + } catch (LinkageError e) { + assumeNoException("JAnsi not supported for this platform", e); + } finally { + try { + // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242 + // but might throw exceptions + AnsiConsole.systemUninstall(); + } catch (Throwable t) { + // ignore any thrown exception like NPE here + } + } + } +} diff --git a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java index aa7323cd..47874690 100644 --- a/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java +++ b/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.testhelpers; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.testhelpers; import java.io.File; import java.io.FileOutputStream; @@ -27,59 +26,45 @@ import java.io.Writer; import org.apache.commons.io.FileUtils; - import org.junit.rules.TemporaryFolder; /** * A few utility methods for file based tests. */ -public final class FileTestHelper -{ +public final class FileTestHelper { - private FileTestHelper() - { + private FileTestHelper() { // utility function doesn't need a public constructor } - public static void generateTestData( OutputStream out, long size ) - throws IOException - { - for ( int i = 0; i < size; i++ ) - { + public static void generateTestData(OutputStream out, long size) throws IOException { + for (int i = 0; i < size; i++) { // nice varied byte pattern compatible with Readers and Writers - out.write( (byte) ( ( i % 127 ) + 1 ) ); + out.write((byte) ((i % 127) + 1)); } } - public static void generateTestFile( File testfile, int size ) - throws IOException - { - if ( testfile.exists() ) - { + public static void generateTestFile(File testfile, int size) throws IOException { + if (testfile.exists()) { //noinspection ResultOfMethodCallIgnored testfile.delete(); } - try ( OutputStream os = new FileOutputStream( testfile ) ) { - generateTestData( os, size ); + try (OutputStream os = new FileOutputStream(testfile)) { + generateTestData(os, size); os.flush(); } } - public static void createLineBasedFile( File file, String[] data ) - throws IOException - { - if ( file.getParentFile() != null && !file.getParentFile().exists() ) - { - throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" ); + public static void createLineBasedFile(File file, String[] data) throws IOException { + if (file.getParentFile() != null && !file.getParentFile().exists()) { + throw new IOException("Cannot create file " + file + " as the parent directory does not exist"); } - try ( Writer out = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) ) - { - for ( String aData : data ) - { - out.write( aData ); - out.write( System.lineSeparator() ); + try (Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) { + for (String aData : data) { + out.write(aData); + out.write(System.lineSeparator()); } } } @@ -90,14 +75,11 @@ public static void createLineBasedFile( File file, String[] data ) * @return the File object for a new file * @throws IOException */ - public static File newFile( TemporaryFolder folder, String filename ) - throws IOException - { - File destination = folder.newFile( filename ); + public static File newFile(TemporaryFolder folder, String filename) throws IOException { + File destination = folder.newFile(filename); - if ( destination.exists() ) - { - FileUtils.deleteQuietly( destination ); + if (destination.exists()) { + FileUtils.deleteQuietly(destination); } return destination; } diff --git a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java index fdf81302..41dee5f1 100644 --- a/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java +++ b/src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,10 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml; + +import javax.swing.text.html.HTML; import java.io.IOException; import java.io.StringWriter; -import javax.swing.text.html.HTML; import org.apache.maven.shared.utils.StringUtils; import org.junit.Assert; @@ -32,172 +32,164 @@ * * @author Vincent Siveton */ -public class PrettyPrintXmlWriterTest -{ +public class PrettyPrintXmlWriterTest { private StringWriter w = new StringWriter(); - private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( w ); - + private PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter(w); + @Test - public void testNoStartTag() throws IOException - { - + public void testNoStartTag() throws IOException { + try { - writer.startElement( "" ); - Assert.fail( "allowed empty name" ); - } catch ( IllegalArgumentException ex ) { - Assert.assertEquals( "Element name cannot be empty", ex.getMessage() ); + writer.startElement(""); + Assert.fail("allowed empty name"); + } catch (IllegalArgumentException ex) { + Assert.assertEquals("Element name cannot be empty", ex.getMessage()); } - } - + @Test - public void testDefaultPrettyPrintXMLWriter() throws IOException - { - writer.startElement( HTML.Tag.HTML.toString() ); + public void testDefaultPrettyPrintXMLWriter() throws IOException { + writer.startElement(HTML.Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - Assert.assertEquals( expectedResult(), w.toString() ); + Assert.assertEquals(expectedResult(), w.toString()); } @Test - public void testPrettyPrintXMLWriterWithGivenLineSeparator() throws IOException - { - writer.setLineSeparator( "\n" ); + public void testPrettyPrintXMLWriterWithGivenLineSeparator() throws IOException { + writer.setLineSeparator("\n"); - writer.startElement( HTML.Tag.HTML.toString() ); + writer.startElement(HTML.Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - Assert.assertEquals( expectedResult(), w.toString() ); + Assert.assertEquals(expectedResult(), w.toString()); } @Test - public void testPrettyPrintXMLWriterWithGivenLineIndenter() throws IOException - { - writer.setLineIndenter( " " ); + public void testPrettyPrintXMLWriterWithGivenLineIndenter() throws IOException { + writer.setLineIndenter(" "); - writer.startElement( HTML.Tag.HTML.toString() ); + writer.startElement(HTML.Tag.HTML.toString()); - writeXhtmlHead( writer ); + writeXhtmlHead(writer); - writeXhtmlBody( writer ); + writeXhtmlBody(writer); writer.endElement(); // Tag.HTML - Assert.assertEquals( expectedResult( " " ), w.toString() ); + Assert.assertEquals(expectedResult(" "), w.toString()); } @Test - public void testEscapeXmlAttributeWindows() throws IOException - { + public void testEscapeXmlAttributeWindows() throws IOException { // Windows - writer.startElement( HTML.Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\r\nion" ); + writer.startElement(HTML.Tag.DIV.toString()); + writer.addAttribute("class", "sect\r\nion"); writer.endElement(); // Tag.DIV - Assert.assertEquals( "
", w.toString() ); + Assert.assertEquals("
", w.toString()); } @Test - public void testEscapeXmlAttributeMac() throws IOException - { + public void testEscapeXmlAttributeMac() throws IOException { // Mac - writer.startElement( HTML.Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\rion" ); + writer.startElement(HTML.Tag.DIV.toString()); + writer.addAttribute("class", "sect\rion"); writer.endElement(); // Tag.DIV - Assert.assertEquals( "
", w.toString() ); + Assert.assertEquals("
", w.toString()); } @Test - public void testEscapeXmlAttributeTrailingCR() throws IOException - { + public void testEscapeXmlAttributeTrailingCR() throws IOException { // Mac - writer.startElement( HTML.Tag.DIV.toString() ); - writer.addAttribute( "class", "section\r" ); + writer.startElement(HTML.Tag.DIV.toString()); + writer.addAttribute("class", "section\r"); writer.endElement(); // Tag.DIV - Assert.assertEquals( "
", w.toString() ); + Assert.assertEquals("
", w.toString()); } @Test - public void testEscapeXmlAttributeUnix() throws IOException - { + public void testEscapeXmlAttributeUnix() throws IOException { // Unix - writer.startElement( HTML.Tag.DIV.toString() ); - writer.addAttribute( "class", "sect\nion" ); + writer.startElement(HTML.Tag.DIV.toString()); + writer.addAttribute("class", "sect\nion"); writer.endElement(); // Tag.DIV - Assert.assertEquals( "
", w.toString() ); + Assert.assertEquals("
", w.toString()); } - private void writeXhtmlHead( XMLWriter writer ) throws IOException - { - writer.startElement( HTML.Tag.HEAD.toString() ); - writer.startElement( HTML.Tag.TITLE.toString() ); - writer.writeText( "title" ); + private void writeXhtmlHead(XMLWriter writer) throws IOException { + writer.startElement(HTML.Tag.HEAD.toString()); + writer.startElement(HTML.Tag.TITLE.toString()); + writer.writeText("title"); writer.endElement(); // Tag.TITLE - writer.startElement( HTML.Tag.META.toString() ); - writer.addAttribute( "name", "author" ); - writer.addAttribute( "content", "Author" ); + writer.startElement(HTML.Tag.META.toString()); + writer.addAttribute("name", "author"); + writer.addAttribute("content", "Author"); writer.endElement(); // Tag.META - writer.startElement( HTML.Tag.META.toString() ); - writer.addAttribute( "name", "date" ); - writer.addAttribute( "content", "Date" ); + writer.startElement(HTML.Tag.META.toString()); + writer.addAttribute("name", "date"); + writer.addAttribute("content", "Date"); writer.endElement(); // Tag.META writer.endElement(); // Tag.HEAD } - private void writeXhtmlBody( XMLWriter writer ) throws IOException - { - writer.startElement( HTML.Tag.BODY.toString() ); - writer.startElement( HTML.Tag.P.toString() ); - writer.writeText( "Paragraph 1, line 1. Paragraph 1, line 2." ); + private void writeXhtmlBody(XMLWriter writer) throws IOException { + writer.startElement(HTML.Tag.BODY.toString()); + writer.startElement(HTML.Tag.P.toString()); + writer.writeText("Paragraph 1, line 1. Paragraph 1, line 2."); writer.endElement(); // Tag.P - writer.startElement( HTML.Tag.DIV.toString() ); - writer.addAttribute( "class", "section" ); - writer.startElement( HTML.Tag.H2.toString() ); - writer.writeText( "Section title" ); + writer.startElement(HTML.Tag.DIV.toString()); + writer.addAttribute("class", "section"); + writer.startElement(HTML.Tag.H2.toString()); + writer.writeText("Section title"); writer.endElement(); // Tag.H2 writer.endElement(); // Tag.DIV writer.endElement(); // Tag.BODY } - private static String expectedResult() - { - return expectedResult( " " ); + private static String expectedResult() { + return expectedResult(" "); } - private static String expectedResult( String lineIndenter ) - { - + private static String expectedResult(String lineIndenter) { + String lineSeparator = "\n"; StringBuilder expected = new StringBuilder(); - expected.append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "title" ) - .append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ) - .append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "" ) - .append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ) - .append( "

Paragraph 1, line 1. Paragraph 1, line 2.

" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
" ) - .append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 3 ) ).append( "

Section title

" ) - .append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 2 ) ).append( "
" ).append( lineSeparator ); - expected.append( StringUtils.repeat( lineIndenter, 1 ) ).append( "" ).append( lineSeparator ); - expected.append( "" ); + expected.append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("title") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("

Paragraph 1, line 1. Paragraph 1, line 2.

") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)) + .append("
") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 3)) + .append("

Section title

") + .append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 2)).append("
").append(lineSeparator); + expected.append(StringUtils.repeat(lineIndenter, 1)).append("").append(lineSeparator); + expected.append(""); return expected.toString(); } diff --git a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java index 433e5feb..5566ef94 100644 --- a/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/apache/maven/shared/utils/xml/XmlWriterUtilTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,23 +16,22 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; -import org.apache.maven.shared.utils.StringUtils; -import org.apache.maven.shared.utils.WriterFactory; import junit.framework.TestCase; +import org.apache.maven.shared.utils.StringUtils; +import org.apache.maven.shared.utils.WriterFactory; /** * @author Vincent Siveton * */ -public class XmlWriterUtilTest - extends TestCase -{ +public class XmlWriterUtilTest extends TestCase { private OutputStream output; private Writer writer; @@ -42,14 +39,12 @@ public class XmlWriterUtilTest private XMLWriter xmlWriter; /** {@inheritDoc} */ - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); output = new ByteArrayOutputStream(); - writer = WriterFactory.newXmlWriter( output ); - xmlWriter = new PrettyPrintXMLWriter( writer ); + writer = WriterFactory.newXmlWriter(output); + xmlWriter = new PrettyPrintXMLWriter(writer); } /** @@ -57,12 +52,10 @@ protected void setUp() * * @throws Exception if any */ - public void testWriteLineBreakXMLWriter() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter ); + public void testWriteLineBreakXMLWriter() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter); writer.close(); - assertEquals( 1, StringUtils.countMatches( output.toString(), "\r\n" ) ); + assertEquals(1, StringUtils.countMatches(output.toString(), "\r\n")); } /** @@ -70,12 +63,10 @@ public void testWriteLineBreakXMLWriter() * * @throws Exception if any */ - public void testWriteLineBreakXMLWriterInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10 ); + public void testWriteLineBreakXMLWriterInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10); writer.close(); - assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) ); + assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n")); } /** @@ -83,14 +74,14 @@ public void testWriteLineBreakXMLWriterInt() * * @throws Exception if any */ - public void testWriteLineBreakXMLWriterIntInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2 ); + public void testWriteLineBreakXMLWriterIntInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2); writer.close(); - assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) ); - assertEquals( 1, StringUtils.countMatches( output.toString(), StringUtils - .repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ) ) ); + assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n")); + assertEquals( + 1, + StringUtils.countMatches( + output.toString(), StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE))); } /** @@ -98,13 +89,11 @@ public void testWriteLineBreakXMLWriterIntInt() * * @throws Exception if any */ - public void testWriteLineBreakXMLWriterIntIntInt() - throws Exception - { - XmlWriterUtil.writeLineBreak( xmlWriter, 10, 2, 4 ); + public void testWriteLineBreakXMLWriterIntIntInt() throws Exception { + XmlWriterUtil.writeLineBreak(xmlWriter, 10, 2, 4); writer.close(); - assertEquals( 10, StringUtils.countMatches( output.toString(), "\r\n" ) ); - assertEquals( 1, StringUtils.countMatches( output.toString(), StringUtils.repeat( " ", 2 * 4 ) ) ); + assertEquals(10, StringUtils.countMatches(output.toString(), "\r\n")); + assertEquals(1, StringUtils.countMatches(output.toString(), StringUtils.repeat(" ", 2 * 4))); } /** @@ -112,15 +101,14 @@ public void testWriteLineBreakXMLWriterIntIntInt() * * @throws Exception if any */ - public void testWriteCommentLineBreakXMLWriter() - throws Exception - { - XmlWriterUtil.writeCommentLineBreak( xmlWriter ); + public void testWriteCommentLineBreakXMLWriter() throws Exception { + XmlWriterUtil.writeCommentLineBreak(xmlWriter); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()); } /** @@ -128,18 +116,16 @@ public void testWriteCommentLineBreakXMLWriter() * * @throws Exception if any */ - public void testWriteCommentLineBreakXMLWriterInt() - throws Exception - { - XmlWriterUtil.writeCommentLineBreak( xmlWriter, 20 ); + public void testWriteCommentLineBreakXMLWriterInt() throws Exception { + XmlWriterUtil.writeCommentLineBreak(xmlWriter, 20); writer.close(); - assertEquals( output.toString(), "" + "\r\n" ); + assertEquals(output.toString(), "" + "\r\n"); } public void testWriteCommentLineBreak() throws IOException { - XmlWriterUtil.writeCommentLineBreak( xmlWriter, 10 ); + XmlWriterUtil.writeCommentLineBreak(xmlWriter, 10); writer.close(); - assertEquals( output.toString(), output.toString(), "" + "\r\n" ); + assertEquals(output.toString(), output.toString(), "" + "\r\n"); } /** @@ -147,37 +133,37 @@ public void testWriteCommentLineBreak() throws IOException { * * @throws Exception if any */ - public void testWriteCommentXMLWriterString() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "hello" ); + public void testWriteCommentXMLWriterString() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, "hello"); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()); } - public void testWriteComment() throws IOException { - XmlWriterUtil.writeComment( xmlWriter, - "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" ); + XmlWriterUtil.writeComment( + xmlWriter, "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "" ) - .append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE ); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() >= XmlWriterUtil.DEFAULT_COLUMN_LINE); } - + public void testWriteComment_2() throws IOException { - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld" ); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld"); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) ); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length())); } /** @@ -185,33 +171,36 @@ public void testWriteComment_2() throws IOException { * * @throws Exception if any */ - public void testWriteCommentXMLWriterStringInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ); + public void testWriteCommentXMLWriterStringInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 - * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ); - + sb.append(indent); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals( + output.toString().length(), + XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); } - + public void testWriteComment_3() throws IOException { - String indent = StringUtils.repeat( " ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE ); - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2 ); + String indent = StringUtils.repeat(" ", 2 * XmlWriterUtil.DEFAULT_INDENTATION_SIZE); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( "\r\n" ); - sb.append( indent ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) + 2 * indent.length() ); + sb.append(indent); + sb.append("") + .append("\r\n"); + sb.append(indent); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals( + output.toString().length(), + 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * indent.length()); } /** @@ -219,32 +208,33 @@ public void testWriteComment_3() throws IOException { * * @throws Exception if any */ - public void testWriteCommentXMLWriterStringIntInt() - throws Exception - { - String repeat = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentXMLWriterStringIntInt() throws Exception { + String repeat = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( repeat ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * 4 ); + sb.append(repeat); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() + 2 * 4); } - - + public void testWriteCommentXMLWriterStringIntInt_2() throws IOException { - String repeat = StringUtils.repeat( " ", 2 * 4 ); - XmlWriterUtil.writeComment( xmlWriter, "hello\nworld", 2, 4 ); + String repeat = StringUtils.repeat(" ", 2 * 4); + XmlWriterUtil.writeComment(xmlWriter, "hello\nworld", 2, 4); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( repeat ); - sb.append( "" ).append( "\r\n" ); - sb.append( repeat ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 2 * ( XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length() ) + 2 * repeat.length() ); + sb.append(repeat); + sb.append("") + .append("\r\n"); + sb.append(repeat); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() + == 2 * (XmlWriterUtil.DEFAULT_COLUMN_LINE - 1 + "\r\n".length()) + 2 * repeat.length()); } /** @@ -252,30 +242,27 @@ public void testWriteCommentXMLWriterStringIntInt_2() throws IOException { * * @throws Exception if any */ - public void testWriteCommentXMLWriterStringIntIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentXMLWriterStringIntIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 50 ); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 50); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() == 50 - 1 + "\r\n".length() + 2 * 4 ); + sb.append(indent); + sb.append("").append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() == 50 - 1 + "\r\n".length() + 2 * 4); } - - public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException - { - String indent = StringUtils.repeat( " ", 2 * 4 ); - XmlWriterUtil.writeComment( xmlWriter, "hello", 2, 4, 10 ); + + public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException { + String indent = StringUtils.repeat(" ", 2 * 4); + XmlWriterUtil.writeComment(xmlWriter, "hello", 2, 4, 10); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( indent ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertTrue( output.toString().length() >= 10 + 2 * 4 ); + sb.append(indent); + sb.append("").append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertTrue(output.toString().length() >= 10 + 2 * 4); } /** @@ -283,71 +270,81 @@ public void testWriteCommentXMLWriterStringIntIntInt_2() throws IOException * * @throws Exception if any */ - public void testWriteCommentTextXMLWriterStringInt() - throws Exception - { - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 0 ); + public void testWriteCommentTextXMLWriterStringInt() throws Exception { + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 0); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - sb.append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), 3 * ( 80 - 1 + "\r\n".length() ) + 2 * "\r\n".length() ); + sb.append("\r\n"); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + sb.append("\r\n"); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 2 * "\r\n".length()); } - + public void testWriteCommentTextXMLWriterStringInt_2() throws IOException { - String indent = StringUtils.repeat( " ", 2 * 2 ); + String indent = StringUtils.repeat(" ", 2 * 2); - XmlWriterUtil.writeCommentText( xmlWriter, "hello world with end of line\n and " - + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", 2 ); + XmlWriterUtil.writeCommentText( + xmlWriter, + "hello world with end of line\n and " + + "loooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnnnnnnnong line", + 2); writer.close(); StringBuffer sb = new StringBuffer(); - sb.append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( "\r\n" ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); + sb.append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append("\r\n"); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); } - /** * Test method for {@link org.apache.maven.shared.utils.xml.XmlWriterUtil#writeCommentText(XMLWriter, java.lang.String, int, int)}. * * @throws Exception if any */ - public void testWriteCommentTextXMLWriterStringIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentTextXMLWriterStringIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4 ); + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( indent ).append( "" ) - .append( "\r\n" ); - sb.append( "\r\n" ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), 3 * ( 80 - 1 + "\r\n".length() ) + 4 * 2 * 4 + 2 * "\r\n".length() ); + sb.append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append("\r\n"); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), 3 * (80 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length()); } /** @@ -355,22 +352,26 @@ public void testWriteCommentTextXMLWriterStringIntInt() * * @throws Exception if any */ - public void testWriteCommentTextXMLWriterStringIntIntInt() - throws Exception - { - String indent = StringUtils.repeat( " ", 2 * 4 ); + public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception { + String indent = StringUtils.repeat(" ", 2 * 4); - XmlWriterUtil.writeCommentText( xmlWriter, "hello", 2, 4, 50 ); + XmlWriterUtil.writeCommentText(xmlWriter, "hello", 2, 4, 50); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "\r\n" ); - sb.append( indent ).append( "" ).append( "\r\n" ); - sb.append( indent ).append( "" ).append( "\r\n" ); - sb.append( indent ).append( "" ).append( "\r\n" ); - sb.append( "\r\n" ); - sb.append( indent ); - assertEquals( output.toString(), sb.toString() ); - assertEquals( output.toString().length(), 3 * ( 50 - 1 + "\r\n".length() ) + 4 * 2 * 4 + 2 * "\r\n".length() ); + sb.append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append(indent) + .append("") + .append("\r\n"); + sb.append("\r\n"); + sb.append(indent); + assertEquals(output.toString(), sb.toString()); + assertEquals(output.toString().length(), 3 * (50 - 1 + "\r\n".length()) + 4 * 2 * 4 + 2 * "\r\n".length()); } /** @@ -378,14 +379,13 @@ public void testWriteCommentTextXMLWriterStringIntIntInt() * * @throws Exception if any */ - public void testWriteCommentNull() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, null ); + public void testWriteCommentNull() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, null); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); } /** @@ -393,14 +393,13 @@ public void testWriteCommentNull() * * @throws Exception if any */ - public void testWriteCommentShort() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "This is a short text" ); + public void testWriteCommentShort() throws Exception { + XmlWriterUtil.writeComment(xmlWriter, "This is a short text"); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); } /** @@ -408,18 +407,22 @@ public void testWriteCommentShort() * * @throws Exception if any */ - public void testWriteCommentLong() - throws Exception - { - XmlWriterUtil.writeComment( xmlWriter, "Maven is a software project management and comprehension tool. " - + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " - + "and documentation from a central piece of information." ); + public void testWriteCommentLong() throws Exception { + XmlWriterUtil.writeComment( + xmlWriter, + "Maven is a software project management and comprehension tool. " + + "Based on the concept of a project object model (POM), Maven can manage a project's build, reporting " + + "and documentation from a central piece of information."); writer.close(); StringBuilder sb = new StringBuilder(); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - sb.append( "" ).append( "\r\n" ); - assertEquals( output.toString(), sb.toString() ); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + sb.append("") + .append("\r\n"); + assertEquals(output.toString(), sb.toString()); } } diff --git a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java index cef681e5..ab921d14 100644 --- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; -import org.junit.Assert; -import org.junit.Test; +package org.apache.maven.shared.utils.xml; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -31,176 +26,159 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; +import org.apache.maven.shared.utils.xml.pull.XmlPullParserException; +import org.junit.Assert; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - /** * @author Kristian Rosenvold */ -public class Xpp3DomBuilderTest -{ +public class Xpp3DomBuilderTest { private static final String XML_DECLARATION = "\n"; @Test - public void selfClosingTag() - throws Exception - { + public void selfClosingTag() throws Exception { String domString = selfClosingTagSource(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ) ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString)); String expected = expectedSelfClosingTag(); String dom1Str = dom.toString(); - assertEquals( "check DOMs match", expected, dom1Str ); + assertEquals("check DOMs match", expected, dom1Str); } @Test - public void testUnrecognizedEncoding() - { + public void testUnrecognizedEncoding() { byte[] data = "".getBytes(StandardCharsets.UTF_8); - InputStream in = new ByteArrayInputStream( data ); + InputStream in = new ByteArrayInputStream(data); try { - Xpp3DomBuilder.build( in , "nosuch encoding" ); + Xpp3DomBuilder.build(in, "nosuch encoding"); fail(); - } catch ( XmlPullParserException expected ) { - assertTrue( expected.getCause() instanceof UnsupportedEncodingException ); + } catch (XmlPullParserException expected) { + assertTrue(expected.getCause() instanceof UnsupportedEncodingException); } - } - @Test - public void trimming() - throws Exception - { + public void trimming() throws Exception { String domString = createDomString(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( domString ), true ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true); - assertEquals( "element1value", dom.getChild( "element1" ).getValue() ); + assertEquals("element1value", dom.getChild("element1").getValue()); - assertEquals( " preserve space ", dom.getChild( "element6" ).getValue() ); + assertEquals(" preserve space ", dom.getChild("element6").getValue()); - dom = Xpp3DomBuilder.build( new StringReader( domString ), false ); + dom = Xpp3DomBuilder.build(new StringReader(domString), false); - assertEquals( " element1value\n ", dom.getChild( "element1" ).getValue() ); + assertEquals(" element1value\n ", dom.getChild("element1").getValue()); - assertEquals( " preserve space ", dom.getChild( "element6" ).getValue() ); + assertEquals(" preserve space ", dom.getChild("element6").getValue()); } @Test - public void testMalformedXml() - { + public void testMalformedXml() { try { - Xpp3DomBuilder.build( new StringReader( "" + createDomString() ) ); - fail( "We're supposed to fail" ); + Xpp3DomBuilder.build(new StringReader("" + createDomString())); + fail("We're supposed to fail"); } catch (XmlPullParserException ex) { - Assert.assertNotNull( ex.getMessage() ); + Assert.assertNotNull(ex.getMessage()); } } @Test - public void attributeEscaping() - throws IOException, XmlPullParserException - { + public void attributeEscaping() throws IOException, XmlPullParserException { String s = getAttributeEncodedString(); - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( s ) ); + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s)); - assertEquals( "", dom.getChild( "el" ).getAttribute( "att" ) ); + assertEquals("", dom.getChild("el").getAttribute("att")); StringWriter w = new StringWriter(); - Xpp3DomWriter.write( w, dom ); + Xpp3DomWriter.write(w, dom); String newString = w.toString(); - assertEquals( newString, s ); + assertEquals(newString, s); } @Test - public void contentEscaping() - throws IOException, XmlPullParserException - { - Xpp3Dom dom = Xpp3DomBuilder.build( new StringReader( getEncodedString() ) ); + public void contentEscaping() throws IOException, XmlPullParserException { + Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString())); - assertEquals( "\"msg\"", dom.getChild( "a1" ).getValue() ); - assertEquals( "\"msg\"", dom.getChild( "a2" ).getValue() ); - assertEquals( "\"msg\"", dom.getChild( "a3" ).getValue() ); + assertEquals("\"msg\"", dom.getChild("a1").getValue()); + assertEquals("\"msg\"", dom.getChild("a2").getValue()); + assertEquals("\"msg\"", dom.getChild("a3").getValue()); StringWriter w = new StringWriter(); - Xpp3DomWriter.write( w, dom ); - assertEquals( getExpectedString(), w.toString() ); + Xpp3DomWriter.write(w, dom); + assertEquals(getExpectedString(), w.toString()); } - private static String getAttributeEncodedString() - { + private static String getAttributeEncodedString() { StringBuilder domString = new StringBuilder(); - domString.append( "" ); - domString.append( "\n" ); - domString.append( " bar" ); - domString.append( "\n" ); - domString.append( "" ); + domString.append(""); + domString.append("\n"); + domString.append(" bar"); + domString.append("\n"); + domString.append(""); return domString.toString(); } - private static String getEncodedString() - { + private static String getEncodedString() { StringBuilder domString = new StringBuilder(); - domString.append( "\n" ); - domString.append( " \"msg\"\n" ); - domString.append( " \"msg\"]]>\n" ); - domString.append( " <b>"msg"</b>\n" ); - domString.append( "" ); + domString.append("\n"); + domString.append(" \"msg\"\n"); + domString.append(" \"msg\"]]>\n"); + domString.append(" <b>"msg"</b>\n"); + domString.append(""); return domString.toString(); } - private static String getExpectedString() - { + private static String getExpectedString() { StringBuilder domString = new StringBuilder(); - domString.append( "" ); - domString.append( "\n" ); - domString.append( " \"msg\"" ); - domString.append( "\n" ); - domString.append( " <b>\"msg\"</b>" ); - domString.append( "\n" ); - domString.append( " <b>\"msg\"</b>" ); - domString.append( "\n" ); - domString.append( "" ); + domString.append(""); + domString.append("\n"); + domString.append(" \"msg\""); + domString.append("\n"); + domString.append(" <b>\"msg\"</b>"); + domString.append("\n"); + domString.append(" <b>\"msg\"</b>"); + domString.append("\n"); + domString.append(""); return domString.toString(); } - private static String createDomString() - { + private static String createDomString() { StringBuilder buf = new StringBuilder(); - buf.append( "\n" ); - buf.append( " element1value\n \n" ); - buf.append( " \n" ); - buf.append( " element3value\n" ); - buf.append( " \n" ); - buf.append( " \n" ); - buf.append( " \n" ); - buf.append( " preserve space \n" ); - buf.append( "\n" ); + buf.append("\n"); + buf.append(" element1value\n \n"); + buf.append(" \n"); + buf.append(" element3value\n"); + buf.append(" \n"); + buf.append(" \n"); + buf.append(" \n"); + buf.append(" preserve space \n"); + buf.append("\n"); return buf.toString(); } - private static String selfClosingTagSource() - { + private static String selfClosingTagSource() { StringBuilder buf = new StringBuilder(); - buf.append( "\n" ); - buf.append( " \n" ); - buf.append( " \n" ); - buf.append( "" ); + buf.append("\n"); + buf.append(" \n"); + buf.append(" \n"); + buf.append(""); return buf.toString(); } - private static String expectedSelfClosingTag() - { + private static String expectedSelfClosingTag() { return XML_DECLARATION + selfClosingTagSource(); } - } diff --git a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java index 3d594bf8..fb8315d2 100644 --- a/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java +++ b/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.utils.xml.pull; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,12 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.utils.xml.pull; import java.io.IOException; import java.io.StringReader; + import org.apache.maven.shared.utils.xml.Xpp3Dom; import org.apache.maven.shared.utils.xml.Xpp3DomBuilder; - import org.junit.Test; import static org.apache.maven.shared.utils.xml.Xpp3Dom.mergeXpp3Dom; @@ -32,242 +31,208 @@ /** * @author Kristian Rosenvold */ -public class Xpp3DomTest -{ +public class Xpp3DomTest { - private Xpp3Dom createElement( String element, String value ) - { - Xpp3Dom t1s1 = new Xpp3Dom( element ); - t1s1.setValue( value ); + private Xpp3Dom createElement(String element, String value) { + Xpp3Dom t1s1 = new Xpp3Dom(element); + t1s1.setValue(value); return t1s1; } - @Test - public void mergePrecedenceSelfClosed() - throws XmlPullParserException, IOException - { - Xpp3Dom parentConfig = build( "" ); - Xpp3Dom childConfig = build( "ooopise" ); - - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig ); - Xpp3Dom items = result.getChild( "items" ); - - assertEquals( 1, items.getChildCount() ); - Xpp3Dom item = items.getChild( 0 ); - assertEquals( "ooopise", item.getValue() ); + public void mergePrecedenceSelfClosed() throws XmlPullParserException, IOException { + Xpp3Dom parentConfig = build(""); + Xpp3Dom childConfig = build("ooopise"); + + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig); + Xpp3Dom items = result.getChild("items"); + + assertEquals(1, items.getChildCount()); + Xpp3Dom item = items.getChild(0); + assertEquals("ooopise", item.getValue()); } @Test - public void mergePrecedenceOpenClose() - throws XmlPullParserException, IOException - { - Xpp3Dom parentConfig = build( "" ); - Xpp3Dom childConfig = build( "ooopise" ); - - Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( childConfig, parentConfig ); - Xpp3Dom items = result.getChild( "items" ); - - assertEquals( 1, items.getChildCount() ); - Xpp3Dom item = items.getChild( 0 ); - assertEquals( "ooopise", item.getValue() ); + public void mergePrecedenceOpenClose() throws XmlPullParserException, IOException { + Xpp3Dom parentConfig = build(""); + Xpp3Dom childConfig = build("ooopise"); + + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom(childConfig, parentConfig); + Xpp3Dom items = result.getChild("items"); + + assertEquals(1, items.getChildCount()); + Xpp3Dom item = items.getChild(0); + assertEquals("ooopise", item.getValue()); } @Test - public void selfOverrideOnRootNode() - { + public void selfOverrideOnRootNode() { // Todo: This does not work when loaded. Probably a bug related to null vs "" handling // Xpp3Dom t1 = build( "" ); - Xpp3Dom t1 = new Xpp3Dom( "top" ); - t1.setAttribute( "attr", "value" ); + Xpp3Dom t1 = new Xpp3Dom("top"); + t1.setAttribute("attr", "value"); - t1.setAttribute( Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE ); + t1.setAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.SELF_COMBINATION_OVERRIDE); - Xpp3Dom t2 = build( "val2" ); - Xpp3Dom result = mergeXpp3Dom( t1, t2 ); + Xpp3Dom t2 = build("val2"); + Xpp3Dom result = mergeXpp3Dom(t1, t2); - assertEquals( 2, result.getAttributeNames().length ); - assertNull( result.getValue() ); + assertEquals(2, result.getAttributeNames().length); + assertNull(result.getValue()); } @Test - public void mergeValuesOnRootNode() - { - Xpp3Dom t1 = build( "" ); - Xpp3Dom t2 = build( "t2Val" ); - Xpp3Dom result = mergeXpp3Dom( t1, t2 ); - assertEquals( 2, result.getAttributeNames().length ); - assertEquals( result.getValue(), t2.getValue() ); + public void mergeValuesOnRootNode() { + Xpp3Dom t1 = build(""); + Xpp3Dom t2 = build("t2Val"); + Xpp3Dom result = mergeXpp3Dom(t1, t2); + assertEquals(2, result.getAttributeNames().length); + assertEquals(result.getValue(), t2.getValue()); } @Test - public void mergeAttributesOnRootNode() - { - Xpp3Dom t1 = build( "" ); - Xpp3Dom t2 = build( "" ); + public void mergeAttributesOnRootNode() { + Xpp3Dom t1 = build(""); + Xpp3Dom t2 = build(""); - Xpp3Dom dom = mergeXpp3Dom( t1, t2 ); - assertEquals( 3, dom.getAttributeNames().length ); + Xpp3Dom dom = mergeXpp3Dom(t1, t2); + assertEquals(3, dom.getAttributeNames().length); } @Test - public void combineAppend() - { - Xpp3Dom t1 = new Xpp3Dom( "root" ); - t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND ); - t1.addChild( createElement( "sub", "s1Value" ) ); + public void combineAppend() { + Xpp3Dom t1 = new Xpp3Dom("root"); + t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); + t1.addChild(createElement("sub", "s1Value")); - Xpp3Dom t2 = new Xpp3Dom( "root" ); - t2.addChild( createElement( "sub", "s1Value" ) ); + Xpp3Dom t2 = new Xpp3Dom("root"); + t2.addChild(createElement("sub", "s1Value")); - Xpp3Dom result = mergeXpp3Dom( t1, t2 ); + Xpp3Dom result = mergeXpp3Dom(t1, t2); - assertEquals( 2, result.getChildren( "sub" ).length ); + assertEquals(2, result.getChildren("sub").length); } @Test - public void mergeOverride() - { - Xpp3Dom t1 = new Xpp3Dom( "root" ); - t1.setAttribute( Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND ); - t1.addChild( createElement( "sub", "s1Value" ) ); + public void mergeOverride() { + Xpp3Dom t1 = new Xpp3Dom("root"); + t1.setAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE, Xpp3Dom.CHILDREN_COMBINATION_APPEND); + t1.addChild(createElement("sub", "s1Value")); - Xpp3Dom t2 = new Xpp3Dom( "root" ); - t2.addChild( createElement( "sub", "s1Value" ) ); + Xpp3Dom t2 = new Xpp3Dom("root"); + t2.addChild(createElement("sub", "s1Value")); - Xpp3Dom result = mergeXpp3Dom( t1, t2, Boolean.TRUE ); + Xpp3Dom result = mergeXpp3Dom(t1, t2, Boolean.TRUE); - assertEquals( 1, result.getChildren( "sub" ).length ); + assertEquals(1, result.getChildren("sub").length); } - - @Test( expected = NullPointerException.class ) - public void nullValue() - { + @Test(expected = NullPointerException.class) + public void nullValue() { //noinspection ConstantConditions - new Xpp3Dom( "top" ).setAttribute( null, "value" ); + new Xpp3Dom("top").setAttribute(null, "value"); } - @Test( expected = NullPointerException.class ) - public void nullAttribute() - { + @Test(expected = NullPointerException.class) + public void nullAttribute() { //noinspection ConstantConditions - new Xpp3Dom( "root" ).setAttribute( "attr", null ); + new Xpp3Dom("root").setAttribute("attr", null); } - @Test - public void testEquals() - { - Xpp3Dom dom = new Xpp3Dom( "single" ); - dom.addChild( new Xpp3Dom( "kid" ) ); + public void testEquals() { + Xpp3Dom dom = new Xpp3Dom("single"); + dom.addChild(new Xpp3Dom("kid")); - Xpp3Dom other = new Xpp3Dom( "single" ); - other.addChild( new Xpp3Dom( "kid2" ) ); + Xpp3Dom other = new Xpp3Dom("single"); + other.addChild(new Xpp3Dom("kid2")); - assertEquals( dom, dom ); + assertEquals(dom, dom); //noinspection ObjectEqualsNull - assertFalse( dom.equals( null ) ); - assertFalse( dom.equals( new Xpp3Dom( (String) null ) ) ); - assertFalse( dom.equals( other ) ); + assertFalse(dom.equals(null)); + assertFalse(dom.equals(new Xpp3Dom((String) null))); + assertFalse(dom.equals(other)); } @Test - public void dominantWinsCollections() - throws XmlPullParserException - { - Xpp3Dom parent = build( "unodos" ); - Xpp3Dom dominant = build( "tres" ); + public void dominantWinsCollections() throws XmlPullParserException { + Xpp3Dom parent = build("unodos"); + Xpp3Dom dominant = build("tres"); - Xpp3Dom result = mergeXpp3Dom( dominant, parent ); + Xpp3Dom result = mergeXpp3Dom(dominant, parent); - Xpp3Dom items = result.getChild( "entries" ); - assertEquals( 1, items.getChildCount() ); + Xpp3Dom items = result.getChild("entries"); + assertEquals(1, items.getChildCount()); - assertElemEquals( "tres", items.getChild( 0 ) ); + assertElemEquals("tres", items.getChild(0)); } @Test - public void combineChildrenAppendTest() - throws XmlPullParserException - { + public void combineChildrenAppendTest() throws XmlPullParserException { Xpp3Dom parent = - build( "unodostres" ); - Xpp3Dom child = build( "quatro" ); + build("unodostres"); + Xpp3Dom child = build("quatro"); - Xpp3Dom result = mergeXpp3Dom( child, parent ); + Xpp3Dom result = mergeXpp3Dom(child, parent); - Xpp3Dom items = result.getChild( "entries" ); - assertEquals( 4, items.getChildCount() ); + Xpp3Dom items = result.getChild("entries"); + assertEquals(4, items.getChildCount()); Xpp3Dom[] item = items.getChildren(); - assertElemEquals( "uno", item[0] ); - assertElemEquals( "dos", item[1] ); - assertElemEquals( "tres", item[2] ); - assertElemEquals( "quatro", item[3] ); + assertElemEquals("uno", item[0]); + assertElemEquals("dos", item[1]); + assertElemEquals("tres", item[2]); + assertElemEquals("quatro", item[3]); } @Test - public void unchangedWithFirstOrLastEmpty() - throws Exception - { + public void unchangedWithFirstOrLastEmpty() throws Exception { String configStr = "test"; - Xpp3Dom dominant = build( configStr ); - Xpp3Dom duplicatedDominant = build( configStr ); - validateEntries( dominant ); - Xpp3Dom result = mergeXpp3Dom( dominant, duplicatedDominant ); - validateEntries( result ); + Xpp3Dom dominant = build(configStr); + Xpp3Dom duplicatedDominant = build(configStr); + validateEntries(dominant); + Xpp3Dom result = mergeXpp3Dom(dominant, duplicatedDominant); + validateEntries(result); } - private void validateEntries( Xpp3Dom result ) - { - Xpp3Dom entries = result.getChild( "entries" ); - assertEquals( 3, entries.getChildCount() ); - assertXpp3Null( entries.getChild( 0 ) ); - assertEquals( "test", entries.getChild( 1 ).getValue() ); - assertXpp3Null( entries.getChild( 2 ) ); + private void validateEntries(Xpp3Dom result) { + Xpp3Dom entries = result.getChild("entries"); + assertEquals(3, entries.getChildCount()); + assertXpp3Null(entries.getChild(0)); + assertEquals("test", entries.getChild(1).getValue()); + assertXpp3Null(entries.getChild(2)); } - - static void assertElemEquals( String value, Xpp3Dom element ) - { - assertEquals( value, element.getValue() ); + static void assertElemEquals(String value, Xpp3Dom element) { + assertEquals(value, element.getValue()); } - - void assertXpp3Null( Xpp3Dom entry ) - { + void assertXpp3Null(Xpp3Dom entry) { // Todo: When we used xpp3dom, all methods using this assert used to return null - assertEquals( "", entry.getValue() ); + assertEquals("", entry.getValue()); } @Test - public void recessiveChildrenIncludedWhenDominantEmpty() - throws Exception - { + public void recessiveChildrenIncludedWhenDominantEmpty() throws Exception { String dominant = "bazzy"; String recessive = "barry"; - Xpp3Dom merged = mergeXpp3Dom( build( dominant ), build( recessive ) ); + Xpp3Dom merged = mergeXpp3Dom(build(dominant), build(recessive)); - assertEquals( 2, merged.getChildCount() ); - assertEquals( "bazzy", merged.getChild( "baz" ).getValue() ); - assertEquals( "barry", merged.getChild( "bar" ).getValue() ); + assertEquals(2, merged.getChildCount()); + assertEquals("bazzy", merged.getChild("baz").getValue()); + assertEquals("barry", merged.getChild("bar").getValue()); } - static Xpp3Dom build( String stringContent ) - { - return Xpp3DomBuilder.build( new StringReader( stringContent ) ); + static Xpp3Dom build(String stringContent) { + return Xpp3DomBuilder.build(new StringReader(stringContent)); } @Test - public void duplicatedChildren() - throws IOException, XmlPullParserException - { + public void duplicatedChildren() throws IOException, XmlPullParserException { String dupes = "xy"; - assertEquals( "y", build( dupes ).getChild( "baz" ).getValue() ); + assertEquals("y", build(dupes).getChild("baz").getValue()); } - }