diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java index 18f67a1..b5ab443 100644 --- a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java @@ -22,11 +22,12 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.List; import java.util.Properties; +import org.mockito.ArgumentCaptor; import org.slf4j.Logger; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -34,15 +35,14 @@ /** * @author Olivier Lamy * @since 1.0-beta-1 - * */ public class PropertyUtilsTest - extends TestSupport + extends TestSupport { private static File testDirectory = new File( getBasedir(), "target/test-classes/" ); public void testBasic() - throws Exception + throws Exception { File basicProp = new File( testDirectory, "basic.properties" ); @@ -66,7 +66,7 @@ public void testBasic() } public void testSystemProperties() - throws Exception + throws Exception { File systemProp = new File( testDirectory, "system.properties" ); @@ -87,7 +87,7 @@ public void testSystemProperties() } public void testException() - throws Exception + throws Exception { File nonExistent = new File( testDirectory, "not_existent_file" ); @@ -105,7 +105,7 @@ public void testException() } public void testloadpropertiesFile() - throws Exception + throws Exception { File propertyFile = new File( getBasedir() + "/src/test/units-files/propertyutils-test.properties" ); Properties baseProps = new Properties(); @@ -124,7 +124,7 @@ public void testloadpropertiesFile() * @throws IOException if problem writing file */ public void testCircularReferences() - throws IOException + throws IOException { File basicProp = new File( testDirectory, "circular.properties" ); @@ -134,21 +134,21 @@ public void testCircularReferences() } basicProp.createNewFile(); - try( FileWriter writer = new FileWriter( basicProp ) ) + try ( FileWriter writer = new FileWriter( basicProp ) ) { writer.write( "test=${test2}\n" ); writer.write( "test2=${test2}\n" ); writer.flush(); } - Logger logger = mock(Logger.class); + Logger logger = mock( Logger.class ); Properties prop = PropertyUtils.loadPropertyFile( basicProp, null, logger ); assertEquals( "${test2}", prop.getProperty( "test" ) ); assertEquals( "${test2}", prop.getProperty( "test2" ) ); - verify( logger, times( 2 ) ).warn( anyString() ); - assertWarn( "Circular reference between properties detected: test2 => test2", logger ); - assertWarn( "Circular reference between properties detected: test => test2 => test2", logger ); + assertWarn( logger, + "Circular reference between properties detected: test2 => test2", + "Circular reference between properties detected: test => test2 => test2" ); } /** @@ -157,7 +157,7 @@ public void testCircularReferences() * @throws IOException if problem writing file */ public void testCircularReferences3Vars() - throws IOException + throws IOException { File basicProp = new File( testDirectory, "circular.properties" ); @@ -175,20 +175,26 @@ public void testCircularReferences3Vars() writer.flush(); } - Logger logger = mock(Logger.class); + Logger logger = mock( Logger.class ); Properties prop = PropertyUtils.loadPropertyFile( basicProp, null, logger ); assertEquals( "${test2}", prop.getProperty( "test" ) ); assertEquals( "${test3}", prop.getProperty( "test2" ) ); assertEquals( "${test}", prop.getProperty( "test3" ) ); - verify( logger, times( 3 ) ).warn( anyString() ); - assertWarn( "Circular reference between properties detected: test3 => test => test2 => test3", logger ); - assertWarn( "Circular reference between properties detected: test2 => test3 => test => test2", logger ); - assertWarn( "Circular reference between properties detected: test => test2 => test3 => test", logger ); + assertWarn( logger, + "Circular reference between properties detected: test3 => test => test2 => test3", + "Circular reference between properties detected: test2 => test3 => test => test2", + "Circular reference between properties detected: test => test2 => test3 => test" ); } - private void assertWarn( String expected, Logger mock ) + private void assertWarn( Logger mock, String... expected ) { -// assertTrue( logger.warnMsgs.contains( expected ) ); + ArgumentCaptor argument = ArgumentCaptor.forClass( String.class ); + verify( mock, times( expected.length ) ).warn( argument.capture() ); + List messages = argument.getAllValues(); + for ( String str : expected ) + { + assertTrue( messages.contains( str ) ); + } } }