Skip to content

Commit

Permalink
Move to Junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed May 8, 2023
1 parent f541b1a commit dad9f18
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 125 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,29 @@
* limitations under the License.
*/

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.codehaus.plexus.interpolation.os.OperatingSystemUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EnvarBasedValueSourceTest
{

@Before
@BeforeEach
public void setUp()
{
EnvarBasedValueSource.resetStatics();
}

@Test
public void testNoArgConstructorIsCaseSensitive()
void testNoArgConstructorIsCaseSensitive()
throws IOException
{
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
Expand All @@ -58,7 +60,7 @@ public Map<String, String> getEnvMap()
}

@Test
public void testCaseInsensitive()
void testCaseInsensitive()
throws IOException
{
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource()
Expand All @@ -80,7 +82,7 @@ public Map<String, String> getEnvMap()
}

@Test
public void testGetRealEnvironmentVariable()
void testGetRealEnvironmentVariable()
throws IOException
{
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() );
Expand All @@ -90,7 +92,7 @@ public void testGetRealEnvironmentVariable()
String realEnvVar = "JAVA_HOME";

String realValue = System.getenv().get( realEnvVar );
assertNotNull( "Can't run this test until " + realEnvVar + " env variable is set", realValue );
assertNotNull( realValue , "Can't run this test until " + realEnvVar + " env variable is set");

assertEquals( realValue, source.getValue( realEnvVar ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
* SOFTWARE.
*/

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

/**
* InterpolatorFilterReaderTest, heavily based on InterpolationFilterReaderTest. Heh, even the test strings remained the
Expand All @@ -40,12 +42,12 @@
*
*/
public class InterpolatorFilterReaderTest
extends TestCase
{
/*
* Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader.
* kenneyw@15-04-2005 fixed the bug.
*/
@Test
public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken()
throws Exception
{
Expand All @@ -60,6 +62,7 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken()
/*
* kenneyw@14-04-2005 Added test to check above fix.
*/
@Test
public void testShouldNotInterpolateExpressionWithMissingEndToken()
throws Exception
{
Expand All @@ -71,6 +74,7 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken()
assertEquals( "This is a ${test, really", interpolate( testStr, m ) );
}

@Test
public void testShouldNotInterpolateWithMalformedStartToken()
throws Exception
{
Expand All @@ -82,6 +86,7 @@ public void testShouldNotInterpolateWithMalformedStartToken()
assertEquals( "This is a $!test} again", interpolate( foo, m ) );
}

@Test
public void testShouldNotInterpolateWithMalformedEndToken()
throws Exception
{
Expand All @@ -93,6 +98,7 @@ public void testShouldNotInterpolateWithMalformedEndToken()
assertEquals( "This is a ${test!} again", interpolate( foo, m ) );
}

@Test
public void testDefaultInterpolationWithNonInterpolatedValueAtEnd()
throws Exception
{
Expand All @@ -105,6 +111,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd()
assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) );
}

@Test
public void testDefaultInterpolationWithInterpolatedValueAtEnd()
throws Exception
{
Expand All @@ -117,6 +124,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd()
assertEquals( "jason is an asshole", interpolate( foo, m ) );
}

@Test
public void testInterpolationWithInterpolatedValueAtEndWithCustomToken()
throws Exception
{
Expand All @@ -129,6 +137,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomToken()
assertEquals( "jason is an asshole", interpolate( foo, m, "@{", "}" ) );
}

@Test
public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomString()
throws Exception
{
Expand All @@ -141,6 +150,7 @@ public void testInterpolationWithInterpolatedValueAtEndWithCustomTokenAndCustomS
assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) );
}

@Test
public void testEscape()
throws Exception
{
Expand All @@ -153,6 +163,7 @@ public void testEscape()
assertEquals( "jason is an ${noun}", interpolate( foo, m, "\\" ) );
}

@Test
public void testEscapeAtStart()
throws Exception
{
Expand All @@ -165,6 +176,7 @@ public void testEscapeAtStart()
assertEquals( "${name} is an ${noun}", interpolate( foo, m, "\\" ) );
}

@Test
public void testEscapeOnlyAtStart()
throws Exception
{
Expand All @@ -178,6 +190,7 @@ public void testEscapeOnlyAtStart()
assertEquals( "@name@ is an asshole", result );
}

@Test
public void testEscapeOnlyAtStartDefaultToken()
throws Exception
{
Expand All @@ -191,6 +204,7 @@ public void testEscapeOnlyAtStartDefaultToken()
assertEquals( "${name} is an asshole", result );
}

@Test
public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes()
throws Exception
{
Expand Down Expand Up @@ -224,6 +238,7 @@ public void testShouldDetectRecursiveExpressionPassingThroughTwoPrefixes()
assertEquals( input, buf.toString() );
}

@Test
public void testShouldDetectRecursiveExpressionWithPrefixAndWithout()
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Collections;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

public class PrefixAwareRecursionInterceptorTest
extends TestCase
{

@Test
public void testFindExpression()
{
PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
Expand All @@ -42,6 +46,7 @@ public void testFindExpression()
assertFalse( receptor.hasRecursiveExpression( expr ) );
}

@Test
public void testFindExpressionWithDifferentPrefix()
{
PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
Expand All @@ -61,6 +66,7 @@ public void testFindExpressionWithDifferentPrefix()
assertFalse( receptor.hasRecursiveExpression( expr ) );
}

@Test
public void testFindExpressionWithoutPrefix()
{
PrefixAwareRecursionInterceptor receptor = new PrefixAwareRecursionInterceptor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

public class PrefixedObjectValueSourceTest
extends TestCase
{


@Test
public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed()
{
String target = "Target object";
Expand All @@ -39,6 +41,7 @@ public void testEmptyExpressionResultsInNullReturn_NoPrefixUsed()
assertNull( result );
}

@Test
public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot()
{
String target = "Target object";
Expand All @@ -53,6 +56,7 @@ public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithDot()
assertNull( result );
}

@Test
public void testEmptyExpressionResultsInNullReturn_PrefixUsedWithoutDot()
{
String target = "Target object";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Properties;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

public class PrefixedValueSourceWrapperTest
extends TestCase
{

@Test
public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix()
{
String prefix = "prefix.";
Expand All @@ -38,6 +41,7 @@ public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix()
assertEquals( value, wrapper.getValue( prefix + key ) );
}

@Test
public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix()
{
String prefix = "prefix.";
Expand All @@ -53,6 +57,7 @@ public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSing
assertNull( wrapper.getValue( otherPrefix + key ) );
}

@Test
public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix()
{
String prefix = "prefix.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Properties;

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

public class PropertiesBasedValueSourceTest
extends TestCase
{

@Test
public void testPropertyShouldReturnValueFromProperties()
{
Properties props = new Properties();
Expand All @@ -38,6 +41,7 @@ public void testPropertyShouldReturnValueFromProperties()
assertNotNull( vs.getValue( key ) );
}

@Test
public void testPropertyShouldReturnNullWhenPropertyMissing()
{
Properties props = new Properties();
Expand Down
Loading

0 comments on commit dad9f18

Please sign in to comment.