Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Upgrade the dependency on Easymock to 3.2 for maven-shared-io

git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1547777 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 56e570232a0ae933e4427c7d1edcdd2d4cff7420 1 parent 0f216ea
@olamy olamy authored
View
4 maven-shared-io/pom.xml
@@ -107,9 +107,9 @@
</dependency>
<dependency>
- <groupId>easymock</groupId>
+ <groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
- <version>1.2_Java1.3</version>
+ <version>3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
View
58 maven-shared-io/src/test/java/org/apache/maven/shared/io/MockManager.java
@@ -1,58 +0,0 @@
-package org.apache.maven.shared.io;
-
-/*
- * 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 java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.easymock.MockControl;
-
-public class MockManager
-{
-
- private List mockControls = new ArrayList();
-
- public void add( MockControl control )
- {
- mockControls.add( control );
- }
-
- public void replayAll()
- {
- for ( Iterator it = mockControls.iterator(); it.hasNext(); )
- {
- MockControl control = (MockControl) it.next();
-
- control.replay();
- }
- }
-
- public void verifyAll()
- {
- for ( Iterator it = mockControls.iterator(); it.hasNext(); )
- {
- MockControl control = (MockControl) it.next();
-
- control.verify();
- }
- }
-
-}
View
164 maven-shared-io/src/test/java/org/apache/maven/shared/io/download/DefaultDownloadManagerTest.java
@@ -24,7 +24,6 @@
import java.util.Collections;
import org.apache.maven.artifact.manager.WagonManager;
-import org.apache.maven.shared.io.MockManager;
import org.apache.maven.shared.io.TestUtils;
import org.apache.maven.shared.io.logging.DefaultMessageHolder;
import org.apache.maven.shared.io.logging.MessageHolder;
@@ -40,20 +39,15 @@
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusTestCase;
-import org.easymock.MockControl;
+
+import static org.easymock.EasyMock.*;
public class DefaultDownloadManagerTest
extends PlexusTestCase
{
- private MockManager mockManager;
-
- private MockControl wagonManagerControl;
-
private WagonManager wagonManager;
- private MockControl wagonControl;
-
private Wagon wagon;
public void setUp()
@@ -61,17 +55,8 @@ public void setUp()
{
super.setUp();
- mockManager = new MockManager();
-
- wagonManagerControl = MockControl.createControl( WagonManager.class );
- mockManager.add( wagonManagerControl );
-
- wagonManager = (WagonManager) wagonManagerControl.getMock();
-
- wagonControl = MockControl.createControl( Wagon.class );
- mockManager.add( wagonControl );
-
- wagon = (Wagon) wagonControl.getMock();
+ wagonManager = createMock( WagonManager.class );
+ wagon = createMock( Wagon.class );
}
public void testShouldConstructWithNoParamsAndHaveNonNullMessageHolder()
@@ -81,18 +66,11 @@ public void testShouldConstructWithNoParamsAndHaveNonNullMessageHolder()
public void testShouldConstructWithWagonManager()
{
- MockManager mockManager = new MockManager();
-
- MockControl ctl = MockControl.createControl( WagonManager.class );
- mockManager.add( ctl );
-
- WagonManager wagonManager = (WagonManager) ctl.getMock();
-
- mockManager.replayAll();
+ replay( wagonManager );
new DefaultDownloadManager( wagonManager );
- mockManager.verifyAll();
+ verify( wagonManager );
}
public void testShouldLookupInstanceDefaultRoleHint()
@@ -103,14 +81,7 @@ public void testShouldLookupInstanceDefaultRoleHint()
public void testShouldFailToDownloadMalformedURL()
{
- MockManager mockManager = new MockManager();
-
- MockControl ctl = MockControl.createControl( WagonManager.class );
- mockManager.add( ctl );
-
- WagonManager wagonManager = (WagonManager) ctl.getMock();
-
- mockManager.replayAll();
+ replay( wagonManager );
DownloadManager mgr = new DefaultDownloadManager( wagonManager );
@@ -125,7 +96,7 @@ public void testShouldFailToDownloadMalformedURL()
assertTrue( e.getMessage().indexOf( "invalid URL" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagonManager );
}
public void testShouldDownloadFromTempFileWithNoTransferListeners()
@@ -136,13 +107,13 @@ public void testShouldDownloadFromTempFileWithNoTransferListeners()
setupDefaultMockConfiguration();
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
downloadManager.download( tempFile.toURL().toExternalForm(), new DefaultMessageHolder() );
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldDownloadFromTempFileTwiceAndUseCache()
@@ -153,7 +124,7 @@ public void testShouldDownloadFromTempFileTwiceAndUseCache()
setupDefaultMockConfiguration();
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -167,7 +138,7 @@ public void testShouldDownloadFromTempFileTwiceAndUseCache()
assertEquals( 1, mh.size() );
assertTrue( mh.render().indexOf( "Using cached" ) > -1 );
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldDownloadFromTempFileWithOneTransferListener()
@@ -178,23 +149,20 @@ public void testShouldDownloadFromTempFileWithOneTransferListener()
setupDefaultMockConfiguration();
- MockControl transferListenerControl = MockControl.createControl( TransferListener.class );
- mockManager.add( transferListenerControl );
-
- TransferListener transferListener = (TransferListener) transferListenerControl.getMock();
+ TransferListener transferListener = createMock( TransferListener.class );
wagon.addTransferListener( transferListener );
wagon.removeTransferListener( transferListener );
- mockManager.replayAll();
+ replay( wagon, wagonManager, transferListener );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
downloadManager.download( tempFile.toURL().toExternalForm(), Collections.singletonList( transferListener ),
new DefaultMessageHolder() );
- mockManager.verifyAll();
+ verify( wagon, wagonManager, transferListener );
}
public void testShouldFailToDownloadWhenWagonProtocolNotFound()
@@ -205,7 +173,7 @@ public void testShouldFailToDownloadWhenWagonProtocolNotFound()
setupMocksWithWagonManagerGetException( new UnsupportedProtocolException( "not supported" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -220,7 +188,7 @@ public void testShouldFailToDownloadWhenWagonProtocolNotFound()
assertTrue( TestUtils.toString( e ).indexOf( "UnsupportedProtocolException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonConnectThrowsConnectionException()
@@ -231,7 +199,7 @@ public void testShouldFailToDownloadWhenWagonConnectThrowsConnectionException()
setupMocksWithWagonConnectionException( new ConnectionException( "connect error" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -246,7 +214,7 @@ public void testShouldFailToDownloadWhenWagonConnectThrowsConnectionException()
assertTrue( TestUtils.toString( e ).indexOf( "ConnectionException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonConnectThrowsAuthenticationException()
@@ -257,7 +225,7 @@ public void testShouldFailToDownloadWhenWagonConnectThrowsAuthenticationExceptio
setupMocksWithWagonConnectionException( new AuthenticationException( "bad credentials" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -272,7 +240,7 @@ public void testShouldFailToDownloadWhenWagonConnectThrowsAuthenticationExceptio
assertTrue( TestUtils.toString( e ).indexOf( "AuthenticationException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonGetThrowsTransferFailedException()
@@ -283,7 +251,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsTransferFailedException()
setupMocksWithWagonGetException( new TransferFailedException( "bad transfer" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -298,7 +266,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsTransferFailedException()
assertTrue( TestUtils.toString( e ).indexOf( "TransferFailedException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonGetThrowsResourceDoesNotExistException()
@@ -309,7 +277,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsResourceDoesNotExistExcept
setupMocksWithWagonGetException( new ResourceDoesNotExistException( "bad resource" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -324,7 +292,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsResourceDoesNotExistExcept
assertTrue( TestUtils.toString( e ).indexOf( "ResourceDoesNotExistException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonGetThrowsAuthorizationException()
@@ -335,7 +303,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsAuthorizationException()
setupMocksWithWagonGetException( new AuthorizationException( "bad transfer" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -350,7 +318,7 @@ public void testShouldFailToDownloadWhenWagonGetThrowsAuthorizationException()
assertTrue( TestUtils.toString( e ).indexOf( "AuthorizationException" ) > -1 );
}
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
public void testShouldFailToDownloadWhenWagonDisconnectThrowsConnectionException()
@@ -361,7 +329,7 @@ public void testShouldFailToDownloadWhenWagonDisconnectThrowsConnectionException
setupMocksWithWagonDisconnectException( new ConnectionException( "not connected" ) );
- mockManager.replayAll();
+ replay( wagon, wagonManager );
DownloadManager downloadManager = new DefaultDownloadManager( wagonManager );
@@ -371,33 +339,27 @@ public void testShouldFailToDownloadWhenWagonDisconnectThrowsConnectionException
assertTrue( mh.render().indexOf( "ConnectionException" ) > -1 );
- mockManager.verifyAll();
+ verify( wagon, wagonManager );
}
private void setupDefaultMockConfiguration()
{
try
{
- wagonManager.getWagon( "file" );
- wagonManagerControl.setReturnValue( wagon );
+ expect( wagonManager.getWagon( "file" ) ).andReturn( wagon );
}
catch ( UnsupportedProtocolException e )
{
fail( "This shouldn't happen!!" );
}
- wagonManager.getAuthenticationInfo( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getAuthenticationInfo( anyString() ) ).andReturn( null );
- wagonManager.getProxy( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getProxy( anyString() ) ).andReturn( null );
try
{
- wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ wagon.connect( anyObject( Repository.class ) , anyObject( AuthenticationInfo.class ), anyObject( ProxyInfo.class ) );
}
catch ( ConnectionException e )
{
@@ -410,8 +372,7 @@ private void setupDefaultMockConfiguration()
try
{
- wagon.get( "file:///some/path", new File( "." ) );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ wagon.get( anyString(), anyObject( File.class ) );
}
catch ( TransferFailedException e )
{
@@ -440,8 +401,7 @@ private void setupMocksWithWagonManagerGetException( Throwable error )
{
try
{
- wagonManager.getWagon( "file" );
- wagonManagerControl.setThrowable( error );
+ expect( wagonManager.getWagon( "file" ) ).andThrow( error );
}
catch ( UnsupportedProtocolException e )
{
@@ -453,27 +413,21 @@ private void setupMocksWithWagonConnectionException( Throwable error )
{
try
{
- wagonManager.getWagon( "file" );
- wagonManagerControl.setReturnValue( wagon );
+ expect( wagonManager.getWagon( "file" ) ).andReturn( wagon );
}
catch ( UnsupportedProtocolException e )
{
fail( "This shouldn't happen!!" );
}
- wagonManager.getAuthenticationInfo( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getAuthenticationInfo( anyString() ) ).andReturn( null );
- wagonManager.getProxy( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getProxy( anyString() ) ).andReturn( null );
try
{
- wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonControl.setThrowable( error );
+ wagon.connect( anyObject( Repository.class ) , anyObject( AuthenticationInfo.class ), anyObject( ProxyInfo.class ) );
+ expectLastCall().andThrow( error );
}
catch ( ConnectionException e )
{
@@ -489,26 +443,20 @@ private void setupMocksWithWagonGetException( Throwable error )
{
try
{
- wagonManager.getWagon( "file" );
- wagonManagerControl.setReturnValue( wagon );
+ expect( wagonManager.getWagon( "file" ) ).andReturn( wagon );
}
catch ( UnsupportedProtocolException e )
{
fail( "This shouldn't happen!!" );
}
- wagonManager.getAuthenticationInfo( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getAuthenticationInfo( anyString() ) ).andReturn( null );
- wagonManager.getProxy( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getProxy( anyString() ) ).andReturn( null );
try
{
- wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ wagon.connect( anyObject( Repository.class ) , anyObject( AuthenticationInfo.class ), anyObject( ProxyInfo.class ) );
}
catch ( ConnectionException e )
{
@@ -521,9 +469,8 @@ private void setupMocksWithWagonGetException( Throwable error )
try
{
- wagon.get( "file:///some/path", new File( "." ) );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonControl.setThrowable( error );
+ wagon.get( anyString(), anyObject( File.class ) );
+ expectLastCall().andThrow( error );
}
catch ( TransferFailedException e )
{
@@ -552,26 +499,20 @@ private void setupMocksWithWagonDisconnectException( Throwable error )
{
try
{
- wagonManager.getWagon( "file" );
- wagonManagerControl.setReturnValue( wagon );
+ expect( wagonManager.getWagon( "file" ) ).andReturn( wagon );
}
catch ( UnsupportedProtocolException e )
{
fail( "This shouldn't happen!!" );
}
- wagonManager.getAuthenticationInfo( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getAuthenticationInfo( anyString() ) ).andReturn( null );
- wagonManager.getProxy( "" );
- wagonManagerControl.setMatcher( MockControl.ALWAYS_MATCHER );
- wagonManagerControl.setReturnValue( null );
+ expect( wagonManager.getProxy( anyString() ) ).andReturn( null );
try
{
- wagon.connect( new Repository(), new AuthenticationInfo(), new ProxyInfo() );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ wagon.connect( anyObject( Repository.class ) , anyObject( AuthenticationInfo.class ), anyObject( ProxyInfo.class ) );
}
catch ( ConnectionException e )
{
@@ -584,8 +525,7 @@ private void setupMocksWithWagonDisconnectException( Throwable error )
try
{
- wagon.get( "file:///some/path", new File( "." ) );
- wagonControl.setMatcher( MockControl.ALWAYS_MATCHER );
+ wagon.get( anyString(), anyObject( File.class ) );
}
catch ( TransferFailedException e )
{
@@ -603,7 +543,7 @@ private void setupMocksWithWagonDisconnectException( Throwable error )
try
{
wagon.disconnect();
- wagonControl.setThrowable( error );
+ expectLastCall().andThrow( error );
}
catch ( ConnectionException e )
{
View
241 maven-shared-io/src/test/java/org/apache/maven/shared/io/location/ArtifactLocatorStrategyTest.java
@@ -31,68 +31,49 @@
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.shared.io.MockManager;
import org.apache.maven.shared.io.logging.DefaultMessageHolder;
import org.apache.maven.shared.io.logging.MessageHolder;
-import org.easymock.MockControl;
+
+import static org.easymock.EasyMock.*;
public class ArtifactLocatorStrategyTest
extends TestCase
{
- private MockManager mockManager = new MockManager();
-
- private MockControl factoryControl;
-
private ArtifactFactory factory;
- private MockControl resolverControl;
-
private ArtifactResolver resolver;
- private MockControl localRepositoryControl;
-
private ArtifactRepository localRepository;
public void setUp()
{
- factoryControl = MockControl.createControl( ArtifactFactory.class );
- mockManager.add( factoryControl );
-
- factory = (ArtifactFactory) factoryControl.getMock();
-
- resolverControl = MockControl.createControl( ArtifactResolver.class );
- mockManager.add( resolverControl );
-
- resolver = (ArtifactResolver) resolverControl.getMock();
-
- localRepositoryControl = MockControl.createControl( ArtifactRepository.class );
- mockManager.add( localRepositoryControl );
-
- localRepository = (ArtifactRepository) localRepositoryControl.getMock();
+ factory = createMock( ArtifactFactory.class );
+ resolver = createMock( ArtifactResolver.class );
+ localRepository = createMock( ArtifactRepository.class );
}
public void testShouldConstructWithoutDefaultArtifactType()
{
- mockManager.replayAll();
+ replay( factory, resolver, localRepository );
new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository );
}
public void testShouldConstructWithDefaultArtifactType()
{
- mockManager.replayAll();
+ replay( factory, resolver, localRepository );
new ArtifactLocatorStrategy( factory, resolver, localRepository, Collections.EMPTY_LIST, "zip" );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository );
}
public void testShouldFailToResolveSpecWithOneToken()
{
- mockManager.replayAll();
+ replay( factory, resolver, localRepository );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST, "zip" );
@@ -103,12 +84,12 @@ public void testShouldFailToResolveSpecWithOneToken()
assertNull( location );
assertEquals( 1, mh.size() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository );
}
public void testShouldFailToResolveSpecWithTwoTokens()
{
- mockManager.replayAll();
+ replay( factory, resolver, localRepository );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST, "zip" );
@@ -119,7 +100,7 @@ public void testShouldFailToResolveSpecWithTwoTokens()
assertNull( location );
assertEquals( 1, mh.size() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository );
}
public void testShouldResolveSpecWithThreeTokensUsingDefaultType()
@@ -128,17 +109,12 @@ public void testShouldResolveSpecWithThreeTokensUsingDefaultType()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifact( "group", "artifact", "version", null, "jar" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifact( "group", "artifact", "version", null, "jar" ) ).andReturn( artifact );
try
{
@@ -155,7 +131,7 @@ public void testShouldResolveSpecWithThreeTokensUsingDefaultType()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -168,7 +144,7 @@ public void testShouldResolveSpecWithThreeTokensUsingDefaultType()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldResolveSpecWithThreeTokensUsingCustomizedDefaultType()
@@ -177,17 +153,12 @@ public void testShouldResolveSpecWithThreeTokensUsingCustomizedDefaultType()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifact( "group", "artifact", "version", null, "zip" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifact( "group", "artifact", "version", null, "zip" ) ).andReturn( artifact );
try
{
@@ -204,7 +175,7 @@ public void testShouldResolveSpecWithThreeTokensUsingCustomizedDefaultType()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST, "zip" );
@@ -217,7 +188,7 @@ public void testShouldResolveSpecWithThreeTokensUsingCustomizedDefaultType()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldResolveSpecWithFourTokens()
@@ -226,17 +197,12 @@ public void testShouldResolveSpecWithFourTokens()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifact( "group", "artifact", "version", null, "zip" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifact( "group", "artifact", "version", null, "zip" ) ).andReturn( artifact );
try
{
@@ -253,7 +219,7 @@ public void testShouldResolveSpecWithFourTokens()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -266,7 +232,7 @@ public void testShouldResolveSpecWithFourTokens()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldResolveSpecWithFiveTokens()
@@ -275,17 +241,13 @@ public void testShouldResolveSpecWithFiveTokens()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" ) )
+ .andReturn( artifact );
try
{
@@ -302,7 +264,7 @@ public void testShouldResolveSpecWithFiveTokens()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -315,7 +277,7 @@ public void testShouldResolveSpecWithFiveTokens()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldResolveSpecWithFiveTokensAndEmptyTypeToken()
@@ -324,17 +286,13 @@ public void testShouldResolveSpecWithFiveTokensAndEmptyTypeToken()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifactWithClassifier( "group", "artifact", "version", "jar", "classifier" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifactWithClassifier( "group", "artifact", "version", "jar", "classifier" ) )
+ .andReturn( artifact );
try
{
@@ -351,7 +309,7 @@ public void testShouldResolveSpecWithFiveTokensAndEmptyTypeToken()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -364,7 +322,7 @@ public void testShouldResolveSpecWithFiveTokensAndEmptyTypeToken()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldResolveSpecWithMoreThanFiveTokens()
@@ -373,17 +331,13 @@ public void testShouldResolveSpecWithMoreThanFiveTokens()
File tempFile = File.createTempFile( "artifact-location.", ".temp" );
tempFile.deleteOnExit();
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
- artifact.getFile();
- artifactControl.setReturnValue( tempFile );
-
- factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( tempFile );
+ expect( artifact.getFile() ).andReturn( tempFile );
+
+ expect( factory.createArtifactWithClassifier( "group", "artifact", "version", "zip", "classifier" ) )
+ .andReturn( artifact );
try
{
@@ -400,7 +354,7 @@ public void testShouldResolveSpecWithMoreThanFiveTokens()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -415,23 +369,18 @@ public void testShouldResolveSpecWithMoreThanFiveTokens()
assertSame( tempFile, location.getFile() );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldNotResolveSpecToArtifactWithNullFile()
throws IOException
{
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
- artifact.getFile();
- artifactControl.setReturnValue( null );
- artifact.getId();
- artifactControl.setReturnValue( "<some-artifact-id>" );
-
- factory.createArtifact( "group", "artifact", "version", null, "jar" );
- factoryControl.setReturnValue( artifact );
+ Artifact artifact = createMock( Artifact.class );
+
+ expect( artifact.getFile() ).andReturn( null );
+ expect( artifact.getId() ).andReturn( "<some-artifact-id>" );
+
+ expect( factory.createArtifact( "group", "artifact", "version", null, "jar" )).andReturn( artifact );
try
{
@@ -448,7 +397,7 @@ public void testShouldNotResolveSpecToArtifactWithNullFile()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -461,30 +410,25 @@ public void testShouldNotResolveSpecToArtifactWithNullFile()
assertTrue( mh.render().indexOf( "<some-artifact-id>" ) > -1 );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldNotResolveWhenArtifactNotFoundExceptionThrown()
throws IOException
{
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
+ Artifact artifact = createMock( Artifact.class );
- artifact.getId();
- artifactControl.setReturnValue( "<some-artifact-id>" );
+ expect( artifact.getId() ).andReturn( "<some-artifact-id>" );
- factory.createArtifact( "group", "artifact", "version", null, "jar" );
- factoryControl.setReturnValue( artifact );
+ expect( factory.createArtifact( "group", "artifact", "version", null, "jar" ) ).andReturn( artifact );
try
{
resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository );
- resolverControl.setThrowable( new ArtifactNotFoundException( "not found", "group", "artifact", "version",
- "jar", Collections.EMPTY_LIST,
- "http://nowhere.com", Collections.EMPTY_LIST,
- new NullPointerException() ) );
+ expectLastCall().andThrow( new ArtifactNotFoundException( "not found", "group", "artifact", "version",
+ "jar", Collections.EMPTY_LIST,
+ "http://nowhere.com", Collections.EMPTY_LIST,
+ new NullPointerException() ) );
}
catch ( ArtifactResolutionException e )
{
@@ -497,7 +441,7 @@ public void testShouldNotResolveWhenArtifactNotFoundExceptionThrown()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -511,30 +455,25 @@ public void testShouldNotResolveWhenArtifactNotFoundExceptionThrown()
assertTrue( mh.render().indexOf( "<some-artifact-id>" ) > -1 );
assertTrue( mh.render().indexOf( "not found" ) > -1 );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
public void testShouldNotResolveWhenArtifactResolutionExceptionThrown()
throws IOException
{
- MockControl artifactControl = MockControl.createControl( Artifact.class );
- mockManager.add( artifactControl );
-
- Artifact artifact = (Artifact) artifactControl.getMock();
+ Artifact artifact = createMock( Artifact.class );
- artifact.getId();
- artifactControl.setReturnValue( "<some-artifact-id>" );
+ expect( artifact.getId() ).andReturn( "<some-artifact-id>" );
- factory.createArtifact( "group", "artifact", "version", null, "jar" );
- factoryControl.setReturnValue( artifact );
+ expect( factory.createArtifact( "group", "artifact", "version", null, "jar" ) ).andReturn( artifact );
try
{
resolver.resolve( artifact, Collections.EMPTY_LIST, localRepository );
- resolverControl.setThrowable( new ArtifactResolutionException( "resolution failed", "group", "artifact",
- "version", "jar", Collections.EMPTY_LIST,
- Collections.EMPTY_LIST,
- new NullPointerException() ) );
+ expectLastCall().andThrow( new ArtifactResolutionException( "resolution failed", "group", "artifact",
+ "version", "jar", Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST,
+ new NullPointerException() ) );
}
catch ( ArtifactResolutionException e )
{
@@ -547,7 +486,7 @@ public void testShouldNotResolveWhenArtifactResolutionExceptionThrown()
fail( "This should NEVER happen. It's a mock!" );
}
- mockManager.replayAll();
+ replay( factory, resolver, localRepository, artifact );
LocatorStrategy strategy = new ArtifactLocatorStrategy( factory, resolver, localRepository,
Collections.EMPTY_LIST );
@@ -561,7 +500,7 @@ public void testShouldNotResolveWhenArtifactResolutionExceptionThrown()
assertTrue( mh.render().indexOf( "<some-artifact-id>" ) > -1 );
assertTrue( mh.render().indexOf( "resolution failed" ) > -1 );
- mockManager.verifyAll();
+ verify( factory, resolver, localRepository, artifact );
}
}
View
35 maven-shared-io/src/test/java/org/apache/maven/shared/io/location/LocatorTest.java
@@ -23,13 +23,13 @@
import java.util.Collections;
import java.util.List;
-import org.apache.maven.shared.io.MockManager;
import org.apache.maven.shared.io.logging.DefaultMessageHolder;
import org.apache.maven.shared.io.logging.MessageHolder;
-import org.easymock.MockControl;
import junit.framework.TestCase;
+import static org.easymock.EasyMock.*;
+
public class LocatorTest
extends TestCase
{
@@ -61,21 +61,10 @@ public void testShouldRetrieveNonNullMessageHolderWhenConstructedWithoutParams()
public void testSetStrategiesShouldClearAnyPreExistingStrategiesOut()
{
- MockManager mgr = new MockManager();
-
- MockControl originalStrategyControl = MockControl.createControl( LocatorStrategy.class );
-
- mgr.add( originalStrategyControl );
-
- LocatorStrategy originalStrategy = (LocatorStrategy) originalStrategyControl.getMock();
-
- MockControl replacementStrategyControl = MockControl.createControl( LocatorStrategy.class );
+ LocatorStrategy originalStrategy = createMock( LocatorStrategy.class );
+ LocatorStrategy replacementStrategy = createMock( LocatorStrategy.class );
- mgr.add( replacementStrategyControl );
-
- LocatorStrategy replacementStrategy = (LocatorStrategy) replacementStrategyControl.getMock();
-
- mgr.replayAll();
+ replay( originalStrategy, replacementStrategy );
Locator locator = new Locator();
locator.addStrategy( originalStrategy );
@@ -87,20 +76,14 @@ public void testSetStrategiesShouldClearAnyPreExistingStrategiesOut()
assertFalse( strategies.contains( originalStrategy ) );
assertTrue( strategies.contains( replacementStrategy ) );
- mgr.verifyAll();
+ verify( originalStrategy, replacementStrategy );
}
public void testShouldRemovePreviouslyAddedStrategy()
{
- MockManager mgr = new MockManager();
-
- MockControl originalStrategyControl = MockControl.createControl( LocatorStrategy.class );
-
- mgr.add( originalStrategyControl );
-
- LocatorStrategy originalStrategy = (LocatorStrategy) originalStrategyControl.getMock();
+ LocatorStrategy originalStrategy = createMock( LocatorStrategy.class );
- mgr.replayAll();
+ replay( originalStrategy );
Locator locator = new Locator();
locator.addStrategy( originalStrategy );
@@ -115,7 +98,7 @@ public void testShouldRemovePreviouslyAddedStrategy()
assertFalse( strategies.contains( originalStrategy ) );
- mgr.verifyAll();
+ verify( originalStrategy );
}
public void testResolutionFallsThroughStrategyStackAndReturnsNullIfNotResolved()
Please sign in to comment.
Something went wrong with that request. Please try again.