]> source.dussan.org Git - archiva.git/commitdiff
Unifying mocks to mockito
authorMartin Schreier <martin_s@apache.org>
Tue, 4 Jan 2022 19:46:35 +0000 (20:46 +0100)
committerMartin Schreier <martin_s@apache.org>
Tue, 4 Jan 2022 19:46:35 +0000 (20:46 +0100)
42 files changed:
archiva-modules/archiva-base/archiva-configuration/pom.xml
archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-repository-scanner/pom.xml
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java
archiva-modules/archiva-maven/archiva-maven-indexer/pom.xml
archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/AbstractMavenRepositorySearch.java
archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchOSGITest.java
archiva-modules/archiva-maven/archiva-maven-indexer/src/test/java/org/apache/archiva/maven/indexer/search/MavenRepositorySearchTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/AbstractProxyTestCase.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/CacheFailuresTransferTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ChecksumTransferTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ErrorHandlingTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/ManagedDefaultTransferTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/MetadataTransferTest.java
archiva-modules/archiva-maven/archiva-maven-proxy/src/test/java/org/apache/archiva/maven/proxy/MockConfiguration.java
archiva-modules/archiva-maven/archiva-maven-repository/pom.xml
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/maven/repository/metadata/storage/mock/MockConfiguration.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/utils/ArtifactBuilderTest.java
archiva-modules/archiva-web/archiva-rss/pom.xml
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
archiva-modules/archiva-web/archiva-security/pom.xml
archiva-modules/archiva-web/archiva-security/src/test/java/org/apache/archiva/security/ArchivaServletAuthenticatorTest.java
archiva-modules/archiva-web/archiva-webdav/pom.xml
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java
archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml
archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java
archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/RepositoriesNamespaceTest.java
archiva-modules/plugins/audit/pom.xml
archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
archiva-modules/plugins/repository-statistics/pom.xml
archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
pom.xml

index 0305dbca078b1491edbfd98dba4e58bea364329c..4852451990013d8357f0b2d142b604cea56f4c35 100644 (file)
@@ -81,8 +81,8 @@
       <artifactId>jakarta.annotation-api</artifactId>
     </dependency>
     <dependency>
-       <groupId>jakarta.inject</groupId>
-<artifactId>jakarta.inject-api</artifactId>
+      <groupId>jakarta.inject</groupId>
+      <artifactId>jakarta.inject-api</artifactId>
     </dependency>
 
     <dependency>
 
     <!-- Test scope -->
 
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
-
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-test-utils</artifactId>
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
   <build>
     <plugins>
index 90802a64bbc9e66bad47e769b7de3d77bd73e096..9a882d3e289274896a1aa44976507dc110838dbc 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
@@ -34,14 +35,13 @@ import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
 import java.nio.charset.Charset;
-import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.List;
 
-import static org.easymock.EasyMock.*;
 import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
 
 /**
  * Test the configuration store.
@@ -219,17 +219,13 @@ public class ArchivaConfigurationTest
         configuration.getWebapp().getUi().setAppletFindEnabled( false );
 
         // add a change listener
-        ConfigurationListener listener = createMock( ConfigurationListener.class );
+        ConfigurationListener listener = mock( ConfigurationListener.class );
         archivaConfiguration.addListener( listener );
 
         listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
 
-        replay( listener );
-
         archivaConfiguration.save( configuration );
 
-        verify( listener );
-
         assertTrue( "Check file exists", Files.exists(file) );
 
         // check it
@@ -246,7 +242,7 @@ public class ArchivaConfigurationTest
 
     private static ConfigurationListener createConfigurationListenerMockControl()
     {
-        return createMock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
+        return mock( ConfigurationListener.class );// MockControl.createControl( ConfigurationListener.class );
     }
 
     @Test
@@ -308,12 +304,8 @@ public class ArchivaConfigurationTest
 
         listener.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
 
-        replay( listener );
-
         archivaConfiguration.save( configuration );
 
-        verify( listener );
-
         assertTrue( "Check file exists", Files.exists(userFile) );
         assertFalse( "Check file not created", Files.exists(baseFile) );
 
index c7c69e4289c2940b4b73e05f3a1fc015da34b2c9..752e88dac4f5328593d46272e608a93469b5bcbe 100644 (file)
       <artifactId>spring-test</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.archiva.redback</groupId>
       <artifactId>redback-rbac-jpa</artifactId>
index fa4cee018286f7734bed7eccb46cd9386b8de6be..9dd1d76393df63fb8cb8f541abe11f60c7893122 100644 (file)
@@ -34,11 +34,10 @@ import org.apache.archiva.repository.features.ArtifactCleanupFeature;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runner.RunWith;
+import org.mockito.Mockito;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
 import org.springframework.test.context.ContextConfiguration;
@@ -56,6 +55,7 @@ import java.util.stream.Collectors;
 
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  */
@@ -96,14 +96,10 @@ public abstract class AbstractRepositoryPurgeTest
 
     protected RepositoryPurge repoPurge;
 
-    protected IMocksControl listenerControl;
-
     protected RepositoryListener listener;
 
-    protected IMocksControl sessionControl;
     protected RepositorySession repositorySession;
 
-    protected IMocksControl sessionFactoryControl;
     protected RepositorySessionFactory sessionFactory;
 
     protected MetadataRepository metadataRepository;
@@ -121,18 +117,13 @@ public abstract class AbstractRepositoryPurgeTest
         throws Exception
     {
 
-        listenerControl = EasyMock.createControl();
-
-        listener = listenerControl.createMock( RepositoryListener.class );
-
-        sessionControl = EasyMock.createControl();
-        sessionFactoryControl = EasyMock.createControl( );
+        listener = mock( RepositoryListener.class );
 
-        repositorySession = sessionControl.createMock( RepositorySession.class );
+        repositorySession = mock( RepositorySession.class );
         metadataRepository = mock( MetadataRepository.class );
-        sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
-        EasyMock.expect( repositorySession.getRepository() ).andStubReturn( metadataRepository );
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
+        sessionFactory = mock( RepositorySessionFactory.class );
+        when( repositorySession.getRepository() ).thenReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
 
     }
 
index 8e497dc2c3d8fe552e940a91e2a97be8be0e1282..0a50b3043cb480eaceef9a320f473a9a5a090244 100644 (file)
@@ -30,9 +30,9 @@ import org.apache.archiva.repository.RepositoryContentFactory;
 import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.metadata.audit.RepositoryListener;
 import org.apache.archiva.repository.metadata.base.MetadataTools;
-import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.xmlunit.assertj.XmlAssert;
 
@@ -47,7 +47,7 @@ import java.util.List;
 import java.util.Set;
 
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.*;
 
 
@@ -90,19 +90,12 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         archivaConfiguration =
             applicationContext.getBean( "archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class );
 
-        listenerControl = EasyMock.createControl( );
-
-        listener = listenerControl.createMock( RepositoryListener.class );
+        listener = mock( RepositoryListener.class );
         List<RepositoryListener> listeners = Collections.singletonList( listener );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        Mockito.when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        Mockito.when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
         repoPurge = new CleanupReleasedSnapshotsRepositoryPurge( getRepository(), metadataTools,
                                                                  applicationContext.getBean(
                                                                      ArchivaRepositoryRegistry.class ),
@@ -135,7 +128,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         // test listeners for the correct artifacts
         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
                                  "maven-plugin-plugin", "2.3-SNAPSHOT", "maven-plugin-plugin-2.3-SNAPSHOT.jar" );
-        listenerControl.replay();
 
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -145,8 +137,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         // complete snapshot version removal for released
         verify(metadataRepository, times(1)).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
@@ -209,8 +199,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         String repoRoot = prepareTestRepos();
 
         // test listeners for the correct artifacts
-        listenerControl.replay();
-
         Path file = Paths.get(repoRoot, INDEX_PATH );
         if ( !Files.exists(file) )
         {
@@ -222,8 +210,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
 
         repoPurge.process( INDEX_PATH );
 
-        listenerControl.verify();
-
         assertTrue( Files.exists(file) );
     }
 
@@ -260,8 +246,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.archiva",
                                  "released-artifact-in-diff-repo", "1.0-SNAPSHOT",
                                  "released-artifact-in-diff-repo-1.0-SNAPSHOT.jar" );
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -274,8 +258,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_RELEASED_SNAPSHOT_IN_DIFF_REPO );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         // Complete version removal for cleanup
         verify(metadataRepository, times(1)).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
@@ -331,8 +313,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
         Path vDir3 = repo.resolve(projectPath).resolve(projectName).resolve("2.0.4-SNAPSHOT");
 
         // test listeners for the correct artifacts - no deletions
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -347,8 +327,6 @@ public class CleanupReleasedSnapshotsRepositoryPurgeTest
 
         repoPurge.process( CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_HIGHER_SNAPSHOT_EXISTS_IN_SAME_REPO );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         // No removal
         verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
index 0deb60d6eca4e8b8c7a4892929b06d427fd041b4..62a894f0c6d27a526074cd913a37288e06e6ca7c 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.archiva.consumers.core.repository;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.audit.RepositoryListener;
 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -36,7 +35,7 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.*;
 
 /**
@@ -73,14 +72,9 @@ public class DaysOldRepositoryPurgeTest
         ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
 
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
 
         repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
                                                 atf.getRetentionCount(), repositorySession,
@@ -115,7 +109,6 @@ public class DaysOldRepositoryPurgeTest
                     "maven-install-plugin", "2.2-SNAPSHOT",
                     "maven-install-plugin-2.2-20061118.060401-2.pom"+exts[i]);
         }
-        listenerControl.replay();
 
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -124,8 +117,6 @@ public class DaysOldRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_BY_DAYS_OLD_ARTIFACT );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -175,14 +166,9 @@ public class DaysOldRepositoryPurgeTest
         ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
         List<RepositoryListener> listeners = Collections.singletonList( listener );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
         repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
                                                 atf.getRetentionCount(), repositorySession, listeners );
 
@@ -209,8 +195,6 @@ public class DaysOldRepositoryPurgeTest
                     "maven-assembly-plugin", "1.1.2-SNAPSHOT",
                     "maven-assembly-plugin-1.1.2-20070427.065136-1.pom"+exts[i]);
         }
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts(repositorySession , TEST_REPO_ID,
@@ -219,8 +203,6 @@ public class DaysOldRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -263,14 +245,9 @@ public class DaysOldRepositoryPurgeTest
         ArtifactCleanupFeature atf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
         List<RepositoryListener> listeners = Collections.singletonList( listener );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
         repoPurge = new DaysOldRepositoryPurge( getRepository(), atf.getRetentionPeriod().getDays(),
             atf.getRetentionCount(), repositorySession, listeners );
 
@@ -317,7 +294,6 @@ public class DaysOldRepositoryPurgeTest
             listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.codehaus.plexus", "plexus-utils",
                     "1.4.3-SNAPSHOT", "plexus-utils-1.4.3-20070113.163208-4.pom"+exts[i]);
         }
-        listenerControl.replay();
 
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
@@ -327,8 +303,6 @@ public class DaysOldRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_BY_DAYS_OLD_METADATA_DRIVEN_ARTIFACT );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion(eq(repositorySession) , eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
index 3af6a44b3f99dafbe014844d6d7c239724f48053..e4f42d8ad9c936efc0cd77491acac9b09e43feb9 100644 (file)
@@ -30,7 +30,6 @@ import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
 import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -52,8 +51,8 @@ import java.util.List;
 import java.util.Set;
 
 import static org.junit.Assert.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.*;
 
 /**
@@ -142,7 +141,7 @@ public class RepositoryPurgeConsumerTest
     private void setLastModified( String path ) throws IOException
     {
         Path dir = Paths.get( path );
-        Path[] contents = new Path[0];
+        Path[] contents;
         try
         {
             contents = Files.list( dir ).toArray(Path[]::new);
@@ -152,9 +151,9 @@ public class RepositoryPurgeConsumerTest
             log.error("Could not list files {}: {}", dir, e.getMessage(), e);
             contents = new Path[0];
         }
-        for ( int i = 0; i < contents.length; i++ )
+        for ( Path content : contents )
         {
-            Files.setLastModifiedTime( contents[i], FileTime.fromMillis( 1179382029 ) );
+            Files.setLastModifiedTime( content, FileTime.fromMillis( 1179382029 ) );
         }
     }
 
@@ -172,14 +171,9 @@ public class RepositoryPurgeConsumerTest
         atf.setRetentionCount( TEST_RETENTION_COUNT );
         addRepoToConfiguration( "retention-count", repoConfiguration );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
 
         repoPurgeConsumer.beginScan( repoConfiguration, null );
 
@@ -287,14 +281,9 @@ public class RepositoryPurgeConsumerTest
         atf.setRetentionPeriod( Period.ofDays( TEST_DAYS_OLDER ) );
         addRepoToConfiguration( "days-old", repoConfiguration );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
         repoPurgeConsumer.beginScan( repoConfiguration, null );
 
         String repoRoot = prepareTestRepos();
@@ -402,7 +391,6 @@ public class RepositoryPurgeConsumerTest
             CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
 
         verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
-        ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
         verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
         verify(metadataRepository, never()).removeFacetFromArtifact( eq(repositorySession), any(), any(), any(), any(), any(MetadataFacet.class) );
 
@@ -441,14 +429,9 @@ public class RepositoryPurgeConsumerTest
         acf.setDeleteReleasedSnapshots( true );
         addRepoToConfiguration( "days-old", repoConfiguration );
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
         repoPurgeConsumer.beginScan( repoConfiguration, null );
 
         String repoRoot = prepareTestRepos();
@@ -469,7 +452,6 @@ public class RepositoryPurgeConsumerTest
             CleanupReleasedSnapshotsRepositoryPurgeTest.PATH_TO_RELEASED_SNAPSHOT_IN_SAME_REPO );
 
         verify(metadataRepository, times(1)).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
-        ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
         verify(metadataRepository, never()).removeTimestampedArtifact( eq(repositorySession), any(), any() );
 
         // check if the snapshot was removed
@@ -486,9 +468,6 @@ public class RepositoryPurgeConsumerTest
 
         String metadataXml = org.apache.archiva.common.utils.FileUtils.readFileToString( artifactMetadataFile, Charset.defaultCharset() );
 
-        String expectedVersions =
-            "<expected><versions><version>2.2</version>" + "<version>2.3</version></versions></expected>";
-
         XmlAssert.assertThat( metadataXml ).valueByXPath( "//metadata/versioning/latest" ).isEqualTo( "2.3" );
         // XMLAssert.assertXpathEvaluatesTo( "2.3", "//metadata/versioning/latest", metadataXml );
         XmlAssert.assertThat( metadataXml ).nodesByXPath( "//metadata/versioning/versions/version" ).hasSize( 2 );
index 97afa7b924004ff436334bcf1178163404b6caec..1081380d9f4096ef0c108e9c9c1a10ad61944fac 100644 (file)
@@ -22,11 +22,11 @@ package org.apache.archiva.consumers.core.repository;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.audit.RepositoryListener;
 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
-import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
 
 import java.nio.file.Path;
 import java.util.Collections;
@@ -35,7 +35,7 @@ import java.util.List;
 import java.util.Set;
 
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.*;
 
 /**
@@ -55,14 +55,9 @@ public class RetentionCountRepositoryPurgeTest
         List<RepositoryListener> listeners = Collections.singletonList( listener );
         ArtifactCleanupFeature acf = repoConfiguration.getFeature( ArtifactCleanupFeature.class ).get();
 
-        sessionControl.reset();
-        sessionFactoryControl.reset();
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( repositorySession );
-        EasyMock.expect( repositorySession.getRepository()).andStubReturn( metadataRepository );
+        Mockito.when( sessionFactory.createSession( ) ).thenReturn( repositorySession );
+        Mockito.when( repositorySession.getRepository()).thenReturn( metadataRepository );
         repositorySession.save();
-        EasyMock.expectLastCall().anyTimes();
-        sessionFactoryControl.replay();
-        sessionControl.replay();
 
         repoPurge = new RetentionCountRepositoryPurge( getRepository(), acf.getRetentionCount(),
                                                        repositorySession, listeners );
@@ -122,8 +117,6 @@ public class RetentionCountRepositoryPurgeTest
         listener.deleteArtifact(metadataRepository, getRepository().getId(), "org.jruby.plugins", "jruby-rake-plugin",
                 "1.0RC1-SNAPSHOT", "jruby-rake-plugin-1.0RC1-20070504.153317-1-javadoc.zip");
 
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -132,8 +125,6 @@ public class RetentionCountRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_ARTIFACT );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -209,8 +200,6 @@ public class RetentionCountRepositoryPurgeTest
                 "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom.sha1" );
         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.codehaus.castor", "castor-anttasks",
                                  "1.1.2-SNAPSHOT", "castor-anttasks-1.1.2-20070427.065136-1.pom" );
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -218,8 +207,6 @@ public class RetentionCountRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_BY_RETENTION_COUNT_POM );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
@@ -297,8 +284,6 @@ public class RetentionCountRepositoryPurgeTest
         listener.deleteArtifact( metadataRepository, getRepository().getId(), "org.apache.maven.plugins",
                                  "maven-assembly-plugin", "1.1.2-SNAPSHOT",
                                  "maven-assembly-plugin-1.1.2-20070427.065136-1.pom" );
-        listenerControl.replay();
-
         // Provide the metadata list
         List<ArtifactMetadata> ml = getArtifactMetadataFromDir(TEST_REPO_ID , projectName, repo.getParent(), vDir );
         when(metadataRepository.getArtifacts( repositorySession, TEST_REPO_ID,
@@ -306,8 +291,6 @@ public class RetentionCountRepositoryPurgeTest
 
         repoPurge.process( PATH_TO_TEST_ORDER_OF_DELETION );
 
-        listenerControl.verify();
-
         // Verify the metadataRepository invocations
         verify(metadataRepository, never()).removeProjectVersion( eq(repositorySession), eq(TEST_REPO_ID), eq(projectNs), eq(projectName), eq(projectVersion) );
         ArgumentCaptor<ArtifactMetadata> metadataArg = ArgumentCaptor.forClass(ArtifactMetadata.class);
index bde634ef1fa82fc93d4b503234511d60fe25820e..c57a4ba1efd882b985e5da151832c1b5bbb60194 100644 (file)
 
 
     <!-- Test scope -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <artifactId>archiva-maven-metadata</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>commons-beanutils</groupId>
       <artifactId>commons-beanutils</artifactId>
index 37989d9b300c2e7b8444c544b42c2468f74e5249..8d09640824b77f1a37d01384fdde0257b9f0381f 100644 (file)
@@ -29,9 +29,9 @@ import org.apache.archiva.repository.ManagedRepository;
 import org.apache.archiva.repository.RemoteRepository;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.commons.lang3.SystemUtils;
-import org.easymock.IMocksControl;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mockito;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -62,7 +62,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.function.Function;
 
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
 
 /**
  * RepositoryContentConsumersTest
@@ -245,27 +245,23 @@ public class RepositoryContentConsumersTest
     public void testExecution()
         throws Exception
     {
-        IMocksControl knownControl = createNiceControl();
-
         RepositoryContentConsumers consumers = lookupRepositoryConsumers();
         KnownRepositoryContentConsumer selectedKnownConsumer =
-            knownControl.createMock( KnownRepositoryContentConsumer.class );
+            mock( KnownRepositoryContentConsumer.class );
 
         KnownRepositoryContentConsumer unselectedKnownConsumer =
-            createNiceControl().createMock( KnownRepositoryContentConsumer.class );
+            mock( KnownRepositoryContentConsumer.class );
 
         consumers.setApplicationContext(
             new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) );
 
         consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) );
 
-        IMocksControl invalidControl = createControl();
-
         InvalidRepositoryContentConsumer selectedInvalidConsumer =
-            invalidControl.createMock( InvalidRepositoryContentConsumer.class );
+            mock( InvalidRepositoryContentConsumer.class );
 
         InvalidRepositoryContentConsumer unselectedInvalidConsumer =
-            createControl().createMock( InvalidRepositoryContentConsumer.class );
+            mock( InvalidRepositoryContentConsumer.class );
 
         consumers.setApplicationContext(
             new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) );
@@ -279,59 +275,37 @@ public class RepositoryContentConsumersTest
         startTime.setTime( 12345678 );
 
         selectedKnownConsumer.beginScan( repo, startTime, false );
-        expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
+        when( selectedKnownConsumer.getIncludes() ).thenReturn( Collections.singletonList( "**/*.txt" ) );
         selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
 
-        knownControl.replay();
-
         selectedInvalidConsumer.beginScan( repo, startTime, false );
-        invalidControl.replay();
 
         consumers.executeConsumers( repo, testFile, true );
 
-        knownControl.verify();
-        invalidControl.verify();
-
-        knownControl.reset();
-        invalidControl.reset();
-
         Path notIncludedTestFile = Paths.get( "target/test-repo/path/to/test-file.xml" );
 
         selectedKnownConsumer.beginScan( repo, startTime, false );
-        expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.<String>emptyList() );
-
-        expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
+        when( selectedKnownConsumer.getExcludes() ).thenReturn( Collections.<String>emptyList() );
 
-        knownControl.replay();
+        when( selectedKnownConsumer.getIncludes() ).thenReturn( Collections.singletonList( "**/*.txt" ) );
 
         selectedInvalidConsumer.beginScan( repo, startTime, false );
         selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
-        expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
-        invalidControl.replay();
+        when( selectedInvalidConsumer.getId() ).thenReturn( "invalid" );
 
         consumers.executeConsumers( repo, notIncludedTestFile, true );
 
-        knownControl.verify();
-        invalidControl.verify();
-
-        knownControl.reset();
-        invalidControl.reset();
-
         Path excludedTestFile = Paths.get( "target/test-repo/path/to/test-file.txt" );
 
         selectedKnownConsumer.beginScan( repo, startTime, false );
-        expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) );
-        knownControl.replay();
+        when( selectedKnownConsumer.getExcludes() ).thenReturn( Collections.singletonList( "**/test-file.txt" ) );
 
         selectedInvalidConsumer.beginScan( repo, startTime, false );
         selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
-        expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
-        invalidControl.replay();
+        when( selectedInvalidConsumer.getId() ).thenReturn( "invalid" );
 
         consumers.executeConsumers( repo, excludedTestFile, true );
 
-        knownControl.verify();
-        invalidControl.verify();
     }
 
     /**
index 265ac6417e5babe97cd05770a1dacb58524f2f81..f2855f68150f50f63943762f74defcef1e3002a6 100644 (file)
 
 
     <!-- TEST Scope -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-proxy</artifactId>
       <artifactId>repository-statistics</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.archiva.redback</groupId>
       <artifactId>redback-common-jpa</artifactId>
index 81f518d3e46f89db3f600fec2347d8283c2d02a9..4cdc10dba2835cde39e75ebac501bcec079150bf 100644 (file)
@@ -27,7 +27,6 @@ import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.archiva.indexer.ArchivaIndexingContext;
 import org.apache.archiva.indexer.search.SearchResultHit;
 import org.apache.archiva.indexer.search.SearchResults;
-import org.apache.archiva.maven.indexer.search.MavenRepositorySearch;
 import org.apache.archiva.proxy.ProxyRegistry;
 import org.apache.archiva.repository.Repository;
 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
@@ -47,8 +46,6 @@ import org.apache.maven.index.ScanningRequest;
 import org.apache.maven.index.ScanningResult;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.maven.index_shaded.lucene.index.IndexUpgrader;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runner.RunWith;
@@ -65,6 +62,9 @@ import java.util.List;
 import java.util.Locale;
 
 import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
 
 /**
  * @author Olivier Lamy
@@ -104,8 +104,6 @@ public abstract class AbstractMavenRepositorySearch
     @Inject
     private IndexerEngine indexerEngine;
 
-    IMocksControl archivaConfigControl;
-
     Configuration config;
 
     @Inject
@@ -132,9 +130,7 @@ public abstract class AbstractMavenRepositorySearch
         assertFalse( Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" )) );
         Files.createDirectories( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer" ) );
 
-        archivaConfigControl = EasyMock.createControl();
-
-        archivaConfig = archivaConfigControl.createMock( ArchivaConfiguration.class );
+        archivaConfig = mock( ArchivaConfiguration.class );
 
         repositoryRegistry.setArchivaConfiguration( archivaConfig );
 
@@ -148,12 +144,9 @@ public abstract class AbstractMavenRepositorySearch
         config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
         config.addManagedRepository( createRepositoryConfig( REPO_RELEASE ) );
 
-        archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) );
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
-        archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
-        EasyMock.expectLastCall().anyTimes();
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration() ).thenReturn(config);
+        archivaConfig.save(any(Configuration.class), anyString());
         repositoryRegistry.reload();
 
     }
@@ -163,12 +156,10 @@ public abstract class AbstractMavenRepositorySearch
     public void tearDown()
         throws Exception
     {
-        archivaConfigControl.reset();
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
-        archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
-        EasyMock.expectLastCall().anyTimes();
-        archivaConfigControl.replay();
+        reset( archivaConfig );
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration() ).thenReturn(config);
+        archivaConfig.save(any(Configuration.class), anyString());
         repositoryRegistry.removeRepository(TEST_REPO_1);
         repositoryRegistry.removeRepository(TEST_REPO_2);
         repositoryRegistry.removeRepository(REPO_RELEASE);
@@ -273,16 +264,10 @@ public abstract class AbstractMavenRepositorySearch
         }
 
 
-
-
-        archivaConfigControl.reset();
-        archivaConfig.addListener( EasyMock.anyObject( ConfigurationListener.class ) );
-        EasyMock.expect( archivaConfig.getConfiguration() ).andReturn(config).anyTimes();
-        archivaConfig.save(EasyMock.anyObject(Configuration.class), EasyMock.anyString());
-        EasyMock.expectLastCall().anyTimes();
-        archivaConfigControl.replay();
+        reset( archivaConfig );
+        when( archivaConfig.getConfiguration() ).thenReturn(config);
+        archivaConfig.save(any(Configuration.class), anyString());
         repositoryRegistry.reload();
-        archivaConfigControl.reset();
 
         Repository rRepo2 = repositoryRegistry.getRepository( repository );
         icf = rRepo2.getFeature(IndexCreationFeature.class).get();
index 080063ed5b38f412a22288e2278bdd6a9c36fa8e..d0cf2b94860c65b7810ea1b8f90f1cbfe4ab670b 100644 (file)
@@ -23,7 +23,6 @@ import org.apache.archiva.indexer.search.SearchResultHit;
 import org.apache.archiva.indexer.search.SearchResults;
 import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
 import org.apache.archiva.repository.base.RepositoryHandlerDependencies;
-import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Test;
 
@@ -33,6 +32,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import static org.mockito.Mockito.when;
+
 /**
  * @author Olivier Lamy
  */
@@ -66,9 +67,7 @@ public class MavenRepositorySearchOSGITest
 
         // search artifactId
         // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchFields searchFields = new SearchFields();
         searchFields.setBundleSymbolicName( "org.apache.felix.bundlerepository" );
@@ -77,8 +76,6 @@ public class MavenRepositorySearchOSGITest
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getTotalHits() );
 
index 74df0a23c95525d4c039418af5eb5e35c1a937d3..0439a4defd087e0ec7859b41cb0f9e72480d71e6 100644 (file)
@@ -26,7 +26,6 @@ import org.apache.archiva.indexer.search.SearchResultLimits;
 import org.apache.archiva.indexer.search.SearchResults;
 import org.apache.archiva.maven.indexer.util.SearchUtil;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.easymock.EasyMock;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
@@ -40,6 +39,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
+
 
 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@@ -110,15 +112,11 @@ public class MavenRepositorySearchTest
         List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
 
         // search artifactId
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
 
         SearchResultHit hit =
@@ -128,18 +126,15 @@ public class MavenRepositorySearchTest
         assertEquals( "archiva-search", hit.getArtifactId() );
         assertEquals( "1.0", hit.getVersions().get( 0 ) );
 
-        archivaConfigControl.reset();
+        reset( archivaConfig );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         // search groupId
-        archivaConfigControl.replay();
 
         results = search.search( "user", selectedRepos, "org.apache.archiva", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( "total hints not 3", 3, results.getTotalHits() );
 
@@ -155,15 +150,11 @@ public class MavenRepositorySearchTest
         List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
 
         // search artifactId
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
 
         SearchResultHit hit =
@@ -173,18 +164,14 @@ public class MavenRepositorySearchTest
         assertEquals( "archiva-search", hit.getArtifactId() );
         assertEquals( "1.0", hit.getVersions().get( 0 ) );
 
-        archivaConfigControl.reset();
+        reset( archivaConfig );
 
         // search groupId
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         results = search.search( "user", selectedRepos, "archiva-search", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( "total hints not 3 hits " + results.getHits(), 3, results.getTotalHits() );
 
@@ -201,15 +188,10 @@ public class MavenRepositorySearchTest
         selectedRepos.add( TEST_REPO_1 );
 
         // search artifactId
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
-
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 3, results.getTotalHits() );
 
@@ -232,10 +214,8 @@ public class MavenRepositorySearchTest
         selectedRepos.add( TEST_REPO_1 );
 
         // search artifactId
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchFields searchFields = new SearchFields();
         searchFields.setGroupId( "org.apache.archiva" );
@@ -245,8 +225,6 @@ public class MavenRepositorySearchTest
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getTotalHits() );
 
@@ -269,14 +247,10 @@ public class MavenRepositorySearchTest
         List<String> selectedRepos = new ArrayList<>();
         selectedRepos.add( TEST_REPO_1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-        archivaConfigControl.replay();
-
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
         SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getTotalHits() );
     }
@@ -294,36 +268,28 @@ public class MavenRepositorySearchTest
         SearchResultLimits limits = new SearchResultLimits( 0 );
         limits.setPageSize( 1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "org", limits, Collections.emptyList() );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getHits().size() );
         assertEquals( "total hits not 9 for page1 " + results, 9, results.getTotalHits() );
         assertEquals( "returned hits not 1 for page1 " + results, 1, results.getReturnedHitsCount() );
         assertEquals( limits, results.getLimits() );
 
-        archivaConfigControl.reset();
+        reset( archivaConfig );
 
         // page 2
         limits = new SearchResultLimits( 1 );
         limits.setPageSize( 1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         results = search.search( "user", selectedRepos, "org", limits, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
 
         assertEquals( "hits not 1", 1, results.getHits().size() );
@@ -351,18 +317,14 @@ public class MavenRepositorySearchTest
 
         config.addManagedRepository( createRepositoryConfig( TEST_REPO_2 ) );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         // wait lucene flush.....
         Thread.sleep( 2000 );
 
         SearchResults results = search.search( "user", selectedRepos, "archiva-search", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
 
         SearchResultHit hit =
@@ -373,9 +335,6 @@ public class MavenRepositorySearchTest
         assertEquals( "not 2 version for hit " + hit + "::" + niceDisplay( results ), 2, hit.getVersions().size() );
         assertTrue( hit.getVersions().contains( "1.0" ) );
         assertTrue( hit.getVersions().contains( "1.1" ) );
-
-        archivaConfigControl.reset();
-
         // TODO: [BROWSE] in artifact info from browse, display all the repositories where the artifact is found
     }
 
@@ -388,15 +347,11 @@ public class MavenRepositorySearchTest
         List<String> selectedRepos = new ArrayList<>();
         selectedRepos.add( TEST_REPO_1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "dfghdfkweriuasndsaie", null, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 0, results.getTotalHits() );
     }
@@ -408,8 +363,8 @@ public class MavenRepositorySearchTest
         List<String> selectedRepos = new ArrayList<>();
         selectedRepos.add( TEST_REPO_1 );
 
-        // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+        // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        // when( archivaConfig.getConfiguration()).thenReturn(config);
 
         // archivaConfigControl.replay();
 
@@ -417,7 +372,6 @@ public class MavenRepositorySearchTest
         assertNotNull( results );
         assertEquals( 0, results.getTotalHits() );
 
-        archivaConfigControl.verify();
     }
 
     @Test
@@ -433,7 +387,6 @@ public class MavenRepositorySearchTest
         assertNotNull( results );
         assertEquals( 0, results.getTotalHits() );
 
-        archivaConfigControl.verify();
     }
 
     @Test
@@ -448,15 +401,11 @@ public class MavenRepositorySearchTest
         List<String> previousSearchTerms = new ArrayList<>();
         previousSearchTerms.add( "archiva-test" );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", selectedRepos, "1.0", null, previousSearchTerms );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( "total hints not 1", 1, results.getTotalHits() );
 
@@ -487,15 +436,11 @@ public class MavenRepositorySearchTest
         searchFields.setVersion( "1.0" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getTotalHits() );
 
@@ -523,34 +468,26 @@ public class MavenRepositorySearchTest
         SearchResultLimits limits = new SearchResultLimits( 0 );
         limits.setPageSize( 1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, limits );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 4, results.getTotalHits() );
         assertEquals( 1, results.getHits().size() );
 
         // page 2
-        archivaConfigControl.reset();
+        reset( archivaConfig );
 
         limits = new SearchResultLimits( 1 );
         limits.setPageSize( 1 );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         results = search.search( "user", searchFields, limits );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 4, results.getTotalHits() );
         assertEquals( 1, results.getHits().size() );
@@ -575,15 +512,11 @@ public class MavenRepositorySearchTest
         searchFields.setArtifactId( "artifactid-numeric" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 2, results.getTotalHits() );
     }
@@ -619,15 +552,13 @@ public class MavenRepositorySearchTest
 
         try
         {
-            // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-            // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+            // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+            // when( archivaConfig.getConfiguration()).thenReturn(config);
 
             // archivaConfigControl.replay();
 
             search.search( "user", searchFields, null );
 
-            archivaConfigControl.verify();
-
             fail( "A RepositorySearchExcecption should have been thrown." );
         }
         catch ( RepositorySearchException e )
@@ -655,14 +586,12 @@ public class MavenRepositorySearchTest
         try
         {
 
-            // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-            // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+            // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+            // when( archivaConfig.getConfiguration()).thenReturn(config);
             // archivaConfigControl.replay();
 
             search.search( "user", searchFields, null );
 
-            archivaConfigControl.verify();
-
             fail( "A RepositorySearchException should have been thrown." );
         }
         catch ( RepositorySearchException e )
@@ -688,15 +617,11 @@ public class MavenRepositorySearchTest
         searchFields.setClassName( "org.apache.archiva.test.App" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
 
         assertEquals( "total hints not 1" + results, 1, results.getTotalHits() );
@@ -720,15 +645,11 @@ public class MavenRepositorySearchTest
         searchFields.setPackaging( "jar" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( "not 8 but " + results.getTotalHits() + ":" + niceDisplay( results ), 8, results.getTotalHits() );
     }
@@ -749,15 +670,11 @@ public class MavenRepositorySearchTest
         searchFields.setPackaging( "war" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 0, results.getTotalHits() );
     }
@@ -774,15 +691,11 @@ public class MavenRepositorySearchTest
         searchFields.setClassName( "com.classname.search.App" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( "totalHits not 1 results " + results, 1, results.getTotalHits() );
 
@@ -803,15 +716,13 @@ public class MavenRepositorySearchTest
         searchFields.setGroupId( "org.apache.archiva" );
         searchFields.setRepositories( selectedRepos );
 
-        // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        // EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
+        // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        // when( archivaConfig.getConfiguration()).thenReturn(config);
 
         // archivaConfigControl.replay();
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 0, results.getTotalHits() );
     }
@@ -828,15 +739,11 @@ public class MavenRepositorySearchTest
         searchFields.setClassName( "SomeClass" );
         searchFields.setRepositories( selectedRepos );
 
-        EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-        EasyMock.expect( archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+        when( archivaConfig.getConfiguration()).thenReturn(config);
 
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 1, results.getHits().size() );
         assertEquals( "test-webapp", results.getHits().get( 0 ).getArtifactId() );
@@ -850,14 +757,10 @@ public class MavenRepositorySearchTest
 
         List<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
 
-        EasyMock.expect( archivaConfig.getConfiguration() ).andReturn( config ).times( 0, 2 );
-
-        archivaConfigControl.replay();
+        when( archivaConfig.getConfiguration() ).thenReturn( config );
 
         Collection<String> groupIds = search.getAllGroupIds( "user", selectedRepos );
 
-        archivaConfigControl.verify();
-
         log.info( "groupIds: {}", groupIds );
 
         assertEquals( 3, groupIds.size() );
@@ -878,12 +781,8 @@ public class MavenRepositorySearchTest
         searchFields.setClassName( "SomeClass" );
         searchFields.setRepositories( selectedRepos );
 
-        archivaConfigControl.replay();
-
         SearchResults results = search.search( "user", searchFields, null );
 
-        archivaConfigControl.verify();
-
         assertNotNull( results );
         assertEquals( 0, results.getHits().size() );
     }
@@ -909,10 +808,8 @@ public class MavenRepositorySearchTest
             SearchResultLimits limits = new SearchResultLimits(SearchResultLimits.ALL_PAGES);
             limits.setPageSize(300);
 
-            // EasyMock.expect( archivaConfig.getDefaultLocale() ).andReturn( Locale.getDefault( ) ).anyTimes();
-            EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
-
-            archivaConfigControl.replay();
+            // when( archivaConfig.getDefaultLocale() ).thenReturn( Locale.getDefault( ) );
+            when(archivaConfig.getConfiguration()).thenReturn(config);
 
             SearchResults searchResults = search.search(null, Arrays.asList(REPO_RELEASE), //
                     "org.example", limits, //
@@ -931,8 +828,6 @@ public class MavenRepositorySearchTest
             log.info("results: {}", searchResults.getHits().size());
 
             assertEquals(255, searchResults.getHits().size());
-
-            archivaConfigControl.verify();
         } finally {
             FileUtils.deleteQuietly(repo);
         }
index c7f26a14eb34b5ef11dd366c5a2aba4fdd8aafbe..1e0ef5db99480f12df4961caa12fbb302cde03a5 100644 (file)
     </dependency>
 
     <!-- Test scope -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>jakarta.persistence</groupId>
       <artifactId>jakarta.persistence-api</artifactId>
       <artifactId>xmlunit-core</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>jakarta.transaction</groupId>
       <artifactId>jakarta.transaction-api</artifactId>
index da72e9eaa50dc0ec9d9397282b1a3796ca60c0ed..156f188cef0a1ede245d77bdd71c4c1b17d15343 100644 (file)
@@ -42,8 +42,6 @@ import org.apache.archiva.repository.base.managed.BasicManagedRepository;
 import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.apache.maven.wagon.Wagon;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -72,6 +70,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
 
 /**
  * AbstractProxyTestCase
@@ -115,8 +114,6 @@ public abstract class AbstractProxyTestCase
 
     // protected static final String REPOPATH_DEFAULT_MANAGED_TARGET = "target/test-repository/managed";
 
-    protected IMocksControl wagonMockControl;
-
     protected Wagon wagonMock;
 
 
@@ -185,8 +182,7 @@ public abstract class AbstractProxyTestCase
 
 
         // Setup the wagon mock.
-        wagonMockControl = EasyMock.createNiceControl();
-        wagonMock = wagonMockControl.createMock( Wagon.class );
+        wagonMock = mock( Wagon.class );
 
         delegate = (WagonDelegate) applicationContext.getBean( "wagon#http", Wagon.class );
 
index 6be8aeacdd3517430260007519bff96a0acc5a05..fe93b5cd49672e8aca9dd171da97327abbfc489f 100644 (file)
@@ -28,7 +28,6 @@ import org.apache.archiva.repository.content.Artifact;
 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
 import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
 import org.junit.Test;
 
 import javax.inject.Inject;
@@ -39,6 +38,9 @@ import java.nio.file.Paths;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
 
 /**
  * CacheFailuresTransferTest
@@ -77,23 +79,11 @@ public class CacheFailuresTransferTest
         saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
             SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false );
 
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-
-        EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
-
-        wagonMockControl.replay( );
+        doThrow(new ResourceDoesNotExistException( "resource does not exist." )).when(wagonMock).get( eq( path ), any(  ) );
 
         //noinspection UnusedAssignment
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
-        wagonMockControl.verify( );
-
-        // Second attempt to download same artifact use cache
-        wagonMockControl.reset( );
-        wagonMockControl.replay( );
         downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-        wagonMockControl.verify( );
 
         assertNotDownloaded( downloadedFile );
         assertNoTempFiles( expectedFile );
@@ -123,26 +113,16 @@ public class CacheFailuresTransferTest
         saveConnector( ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
             SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
 
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
-        wagonMockControl.replay( );
+        doThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).when( wagonMock ).get( eq( path ), any( ) );
 
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
+        verify( wagonMock, times( 2 ) ).get( eq( path ), any( ) );
 
-        wagonMockControl.verify( );
-
-        // Second attempt to download same artifact DOES NOT use cache
-        wagonMockControl.reset( );
-
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).times( 2 );
-
-        wagonMockControl.replay( );
+        reset( wagonMock );
+        doThrow( new ResourceDoesNotExistException( "resource does not exist." ) ).when( wagonMock ).get( eq( path ), any( ) );
 
         downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
-        wagonMockControl.verify( );
+        verify( wagonMock, times( 2 ) ).get( eq( path ), any( ) );
 
         assertNotDownloaded( downloadedFile );
         assertNoTempFiles( expectedFile );
index 2d9c155e95fff44504ac81fb1ed4228c8e26b6f5..def94b23e6b70ea2ddfd826cb2d37538cc34760a 100644 (file)
@@ -27,7 +27,6 @@ import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
 import org.apache.archiva.repository.content.Artifact;
 import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
 import org.junit.Test;
 
 import java.io.File;
@@ -38,6 +37,9 @@ import java.nio.file.StandardCopyOption;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
 
 /**
  * ChecksumTransferTest
@@ -457,20 +459,12 @@ public class ChecksumTransferTest
         saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
             SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
 
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall( ).once( );
-
-        wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall( ).once( );
-
-        wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall( ).andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once( );
-
-        wagonMockControl.replay( );
+        doThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).when( wagonMock ).get( eq( path + ".md5" ), any( ) );
 
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository( ), artifact );
-
-        wagonMockControl.verify( );
+        verify( wagonMock, times( 1 ) ).get( eq( path ), any( ) );
+        verify( wagonMock, times( 1 ) ).get( eq( path + ".sha1"), any( ) );
+        verify( wagonMock, times( 1 ) ).get( eq( path + ".md5"), any( ) );
 
         // Do what the mock doesn't do.
         Path proxyPath = Paths.get( REPOPATH_PROXIED1, path ).toAbsolutePath( );
index 53fb8f36b0eb3f96dd14cc138f4ae5e0445424cd..d85bdd4bda948a709ea7f240fa7215bb4c18052a 100644 (file)
@@ -18,23 +18,34 @@ package org.apache.archiva.maven.proxy;
  * under the License.
  */
 
-import org.apache.archiva.policies.*;
+import org.apache.archiva.policies.CachedFailuresPolicy;
+import org.apache.archiva.policies.ChecksumPolicy;
+import org.apache.archiva.policies.PolicyOption;
+import org.apache.archiva.policies.PropagateErrorsDownloadPolicy;
+import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
+import org.apache.archiva.policies.ProxyDownloadException;
+import org.apache.archiva.policies.ReleasesPolicy;
+import org.apache.archiva.policies.SnapshotsPolicy;
 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
 import org.apache.archiva.repository.content.LayoutException;
 import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.easymock.EasyMock;
 import org.junit.Test;
+import org.mockito.stubbing.Stubber;
 
-import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
 
 import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
 
 /**
  * ErrorHandlingTest
@@ -68,7 +79,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
 
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
     }
@@ -83,9 +94,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
 
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
     }
@@ -115,7 +124,7 @@ public class ErrorHandlingTest
 
         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
 
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
 
         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
     }
@@ -131,7 +140,7 @@ public class ErrorHandlingTest
 
         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
 
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
     }
@@ -161,9 +170,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
 
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
     }
@@ -179,9 +186,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createResourceNotFoundException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
     }
@@ -197,9 +202,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
 
         confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
     }
@@ -215,7 +218,7 @@ public class ErrorHandlingTest
 
         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
 
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ) ) );
 
         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
     }
@@ -231,7 +234,7 @@ public class ErrorHandlingTest
 
         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
 
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
 
         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
     }
@@ -261,9 +264,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
 
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
-
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createResourceNotFoundException( ), createTransferException( ) ) );
 
         confirmNotDownloadedNoError( path );
     }
@@ -279,9 +280,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-
-        simulateGetError( path, expectedFile, createResourceNotFoundException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createResourceNotFoundException( ) ) );
 
         confirmNotDownloadedNoError( path );
     }
@@ -297,9 +296,7 @@ public class ErrorHandlingTest
 
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
 
         confirmNotDownloadedNoError( path );
     }
@@ -316,7 +313,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
                                     PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
 
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
     }
@@ -350,8 +347,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
                                     PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
 
         confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
     }
@@ -386,8 +382,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
                                     PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
 
         confirmNotDownloadedNoError( path );
     }
@@ -423,7 +418,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
                                     PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
 
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ) ) );
 
         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
     }
@@ -458,8 +453,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
                                     PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-        simulateGetError( path, expectedFile, createTransferException() );
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
 
         confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
     }
@@ -495,9 +489,7 @@ public class ErrorHandlingTest
         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
                                     PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
 
-        simulateGetError( path, expectedFile, createTransferException() );
-        simulateGetError( path, expectedFile, createTransferException() );
-
+        simulateGetError( path, expectedFile, Arrays.asList( createTransferException( ), createTransferException( ) ) );
         confirmNotDownloadedNoError( path );
     }
 
@@ -562,18 +554,23 @@ public class ErrorHandlingTest
         return file;
     }
 
-    private void simulateGetError( String path, Path expectedFile, Exception throwable )
+    private void simulateGetError( String path, Path expectedFile, List<Exception> throwables )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
-        EasyMock.expectLastCall().andThrow(throwable );
+        Stubber stubber = doThrow( throwables.get( 0 ) );
+        if (throwables.size()>1) {
+            for(int i=1; i<throwables.size(); i++)
+            {
+                stubber = stubber.doThrow( throwables.get( i ) );
+            }
+        }
+        stubber.when( wagonMock ).get( eq( path ), any( ) );
     }
 
     private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
     {
-        wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
-        EasyMock.expectLastCall().andThrow( exception );
+        doThrow( exception ).when( wagonMock ).getIfNewer( eq( path ), any( ), eq( Files.getLastModifiedTime( expectedFile ).toMillis( ) ) );
     }
 
     private Path createExpectedTempFile( Path expectedFile )
@@ -590,8 +587,6 @@ public class ErrorHandlingTest
     private void confirmFailures( String path, String[] ids )
         throws LayoutException
     {
-        wagonMockControl.replay();
-
         // Attempt the proxy fetch.
         StorageAsset downloadedFile = null;
         try
@@ -609,9 +604,6 @@ public class ErrorHandlingTest
                 assertTrue( e.getFailures().keySet().contains( id ) );
             }
         }
-
-        wagonMockControl.verify();
-
         assertNotDownloaded( downloadedFile );
     }
 
@@ -635,15 +627,11 @@ public class ErrorHandlingTest
     private StorageAsset performDownload( String path )
         throws ProxyDownloadException, LayoutException
     {
-        wagonMockControl.replay();
-
         // Attempt the proxy fetch.
         BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
 
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
             layout.getArtifact( path ) );
-
-        wagonMockControl.verify();
         return downloadedFile;
     }
 
index 3cc78dc93b0dc0c018a9356a48242f79b1076e58..f4fcf724e98a7d7b65d7a08cf96be4c73badd1af 100644 (file)
@@ -28,7 +28,6 @@ import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.easymock.EasyMock;
 import org.junit.Test;
 
 import java.io.File;
@@ -40,6 +39,9 @@ import java.nio.file.attribute.FileTime;
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
 
 /**
  * ManagedDefaultTransferTest
@@ -434,9 +436,8 @@ public class ManagedDefaultTransferTest
         saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "" +
             "http://bad.machine.com/repo/", "default" );
 
-        wagonMock.get( EasyMock.eq( path), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "transfer failed" )  );
-        wagonMockControl.replay();
+        doThrow( new ResourceDoesNotExistException( "transfer failed" ) ).when( wagonMock ).get( eq( path ), any( ) );
+
 
         // Configure Connector (usually done within archiva.xml configuration)
         saveConnector( ID_DEFAULT_MANAGED, "badproxied", false );
@@ -444,8 +445,7 @@ public class ManagedDefaultTransferTest
 
         // Attempt the proxy fetch.
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
-
-        wagonMockControl.verify();
+        verify( wagonMock, atLeastOnce( ) ).get( eq( path ), any( ) );
 
         Path proxied2File = Paths.get(REPOPATH_PROXIED2, path);
         assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied2File );
@@ -477,19 +477,14 @@ public class ManagedDefaultTransferTest
 
         Path tmpFile = expectedFile.getParent().resolve(expectedFile.getFileName() + ".tmp" );
 
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) );
-
-        wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ) );
-        EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Can't find resource." ) );
+        doThrow( new ResourceDoesNotExistException( "Can't find resource." ) ).when( wagonMock ).get( eq( path ), any( ) );
 
-        wagonMockControl.replay();
 
         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
+        verify( wagonMock, atLeastOnce( ) ).get( eq( path ), any( ) );
 
         assertNotDownloaded( downloadedFile );
 
-        wagonMockControl.verify();
         assertNoTempFiles( expectedFile );
 
         // TODO: do not want failures to present as a not found [MRM-492]
index 26baf642ac46d3d43ad9000ebc5f519985324f9f..530b0561f38339cd8ea26fc31a5e56bd53ac78fa 100644 (file)
@@ -42,7 +42,6 @@ import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.wagon.TransferFailedException;
-import org.easymock.EasyMock;
 import org.junit.Test;
 import org.xmlunit.builder.DiffBuilder;
 import org.xmlunit.diff.Diff;
@@ -58,6 +57,10 @@ import java.util.ArrayList;
 import java.util.Arrays;
 
 import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.when;
 
 /**
  * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
@@ -166,16 +169,11 @@ public class MetadataTransferTest
         Path expectedFile = managedDefaultDir.resolve(
                                       metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
 
-        wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
-        EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
+        doThrow( new TransferFailedException( "can't connect" )).when( wagonMock  ).get( eq( requestedResource ), any( File.class ) );
 
 
-        wagonMockControl.replay();
-
         assertFetchProjectOrGroup( requestedResource );
 
-        wagonMockControl.verify();
-
         assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
         assertNoRepoMetadata( "badproxied1", requestedResource );
         assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
index 5ce3f2e8ee49b363fc10f6d99925640b54a6e84b..2cf6a105a73369f0d34c6ab8058f6cc851541d5f 100644 (file)
@@ -23,8 +23,7 @@ import org.apache.archiva.components.registry.Registry;
 import org.apache.archiva.components.registry.RegistryException;
 import org.apache.archiva.components.registry.RegistryListener;
 import org.apache.commons.lang3.StringUtils;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
+import org.mockito.Mockito;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
@@ -32,6 +31,8 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.*;
 
+import static org.mockito.Mockito.mock;
+
 /**
  * MockConfiguration
  *
@@ -48,14 +49,12 @@ public class MockConfiguration
 
     private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
 
-    private IMocksControl registryControl;
 
     private Registry registryMock;
 
     public MockConfiguration()
     {
-        registryControl = EasyMock.createNiceControl( );
-        registryMock = registryControl.createMock( Registry.class );
+        registryMock = mock( Registry.class );
     }
 
     @PostConstruct
index 8561777cb7249bbddbf1afe8a96c73e270b38080..a065afd01a35925a71ce7e143179dc2d94bdb691 100644 (file)
       <artifactId>xmlunit-assertj</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
 
     <dependency>
       <groupId>org.springframework</groupId>
index a9dd1e419ac6c3060679c8982ada48e8344e9910..a5de3eaeb1fc5b43054cd4b527b154a9ce22dc34 100644 (file)
@@ -29,7 +29,6 @@ import org.apache.archiva.configuration.FileType;
 import org.apache.archiva.configuration.IndeterminateConfigurationException;
 import org.apache.archiva.configuration.RepositoryScanningConfiguration;
 import org.apache.commons.lang3.StringUtils;
-import org.easymock.IMocksControl;
 import org.springframework.stereotype.Service;
 
 import java.nio.file.Path;
@@ -40,7 +39,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
-import static org.easymock.EasyMock.createNiceControl;
+import static org.mockito.Mockito.mock;
 
 /**
  * MockConfiguration 
@@ -57,14 +56,11 @@ public class MockConfiguration
     private Set<RegistryListener> registryListeners = new HashSet<RegistryListener>();
     private Set<ConfigurationListener> configListeners = new HashSet<ConfigurationListener>();
 
-    private IMocksControl registryControl;
-
     private Registry registryMock;
 
     public MockConfiguration()
     {
-        registryControl = createNiceControl();
-        registryMock = registryControl.createMock( Registry.class );
+        registryMock = mock( Registry.class );
         configuration.setArchivaRuntimeConfiguration(new ArchivaRuntimeConfiguration());
         configuration.getArchivaRuntimeConfiguration().addChecksumType("sha1");
         configuration.getArchivaRuntimeConfiguration().addChecksumType("sha256");
index 3b5f3891dde6506f850ab6f46df348508d38a9bc..7dd8dad507b4c1e3ab30d6f15a7b14972d2750f0 100644 (file)
 
 
     <!-- TEST Scope -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
       <artifactId>jakarta.persistence-api</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>jakarta.transaction</groupId>
       <artifactId>jakarta.transaction-api</artifactId>
index 5bc1d9b28b0737b62128c78eaf708321f3caf55d..07588dad9fe756f2e047a6550357d31326eeda42 100644 (file)
@@ -22,8 +22,8 @@ import org.apache.archiva.common.filelock.DefaultFileLockManager;
 import org.apache.archiva.repository.storage.fs.FilesystemAsset;
 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
 import org.apache.archiva.repository.storage.StorageAsset;
-import org.easymock.TestSubject;
 import org.junit.Test;
+import org.mockito.InjectMocks;
 
 import java.io.IOException;
 import java.nio.file.Path;
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 public class ArtifactBuilderTest
 {
-    @TestSubject
+    @InjectMocks
     private ArtifactBuilder builder = new ArtifactBuilder();
 
     StorageAsset getFile(String path) throws IOException {
index f67f8a4eee6c7aeb93d1f8d348e0e8a33902421a..d74c248475e5e12af5d69c3467a5bd26db520fcf 100644 (file)
       <artifactId>archiva-filelock</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-test-utils</artifactId>
       <artifactId>spring-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
 
   </dependencies>
 
index 2e5913108cb404333f89db050cd9c5782e32b4f5..a927214774258688c8522196116bc709d1c9710c 100644 (file)
@@ -28,23 +28,19 @@ import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.rss.RssFeedGenerator;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.time.LocalDateTime;
-import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.TimeZone;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 @RunWith (ArchivaBlockJUnit4ClassRunner.class)
 public class NewArtifactsRssFeedProcessorTest
@@ -56,10 +52,8 @@ public class NewArtifactsRssFeedProcessorTest
 
     private MetadataRepositoryMock metadataRepository;
 
-    private IMocksControl sessionFactoryControl;
     private RepositorySessionFactory sessionFactory;
 
-    private IMocksControl sessionControl;
     private RepositorySession session;
 
     @Before
@@ -74,18 +68,11 @@ public class NewArtifactsRssFeedProcessorTest
 
         metadataRepository = new MetadataRepositoryMock();
 
-        sessionFactoryControl = EasyMock.createControl();
-        sessionControl = EasyMock.createControl();
-        sessionControl.resetToNice();
-
-        sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
-        session = sessionControl.createMock( RepositorySession.class );
-
-        EasyMock.expect( sessionFactory.createSession() ).andStubReturn( session );
-        EasyMock.expect( session.getRepository( ) ).andStubReturn( metadataRepository );
+        sessionFactory = mock( RepositorySessionFactory.class );
+        session = mock( RepositorySession.class );
 
-        sessionFactoryControl.replay();
-        sessionControl.replay();
+        when( sessionFactory.createSession() ).thenReturn( session );
+        when( session.getRepository( ) ).thenReturn( metadataRepository );
 
         newArtifactsProcessor.setRepositorySessionFactory( sessionFactory );
 
index 28b679a2567478ff2fd7f36d5d40c0a3d26c9ad8..ddb35ff3347831428cd898434095652851cdc7b3 100644 (file)
@@ -34,8 +34,6 @@ import org.apache.archiva.repository.RepositoryRegistry;
 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
 import org.apache.archiva.rss.RssFeedGenerator;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -51,8 +49,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static org.easymock.EasyMock.createControl;
-import static org.easymock.EasyMock.expect;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 
 @RunWith(ArchivaBlockJUnit4ClassRunner.class)
 public class NewVersionsOfArtifactRssFeedProcessorTest
@@ -66,17 +65,12 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
 
     private static final String ARTIFACT_ID = "artifact-two";
 
-    private IMocksControl metadataRepositoryControl;
-
     private MetadataRepository metadataRepository;
 
-    private IMocksControl sessionFactoryControl;
     private RepositorySessionFactory sessionFactory;
 
-    private IMocksControl sessionControl;
     private RepositorySession session;
 
-    private IMocksControl repositoryRegistryControl;
     private RepositoryRegistry repositoryRegistry;
 
 
@@ -90,28 +84,20 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
         newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
         newVersionsProcessor.setGenerator( new RssFeedGenerator() );
 
-        metadataRepositoryControl = createControl();
-        metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+        metadataRepository = mock( MetadataRepository.class );
 
-        sessionFactoryControl = EasyMock.createControl();
-        sessionControl = EasyMock.createControl();
-        sessionControl.resetToNice();
 
-        sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
-        session = sessionControl.createMock( RepositorySession.class );
+        sessionFactory = mock( RepositorySessionFactory.class );
+        session = mock( RepositorySession.class );
 
-        EasyMock.expect( sessionFactory.createSession() ).andStubReturn( session );
-        EasyMock.expect( session.getRepository( ) ).andStubReturn( metadataRepository );
-        sessionFactoryControl.replay();
-        sessionControl.replay();
+        when( sessionFactory.createSession() ).thenReturn( session );
+        when( session.getRepository( ) ).thenReturn( metadataRepository );
 
-        repositoryRegistryControl = EasyMock.createControl();
-        repositoryRegistry = repositoryRegistryControl.createMock( ArchivaRepositoryRegistry.class );
+        repositoryRegistry = mock( ArchivaRepositoryRegistry.class );
 
         List<Repository> reg = new ArrayList<>( );
         reg.add( new BasicManagedRepository( TEST_REPO, TEST_REPO, new FilesystemStorage( Paths.get("target/test-storage"), new DefaultFileLockManager() ) ) );
-        EasyMock.expect( repositoryRegistry.getRepositories() ).andStubReturn( reg );
-        repositoryRegistryControl.replay();
+        when( repositoryRegistry.getRepositories() ).thenReturn( reg );
 
         newVersionsProcessor.setRepositorySessionFactory( sessionFactory );
         newVersionsProcessor.setRepositoryRegistry( repositoryRegistry );
@@ -137,15 +123,14 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
         reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
         reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
 
-            expect(metadataRepository.getProjectVersions(session, TEST_REPO, GROUP_ID, ARTIFACT_ID)).andReturn(
+            when(metadataRepository.getProjectVersions(session, TEST_REPO, GROUP_ID, ARTIFACT_ID)).thenReturn(
                     Arrays.asList("1.0.1", "1.0.2", "1.0.3-SNAPSHOT"));
-            expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1")).andReturn(
+            when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1")).thenReturn(
                     Collections.singletonList(artifact1));
-            expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2")).andReturn(
+            when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2")).thenReturn(
                     Collections.singletonList(artifact2));
-            expect(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT")).andReturn(
+            when(metadataRepository.getArtifacts(session, TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT")).thenReturn(
                     Collections.singletonList(artifact3));
-        metadataRepositoryControl.replay();
 
         SyndFeed feed = newVersionsProcessor.process( reqParams );
 
@@ -166,7 +151,6 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
 
         assertEquals( whenGatheredNext.toInstant(), entries.get( 1 ).getPublishedDate().toInstant() );
 
-        metadataRepositoryControl.verify();
     }
 
     private ArtifactMetadata createArtifact(ZonedDateTime whenGathered, String version )
index c56bd89bb9fed0fe61808a9ef072c8c528eac351..e84139a5c573009d5c6736d74db4f31617033b7f 100644 (file)
 
 
     <!-- Test Scoped -->
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva.maven</groupId>
       <artifactId>archiva-maven-proxy</artifactId>
       <artifactId>jakarta.persistence-api</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.apache.archiva.redback</groupId>
       <artifactId>redback-keys-jpa</artifactId>
index 9258abea89a1d93f43246986c4f606fd0ce0061d..75a1887b285e0c5b101b7f43ad3d7bf4767ec018 100644 (file)
@@ -27,8 +27,6 @@ import org.apache.archiva.redback.system.SecuritySession;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,6 +34,9 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 /**
  * ArchivaServletAuthenticatorTest
  */
@@ -46,8 +47,6 @@ public class ArchivaServletAuthenticatorTest
     @Named( value = "servletAuthenticator#test" )
     private ServletAuthenticator servletAuth;
 
-    private IMocksControl httpServletRequestControl;
-
     private HttpServletRequest request;
 
     @Before
@@ -57,8 +56,7 @@ public class ArchivaServletAuthenticatorTest
     {
         super.setUp();
 
-        httpServletRequestControl = EasyMock.createControl( );
-        request = httpServletRequestControl.createMock( HttpServletRequest.class );
+        request = mock( HttpServletRequest.class );
 
         setupRepository( "corporate" );
     }
@@ -126,7 +124,7 @@ public class ArchivaServletAuthenticatorTest
         assignRepositoryObserverRole( USER_ALPACA, "corporate" );
 
         //httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" );
-        EasyMock.expect( request.getRemoteAddr() ).andReturn( "192.168.111.111" );
+        when( request.getRemoteAddr() ).thenReturn( "192.168.111.111" );
 
         UserManager userManager = securitySystem.getUserManager();
         User user = userManager.findUser( USER_ALPACA );
@@ -135,8 +133,6 @@ public class ArchivaServletAuthenticatorTest
 
         SecuritySession session = new DefaultSecuritySession( result, user );
 
-        httpServletRequestControl.replay();
-
         try
         {
             servletAuth.isAuthorized( request, session, "corporate", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT );
@@ -147,8 +143,6 @@ public class ArchivaServletAuthenticatorTest
             assertEquals( "Access denied for repository corporate", e.getMessage() );
         }
 
-        httpServletRequestControl.verify();
-
         restoreGuestInitialValues( USER_ALPACA );
     }
 
index dcfacf75c7459a5f8a6c4c419f22ab03b861e06a..747293b414da5d223ce34e174cfe47b01dc84b3a 100644 (file)
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
index 2de2b9a786da9fe0d27d6e78557acc65c6c644fe..3650a9704f5789a6e4047a29441e86121207072f 100644 (file)
@@ -56,12 +56,11 @@ import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.jackrabbit.webdav.DavServletResponse;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mockito;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ConfigurableApplicationContext;
@@ -78,7 +77,8 @@ import java.util.Locale;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
 
-import static org.easymock.EasyMock.*;
+import static org.mockito.Mockito.*;
+
 
 /**
  * ArchivaDavResourceFactoryTest
@@ -102,26 +102,16 @@ public class ArchivaDavResourceFactoryTest
 
     private OverridingArchivaDavResourceFactory resourceFactory;
 
-    private IMocksControl requestControl;
-
     private DavServletRequest request;
 
-    private IMocksControl repoRequestControl;
-
     private MavenRepositoryRequestInfo repoRequest;
 
-    private IMocksControl responseControl;
-
     private DavServletResponse response;
 
-    private IMocksControl archivaConfigurationControl;
-
     private ArchivaConfiguration archivaConfiguration;
 
     private Configuration config;
 
-    private IMocksControl repoContentFactoryControl;
-
     private RepositoryContentFactory repoFactory;
 
     @Inject
@@ -184,26 +174,19 @@ public class ArchivaDavResourceFactoryTest
     {
         super.setUp();
 
-        requestControl = createControl();
-        request = requestControl.createMock( DavServletRequest.class );
+        request = mock( DavServletRequest.class );
 
-        responseControl = createControl();
-        response = responseControl.createMock( DavServletResponse.class );
+        response = mock( DavServletResponse.class );
         //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
 
-        archivaConfigurationControl = createControl();
-        archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
+        archivaConfiguration = mock( ArchivaConfiguration.class );
 
         config = new Configuration();
-        expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2, 25 );
-        expect (archivaConfiguration.getDefaultLocale()).andReturn( Locale.getDefault() ).anyTimes();
-        archivaConfiguration.addListener( EasyMock.anyObject(  ) );
-        expectLastCall().times(0, 4);
+        when( archivaConfiguration.getConfiguration() ).thenReturn( config );
+        when(archivaConfiguration.getDefaultLocale()).thenReturn( Locale.getDefault() );
+        archivaConfiguration.addListener( any() );
         archivaConfiguration.save( eq(config));
-        expectLastCall().times( 0, 5 );
-        archivaConfiguration.save( eq(config), EasyMock.anyString());
-        expectLastCall().times( 0, 5 );
-        archivaConfigurationControl.replay();
+        archivaConfiguration.save( eq(config), anyString());
 
         defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
         repositoryRegistry.setArchivaConfiguration( archivaConfiguration );
@@ -233,11 +216,9 @@ public class ArchivaDavResourceFactoryTest
             defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
         }
 
-        repoContentFactoryControl = createControl();
-        repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
+        repoFactory = mock( RepositoryContentFactory.class );
 
-        repoRequestControl = createControl();
-        repoRequest = repoRequestControl.createMock( MavenRepositoryRequestInfo.class );
+        repoRequest = mock( MavenRepositoryRequestInfo.class );
 
         resourceFactory =
             new OverridingArchivaDavResourceFactory( applicationContext, archivaConfiguration );
@@ -248,6 +229,12 @@ public class ArchivaDavResourceFactoryTest
         resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
         resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
         resourceFactory.setRepositoryRegistry( repositoryRegistry );
+        verify( archivaConfiguration,    atLeast( 2 )).getConfiguration();
+        verify( archivaConfiguration,    atMost( 25 )).getConfiguration();
+        verify( archivaConfiguration, atMost( 4 ) ).addListener( any() );
+        verify( archivaConfiguration, atMost( 5 ) ).save( eq(config) );
+        verify( archivaConfiguration, atMost( 5 ) ).save( eq(config), anyString() );
+
     }
 
     private ManagedRepository createManagedRepository( String id, String location, String layout )
@@ -349,51 +336,51 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
-
-            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+            reset( archivaConfiguration );
+            reset( request );
+            reset( repoFactory );
+            when( archivaConfiguration.getConfiguration( ) ).thenReturn( config );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
 
-            expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+            when( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).thenReturn( releasesRepo );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            when( request.getRemoteAddr( ) ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            when( request.getDavSession( ) ).thenReturn( new ArchivaDavSession( ) );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+            when( request.getContextPath( ) ).thenReturn( "" );
 
-            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
+            when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( true );
 
-            expect(
-                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+            when(
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
                 "legacy" );
 
-            expect( repoRequest.toItemSelector(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+            when( repoRequest.toItemSelector(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
-            ) ).andReturn(
+            when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).thenReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
-            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
 
-            expect( repoRequest.isArchetypeCatalog(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
-            archivaConfigurationControl.replay();
-            requestControl.replay();
-            repoContentFactoryControl.replay();
-            repoRequestControl.replay();
+            when( repoRequest.isArchetypeCatalog(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
 
             resourceFactory.createResource( locator, request, response );
 
-            archivaConfigurationControl.verify();
-            requestControl.verify();
-            repoContentFactoryControl.verify();
-            repoRequestControl.verify();
+            verify(archivaConfiguration, times( 3 )).getConfiguration();
+            verify( request, times( 3 ) ).getMethod( );
+            verify( request, atMost( 2 ) ).getPathInfo( );
+            verify(request,times( 2 )).getRemoteAddr();
+            verify( request, times( 2 ) ).getDavSession( );
+            verify( request, times( 2 ) ).getContextPath( );
+
 
             fail( "A DavException with 401 error code should have been thrown." );
         }
@@ -427,52 +414,51 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
+            reset( archivaConfiguration );
+            reset( request );
+            reset( repoFactory );
 
-            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+            when( archivaConfiguration.getConfiguration( ) ).thenReturn( config );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
 
-            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
 
-            expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+            when( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).thenReturn( releasesRepo );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+            when( request.getContextPath() ).thenReturn( "" );
 
-            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
+            when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
 
-            expect(
-                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+            when(
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
                 "legacy" );
 
-            expect( repoRequest.toItemSelector(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+            when( repoRequest.toItemSelector(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
-            ) ).andReturn(
+            when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).thenReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
 
-            expect( repoRequest.isArchetypeCatalog(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
-            archivaConfigurationControl.replay();
-            requestControl.replay();
-            repoContentFactoryControl.replay();
-            repoRequestControl.replay();
+            when( repoRequest.isArchetypeCatalog(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
 
             resourceFactory.createResource( locator, request, response );
-
-            archivaConfigurationControl.verify();
-            requestControl.verify();
-            repoContentFactoryControl.verify();
-            repoRequestControl.verify();
+            verify( archivaConfiguration, times( 3 ) ).getConfiguration( );
+            verify( request, times( 3 ) ).getMethod();
+            verify( request, atMost( 2 ) ).getPathInfo( );
+            verify( request, times( 2 ) ).getRemoteAddr( );
+            verify( request, times( 2 ) ).getDavSession( );
+            verify( request, times( 2 ) ).getContextPath( );
 
             fail( "A DavException with 401 error code should have been thrown." );
         }
@@ -511,55 +497,59 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
+            reset( archivaConfiguration );
+            reset( request );
+            reset( repoFactory );
 
-            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
+            when( archivaConfiguration.getConfiguration() ).thenReturn( config );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 5 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            when( request.getPathInfo() ).thenReturn( "org/apache/archiva" );
 
-            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
 
-            expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
+            when( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).thenReturn( localMirrorRepo );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
+            when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
+            when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+            when( request.getContextPath() ).thenReturn( "" );
 
-            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
+            when( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
 
-            expect(
-                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
-                "legacy" ).times( 2 );
+            when(
+                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn(
+                "legacy" );
 
-            expect( repoRequest.toItemSelector(
-                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
+            when( repoRequest.toItemSelector(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( null );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
-            ) ).andReturn(
+            when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            ) ).thenReturn(
                 Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString() );
 
-            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
+            when( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
             ) )
-                .andReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
+                .thenReturn( Paths.get( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
                                       "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
 
-            expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
-            archivaConfigurationControl.replay();
-            requestControl.replay();
-            repoContentFactoryControl.replay();
-            repoRequestControl.replay();
+            when( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).thenReturn( false );
 
             resourceFactory.createResource( locator, request, response );
-
-            archivaConfigurationControl.verify();
-            requestControl.verify();
-            repoContentFactoryControl.verify();
-            repoRequestControl.verify();
+            verify( archivaConfiguration, times( 3 ) ).getConfiguration( );
+            verify( request, times( 5 ) ).getMethod( );
+            verify( request, atMost( 2 ) ).getPathInfo( );
+            verify( request, times( 4 ) ).getRemoteAddr( );
+            verify( request, times( 4 ) ).getDavSession( );
+            verify( request, times( 2 ) ).getContextPath( );
+            verify( repoRequest, times( 2 ) ).isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+            verify(repoRequest, times( 2 )).getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+            verify( repoRequest, times( 2 ) ).toItemSelector(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
+            verify( repoRequest, times( 2 ) ).isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" );
 
             fail( "A DavException with 404 error code should have been thrown." );
         }
@@ -586,39 +576,27 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
+            reset( request );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+            when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 1 );
+            when( request.getContextPath() ).thenReturn( "" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
 
-            expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
+            when( request.getRequestURI() ).thenReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
             response.setHeader( "Pragma", "no-cache" );
-
-            expectLastCall();
-
             response.setHeader( "Cache-Control", "no-cache" );
-
-            expectLastCall();
-
             response.setDateHeader( eq("Last-Modified"), anyLong() );
-            expectLastCall();
-
-            archivaConfigurationControl.replay();
-            repoContentFactoryControl.replay();
-            requestControl.replay();
-            responseControl.replay();
 
             resourceFactory.createResource( locator, request, response );
+            verify( request, times( 4 ) ).getMethod( );
+            verify( request, times( 3 ) ).getRemoteAddr( );
+            verify( request, times( 1 ) ).getContextPath( );
+            verify( request, times( 2 ) ).getDavSession( );
 
-            archivaConfigurationControl.verify();
-            repoContentFactoryControl.verify();
-            requestControl.verify();
-            responseControl.verify();
         }
         catch ( DavException e )
         {
@@ -640,29 +618,28 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
-
-            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+            reset( archivaConfiguration );
+            reset( request );
+            reset( repoFactory );
 
-            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            when( archivaConfiguration.getConfiguration() ).thenReturn( config );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+            when( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).thenReturn( internalRepo );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+            when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
 
-            archivaConfigurationControl.replay();
-            repoContentFactoryControl.replay();
-            requestControl.replay();
+            when( request.getContextPath() ).thenReturn( "" );
 
             resourceFactory.createResource( locator, request, response );
-
-            archivaConfigurationControl.verify();
-            repoContentFactoryControl.verify();
-            requestControl.verify();
+            verify( archivaConfiguration, times( 2 ) ).getConfiguration( );
+            verify( request, times( 3 ) ).getMethod( );
+            verify( request, times( 3 ) ).getRemoteAddr( );
+            verify( request, times( 2 ) ).getDavSession( );
+            verify( request, times( 2 ) ).getContextPath( );
 
             fail( "A 404 error should have been thrown!" );
         }
@@ -693,29 +670,30 @@ public class ArchivaDavResourceFactoryTest
 
         try
         {
-            archivaConfigurationControl.reset();
-
-            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 2 );
+            reset( archivaConfiguration );
+            reset( request );
+            reset( repoFactory );
 
-            expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
+            when( archivaConfiguration.getConfiguration() ).thenReturn( config );
 
-            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+            when( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).thenReturn( legacyRepo );
 
-            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+            when( request.getMethod() ).thenReturn( "GET" );
 
-            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            when( request.getRemoteAddr() ).thenReturn( "http://localhost:8080" );
 
-            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
+            when( request.getDavSession() ).thenReturn( new ArchivaDavSession() );
 
-            archivaConfigurationControl.replay();
-            repoContentFactoryControl.replay();
-            requestControl.replay();
+            when( request.getContextPath() ).thenReturn( "" );
 
             resourceFactory.createResource( locator, request, response );
 
-            archivaConfigurationControl.verify();
-            repoContentFactoryControl.verify();
-            requestControl.verify();
+            verify( archivaConfiguration,
+                times( 2 ) ).getConfiguration( );
+            verify( request, times( 3 ) ).getMethod( );
+            verify( request, times( 3 ) ).getRemoteAddr( );
+            verify( request, times( 2 ) ).getDavSession( );
+            verify( request, times( 2 ) ).getContextPath( );
 
             fail( "A 404 error should have been thrown!" );
         }
index 36e1f1dca6a52c06a48dc7233bd3775cca2a78bd..bba326e6579f40c219a6a61392e72d37f6206476 100644 (file)
@@ -43,13 +43,12 @@ import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.jackrabbit.webdav.DavSessionProvider;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.Mockito;
 import org.springframework.context.ApplicationContext;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
@@ -72,8 +71,11 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.eq;
+import static org.mockito.AdditionalMatchers.not;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.*;
+
 
 /**
  * RepositoryServletSecurityTest Test the flow of the authentication and authorization checks. This does not necessarily
@@ -98,12 +100,8 @@ public class RepositoryServletSecurityTest
 
     private DavSessionProvider davSessionProvider;
 
-    private IMocksControl servletAuthControl;
-
     private ServletAuthenticator servletAuth;
 
-    private IMocksControl httpAuthControl;
-
     private HttpAuthenticator httpAuth;
 
     private RepositoryServlet servlet;
@@ -164,13 +162,9 @@ public class RepositoryServletSecurityTest
         CacheManager.getInstance().clearAll();
 
 
-        servletAuthControl = EasyMock.createControl();
-
-        servletAuth = servletAuthControl.createMock( ServletAuthenticator.class );
-
-        httpAuthControl = EasyMock.createControl();
+        servletAuth = mock( ServletAuthenticator.class );
 
-        httpAuth = httpAuthControl.createMock( HttpAuthenticator.class );
+        httpAuth = mock( HttpAuthenticator.class );
 
         davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
 
@@ -257,20 +251,16 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any(  ),
+                                                           any(  ) ) ).thenReturn(
             result );
 
-        servletAuth.isAuthenticated( EasyMock.anyObject( HttpServletRequest.class ),
-                                     EasyMock.anyObject( AuthenticationResult.class ) );
-        EasyMock.expectLastCall().andThrow( new AuthenticationException( "Authentication error" ) );
+        when(servletAuth.isAuthenticated( any(  ),
+                                     any(  ) )).thenThrow( new AuthenticationException( "Authentication error" ) );
 
-        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT );
+        when(servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ))
+            .thenThrow( new UnauthorizedException( "'guest' has no write access to repository" ) );
 
-        EasyMock.expectLastCall().andThrow( new UnauthorizedException( "'guest' has no write access to repository" ) );
-
-        httpAuthControl.replay();
-        servletAuthControl.replay();
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
         mockHttpServletRequest.setMethod( "PUT" );
@@ -282,9 +272,6 @@ public class RepositoryServletSecurityTest
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
 
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
     }
 
@@ -293,7 +280,6 @@ public class RepositoryServletSecurityTest
     public void testPutWithInvalidUserAndGuestHasWriteAccess()
         throws Exception
     {
-        
         servlet.setDavSessionProvider( davSessionProvider );
 
         ArchivaDavResourceFactory archivaDavResourceFactory = (ArchivaDavResourceFactory) servlet.getResourceFactory();
@@ -304,40 +290,35 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any(  ),
+                                                           any(  ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andThrow(
-            new AuthenticationException( "Authentication error" ) );
 
-        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
-                                                   ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).andReturn(
+        when( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).thenReturn(
             true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andThrow(
+        when( servletAuth.isAuthenticated( any( ),
+            any( ) ) ).thenThrow(
             new AuthenticationException( "Authentication error" ) );
 
-        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
+        when( httpAuth.getSessionUser( any( ) ) ).thenReturn( null );
 
         // check if guest has write access
-        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
-                                                   ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).andReturn(
+        when( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ).thenReturn(
             true );
 
-        httpAuthControl.replay();
-        servletAuthControl.replay();
-
         InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
         assertNotNull( "artifact.jar inputstream", is );
 
@@ -352,9 +333,6 @@ public class RepositoryServletSecurityTest
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
 
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_CREATED, mockHttpServletResponse.getStatus() );
     }
 
@@ -373,37 +351,34 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+        when( servletAuth.isAuthenticated( any( ),
+                                                      any( ) ) ).thenReturn( true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
 
-        EasyMock.expect( httpAuth.getSecuritySession( mockHttpServletRequest.getSession( true ) ) ).andReturn(
+        when( httpAuth.getSecuritySession( mockHttpServletRequest.getSession( true ) ) ).thenReturn(
             session );
 
-        EasyMock.expect( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).andReturn( new SimpleUser() );
+        when( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).thenReturn( new SimpleUser() );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+        when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
             true );
 
-        EasyMock.expect(
-            servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
-                                      eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).andThrow(
+        when(
+            servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+                                      eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).thenThrow(
             new UnauthorizedException( "User not authorized" ) );
-        httpAuthControl.replay();
-        servletAuthControl.replay();
-
         InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
         assertNotNull( "artifact.jar inputstream", is );
 
@@ -416,10 +391,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
     }
 
@@ -447,12 +418,12 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+        when( servletAuth.isAuthenticated( any( ),
+                                                      any( ) ) ).thenReturn( true );
 
         User user = new SimpleUser();
         user.setUsername( "admin" );
@@ -460,23 +431,20 @@ public class RepositoryServletSecurityTest
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( httpAuth.getSecuritySession( mockHttpServletRequest.getSession() ) ).andReturn( session );
+        when( httpAuth.getSecuritySession( mockHttpServletRequest.getSession() ) ).thenReturn( session );
 
-        EasyMock.expect( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).andReturn( user );
+        when( httpAuth.getSessionUser( mockHttpServletRequest.getSession() ) ).thenReturn( user );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+        when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
             true );
 
-        EasyMock.expect(
-            servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
-                                      eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).andReturn( true );
-
-        httpAuthControl.replay();
-        servletAuthControl.replay();
+        when(
+            servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+                                      eq( ArchivaRoleConstants.OPERATION_ADD_ARTIFACT ) ) ).thenReturn( true );
 
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
         mockHttpServletRequest.setMethod( "PUT" );
@@ -487,10 +455,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_CREATED, mockHttpServletResponse.getStatus() );
 
         assertEquals( "admin", listener.getEvents().get( 0 ).getUserId() );
@@ -519,38 +483,31 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andThrow(
-            new AuthenticationException( "Authentication error" ) );
 
-        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
-                                                   ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).andReturn(
+        when( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).thenReturn(
             true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
-            result );
-
-        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
 
-        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
+        when( httpAuth.getSessionUser( any( ) ) ).thenReturn( null );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+        when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
             true );
+        when( servletAuth.isAuthenticated( any( ),
+            not(eq(result)) ) ).thenThrow(
+            new AuthenticationException( "Authentication error" ) );
 
-        EasyMock.expect(
-            servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
-                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andReturn( true );
-        httpAuthControl.replay();
-        servletAuthControl.replay();
-
+        when(
+            servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenReturn( true );
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
         mockHttpServletRequest.setMethod( "GET" );
@@ -559,10 +516,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus() );
 
         assertEquals( "Expected file contents", expectedArtifactContents, mockHttpServletResponse.getContentAsString() );
@@ -585,20 +538,17 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andThrow(
+        when( servletAuth.isAuthenticated( any( ),
+                                                      any( ) ) ).thenThrow(
             new AuthenticationException( "Authentication error" ) );
 
-        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
-                                                   ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).andReturn(
+        when( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ).thenReturn(
             false );
-        httpAuthControl.replay();
-        servletAuthControl.replay();
-
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
         mockHttpServletRequest.setMethod( "GET" );
@@ -607,10 +557,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
     }
 
@@ -637,32 +583,29 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+        when( servletAuth.isAuthenticated( any( ),
+                                                      any( ) ) ).thenReturn( true );
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
 
-        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() );
+        when( httpAuth.getSessionUser( any( ) ) ).thenReturn( new SimpleUser() );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+        when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
             true );
 
-        EasyMock.expect(
-            servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
-                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andReturn( true );
-
-        httpAuthControl.replay();
-        servletAuthControl.replay();
+        when(
+            servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenReturn( true );
 
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
@@ -672,10 +615,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_OK, mockHttpServletResponse.getStatus() );
         assertEquals( "Expected file contents", expectedArtifactContents, mockHttpServletResponse.getContentAsString() );
     }
@@ -703,34 +642,31 @@ public class RepositoryServletSecurityTest
 
         AuthenticationResult result = new AuthenticationResult();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
-                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
+        when( servletAuth.isAuthenticated( any( ),
+                                                      any( ) ) ).thenReturn( true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
 
-        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
-                                                           anyObject( HttpServletResponse.class ) ) ).andReturn(
+        when( httpAuth.getAuthenticationResult( any( ),
+                                                           any( ) ) ).thenReturn(
             result );
 
-        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        when( httpAuth.getSecuritySession( any( ) ) ).thenReturn( session );
 
-        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() );
+        when( httpAuth.getSessionUser( any( ) ) ).thenReturn( new SimpleUser() );
 
-        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq( result ) ) ).andReturn(
+        when( servletAuth.isAuthenticated( any( ), eq( result ) ) ).thenReturn(
             true );
 
-        EasyMock.expect(
-            servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq( session ), eq( "internal" ),
-                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).andThrow(
+        when(
+            servletAuth.isAuthorized( any( ), eq( session ), eq( "internal" ),
+                                      eq( ArchivaRoleConstants.OPERATION_READ_REPOSITORY ) ) ).thenThrow(
             new UnauthorizedException( "User not authorized to read repository." ) );
-        httpAuthControl.replay();
-        servletAuthControl.replay();
-
         MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
         mockHttpServletRequest.addHeader( "User-Agent", "foo" );
         mockHttpServletRequest.setMethod( "GET" );
@@ -740,10 +676,6 @@ public class RepositoryServletSecurityTest
         MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
 
         servlet.service( mockHttpServletRequest, mockHttpServletResponse );
-
-        httpAuthControl.verify();
-        servletAuthControl.verify();
-
         assertEquals( HttpServletResponse.SC_UNAUTHORIZED, mockHttpServletResponse.getStatus() );
     }
 
index 58bb31b62dc2c6d1a7bbd4883f6a27fef31613a1..c5be4d834144a1f8b2afe36e8d81b54fd5bda33f 100644 (file)
@@ -31,7 +31,7 @@
 
   <properties>
     <site.staging.base>${project.parent.parent.basedir}</site.staging.base>
-    <cassandraVersion>3.11.10</cassandraVersion>
+    <cassandraVersion>3.11.11</cassandraVersion>
     <datastax.driver.version>4.13.0</datastax.driver.version>
   </properties>
 
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>cassandra-maven-plugin</artifactId>
-        <version>3.6</version>
+        <version>3.7-SNAPSHOT</version>
         <executions>
           <execution>
             <id>start-cassandra</id>
@@ -334,4 +334,15 @@ num_tokens: 1
     </pluginManagement>
   </build>
 
+  <profiles>
+    <profile>
+      <id>jdk9+</id>
+      <activation>
+        <jdk>[1.9,)</jdk>
+      </activation>
+      <properties >
+        <cassandra.addJdk11Options>true</cassandra.addJdk11Options>
+      </properties>
+    </profile>
+  </profiles>
 </project>
index a6c4bf0fe6574a5cd4784878962926d538c5304e..c1e07a07a097a2b890139a811768d8f102fb59b1 100644 (file)
@@ -27,8 +27,6 @@ import org.apache.archiva.metadata.repository.MetadataService;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.cassandra.model.ProjectVersionMetadataModel;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -50,8 +48,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate;
-import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * @author Olivier Lamy
@@ -67,10 +66,8 @@ public class CassandraMetadataRepositoryTest
 
     CassandraMetadataRepository cmr;
 
-    IMocksControl sessionFactoryControl;
     RepositorySessionFactory sessionFactory;
 
-    IMocksControl sessionControl;
     RepositorySession session;
 
     long cTime;
@@ -111,14 +108,10 @@ public class CassandraMetadataRepositoryTest
 
         this.cmr = new CassandraMetadataRepository( metadataService, cassandraArchivaManager );
 
-        sessionFactoryControl = EasyMock.createControl( );
-        sessionFactory = sessionFactoryControl.createMock( RepositorySessionFactory.class );
-        sessionControl = EasyMock.createControl( );
-        session = sessionControl.createMock( RepositorySession.class );
+        sessionFactory = mock( RepositorySessionFactory.class );
+        session = mock( RepositorySession.class );
 
-        EasyMock.expect( sessionFactory.createSession( ) ).andStubReturn( session );
-
-        sessionFactoryControl.replay();
+        when( sessionFactory.createSession( ) ).thenReturn( session );
 
         if (!clearedTables.get())
         {
index c67e4d3484d4ace2c22cb97d12010a8a55640048..7bcc68758e9bd31c9c638f783fdaf632bb1f1904 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.archiva.metadata.repository.cassandra;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.repository.cassandra.model.Namespace;
 import org.apache.archiva.metadata.repository.cassandra.model.Repository;
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
index c3eea17ded4998145a946f9608d3a7f0dd8516fd..af5c0b949cfd595dcfeebbc9b8f094058ad058ba 100644 (file)
 
     <!-- Test scope -->
     <dependency>
-      <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-test-utils</artifactId>
-      <version>${project.version}</version>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-test-utils</artifactId>
+      <version>${project.version}</version>
       <scope>test</scope>
     </dependency>
 
index 4622b1b3fd9f302f5469b05ef29e5f7c968af2a0..f0cb5d2cc3746895107919a579005459a449d760 100644 (file)
@@ -25,10 +25,7 @@ import org.apache.archiva.metadata.model.facets.AuditEvent;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.apache.archiva.repository.Repository;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -45,14 +42,15 @@ import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 @RunWith(ArchivaBlockJUnit4ClassRunner.class)
 public class AuditManagerTest
     extends TestCase
 {
     private DefaultAuditManager auditManager;
 
-    private IMocksControl metadataRepositoryControl;
-
     private MetadataRepository metadataRepository;
 
     private RepositorySessionFactory repositorySessionFactory;
@@ -74,8 +72,6 @@ public class AuditManagerTest
     private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
 
     private static final DecimalFormat MILLIS_FORMAT = new DecimalFormat( "000" );
-    private IMocksControl factoryControl;
-    private IMocksControl sessionControl;
 
     private static SimpleDateFormat createTimestampFormat()
     {
@@ -93,14 +89,11 @@ public class AuditManagerTest
 
         auditManager = new DefaultAuditManager();
 
-        metadataRepositoryControl = EasyMock.createControl();
-        metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+        metadataRepository = mock( MetadataRepository.class );
 
-        factoryControl = EasyMock.createControl();
-        repositorySessionFactory = factoryControl.createMock(RepositorySessionFactory.class);
+        repositorySessionFactory = mock(RepositorySessionFactory.class);
 
-        sessionControl = EasyMock.createControl( );
-        session = sessionControl.createMock( RepositorySession.class );
+        session = mock( RepositorySession.class );
 
         auditManager.setRepositorySessionFactory( repositorySessionFactory );
 
@@ -121,19 +114,15 @@ public class AuditManagerTest
             expectedEvents.add( event );
         }
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     getEventNames(expectedEvents));
 
             for (AuditEvent event : expectedEvents.subList(1, expectedEvents.size())) {
-                EasyMock.expect(
-                        metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(
+                when(
+                        metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).thenReturn(
                         event);
             }
-        metadataRepositoryControl.replay();
 
         List<AuditEvent> events =
             auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
@@ -147,7 +136,6 @@ public class AuditManagerTest
             expectedTimestampCounter--;
         }
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -161,18 +149,14 @@ public class AuditManagerTest
             expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) );
         }
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     getEventNames(expectedEvents));
             for (AuditEvent event : expectedEvents) {
-                EasyMock.expect(
-                        metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(
+                when(
+                        metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).thenReturn(
                         event);
             }
-        metadataRepositoryControl.replay();
 
         List<AuditEvent> events =
             auditManager.getMostRecentAuditEvents( metadataRepository, Collections.singletonList( TEST_REPO_ID ) );
@@ -186,7 +170,6 @@ public class AuditManagerTest
             expectedTimestampCounter--;
         }
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -194,10 +177,10 @@ public class AuditManagerTest
         throws Exception
     {
         int numEvents = 11;
-        Map<String, List<String>> eventNames = new LinkedHashMap<String, List<String>>();
+        Map<String, List<String>> eventNames = new LinkedHashMap<>( );
         List<AuditEvent> events = new ArrayList<>();
-        eventNames.put( TEST_REPO_ID, new ArrayList<String>() );
-        eventNames.put( TEST_REPO_ID_2, new ArrayList<String>() );
+        eventNames.put( TEST_REPO_ID, new ArrayList<>( ) );
+        eventNames.put( TEST_REPO_ID_2, new ArrayList<>( ) );
         for ( int i = 0; i < numEvents; i++ )
         {
             String repositoryId = i % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
@@ -206,20 +189,16 @@ public class AuditManagerTest
             events.add( event );
             eventNames.get( repositoryId ).add( event.getName() );
         }
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     eventNames.get(TEST_REPO_ID));
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID)).andReturn(
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID)).thenReturn(
                     eventNames.get(TEST_REPO_ID_2));
 
             for (AuditEvent event : events.subList(1, events.size())) {
-                EasyMock.expect(metadataRepository.getMetadataFacet(session, event.getRepositoryId(),
-                        AuditEvent.FACET_ID, event.getName())).andReturn(event);
+                when(metadataRepository.getMetadataFacet(session, event.getRepositoryId(),
+                        AuditEvent.FACET_ID, event.getName())).thenReturn(event);
             }
-        metadataRepositoryControl.replay();
 
         events =
             auditManager.getMostRecentAuditEvents( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ) );
@@ -234,7 +213,6 @@ public class AuditManagerTest
             expectedTimestampCounter--;
         }
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -242,18 +220,13 @@ public class AuditManagerTest
         throws Exception
 
     {
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
-                    Collections.<String>emptyList());
-        metadataRepositoryControl.replay();
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
+                    Collections.emptyList());
 
         assertTrue( auditManager.getMostRecentAuditEvents( metadataRepository,
                                                            Collections.singletonList( TEST_REPO_ID ) ).isEmpty() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -263,17 +236,12 @@ public class AuditManagerTest
     {
         AuditEvent event = createEvent( new Date() );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
             metadataRepository.addMetadataFacet(session, TEST_REPO_ID, event);
 
-        metadataRepositoryControl.replay();
 
         auditManager.addAuditEvent( metadataRepository, event );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -285,11 +253,7 @@ public class AuditManagerTest
 
         // should just be ignored
 
-        metadataRepositoryControl.replay();
-
         auditManager.addAuditEvent( metadataRepository, event );
-
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -298,18 +262,12 @@ public class AuditManagerTest
 
     {
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
 
         metadataRepository.removeMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID);
 
-        metadataRepositoryControl.replay();
-
         auditManager.deleteAuditEvents( metadataRepository, TEST_REPO_ID );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -323,19 +281,13 @@ public class AuditManagerTest
         Date expectedTimestamp = new Date( current.getTime() - 3000 );
         AuditEvent expectedEvent = createEvent( expectedTimestamp );
         AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(event1.getName(), expectedEvent.getName(), event3.getName()));
 
             // only match the middle one
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent.getName())).andReturn(expectedEvent);
-
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent.getName())).thenReturn(expectedEvent);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -345,7 +297,6 @@ public class AuditManagerTest
         assertEquals( 1, events.size() );
         assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent.getResource() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -360,19 +311,14 @@ public class AuditManagerTest
         Date ts3 = new Date( current.getTime() - 1000 );
         AuditEvent expectedEvent3 = createEvent( ts3 );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(event1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -381,8 +327,6 @@ public class AuditManagerTest
         assertEquals( 2, events.size() );
         assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
         assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
-
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -397,20 +341,16 @@ public class AuditManagerTest
         AuditEvent expectedEvent2 = createEvent( expectedTimestamp );
         AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
 
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), event3.getName()));
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -420,8 +360,6 @@ public class AuditManagerTest
         assertEquals( 2, events.size() );
         assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
         assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
-
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -437,22 +375,18 @@ public class AuditManagerTest
         Date ts3 = new Date( current.getTime() - 1000 );
         AuditEvent expectedEvent3 = createEvent( ts3 );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -463,7 +397,6 @@ public class AuditManagerTest
         assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( expectedTimestamp ), expectedEvent2.getResource() );
         assertTestEvent( events.get( 2 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -480,23 +413,19 @@ public class AuditManagerTest
         Date ts3 = new Date( current.getTime() - 1000 );
         AuditEvent expectedEvent3 = createEvent( ts3 );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
 
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -506,7 +435,6 @@ public class AuditManagerTest
         assertTestEvent( events.get( 0 ), TIMESTAMP_FORMAT.format( ts3 ), expectedEvent3.getResource() );
         assertTestEvent( events.get( 1 ), TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -521,21 +449,17 @@ public class AuditManagerTest
         expectedEvent2.setResource( "different-resource" );
         AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID)).thenReturn(
                     Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
 
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName())).thenReturn(expectedEvent1);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName())).thenReturn(expectedEvent2);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName())).thenReturn(expectedEvent3);
 
-        metadataRepositoryControl.replay();
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ), "foo",
@@ -543,7 +467,6 @@ public class AuditManagerTest
 
         assertEquals( 0, events.size() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -560,26 +483,22 @@ public class AuditManagerTest
         Date ts3 = new Date( current.getTime() - 1000 );
         AuditEvent expectedEvent3 = createEvent( ts3 );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
-                    .andReturn(Arrays.asList(expectedEvent1.getName(), expectedEvent3.getName()));
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
+                    .thenReturn(Arrays.asList(expectedEvent1.getName(), expectedEvent3.getName()));
 
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID))
-                    .andReturn(Arrays.asList(expectedEvent2.getName()));
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID_2, AuditEvent.FACET_ID))
+                    .thenReturn( Collections.singletonList( expectedEvent2.getName( ) ) );
 
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName()))
-                    .andReturn(expectedEvent1);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName()))
+                    .thenReturn(expectedEvent1);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName()))
-                    .andReturn(expectedEvent2);
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName()))
+                    .thenReturn(expectedEvent2);
 
-            EasyMock.expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName()))
-                    .andReturn(expectedEvent3);
-        metadataRepositoryControl.replay();
+            when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName()))
+                    .thenReturn(expectedEvent3);
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Arrays.asList( TEST_REPO_ID, TEST_REPO_ID_2 ),
@@ -591,7 +510,6 @@ public class AuditManagerTest
                          expectedEvent2.getResource() );
         assertTestEvent( events.get( 2 ), TEST_REPO_ID, TIMESTAMP_FORMAT.format( ts1 ), expectedEvent1.getResource() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -605,13 +523,9 @@ public class AuditManagerTest
         String name2 = createEvent( expectedTimestamp ).getName();
         String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName();
 
-        sessionControl.reset();
-        factoryControl.reset();
-        EasyMock.expect( repositorySessionFactory.createSession() ).andStubReturn( session );
-        factoryControl.replay();
-            EasyMock.expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
-                    .andReturn(Arrays.asList(name1, name2, name3));
-        metadataRepositoryControl.replay();
+        when( repositorySessionFactory.createSession() ).thenReturn( session );
+            when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, AuditEvent.FACET_ID))
+                    .thenReturn(Arrays.asList(name1, name2, name3));
 
         List<AuditEvent> events =
             auditManager.getAuditEventsInRange( metadataRepository, Collections.singletonList( TEST_REPO_ID ),
@@ -620,7 +534,6 @@ public class AuditManagerTest
 
         assertEquals( 0, events.size() );
 
-        metadataRepositoryControl.verify();
     }
 
     private static String getDefaultTestResourceName( String num )
index 7fc78285c78e0f36693694a3c8e35bf89a7a0efd..0b117723a3ed7626e43f40eff2768253560ba1de 100644 (file)
@@ -70,8 +70,8 @@
 
     <!-- Test dependencies -->
     <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
index f12a17ae8af18ac48581181bd042581b1ddb2ca8..4760135a96eb21750051dbb554125be249cd7216 100644 (file)
@@ -19,19 +19,16 @@ package org.apache.archiva.metadata.repository.stats;
  * under the License.
  */
 
-import junit.framework.TestCase;
-import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.maven.metadata.model.MavenArtifactFacet;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics;
 import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics;
-import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
-import org.easymock.IMocksControl;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -43,17 +40,16 @@ import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
 
-import static org.easymock.EasyMock.*;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
 
-@RunWith( ArchivaBlockJUnit4ClassRunner.class )
 public class RepositoryStatisticsManagerTest
-    extends TestCase
 {
     private DefaultRepositoryStatisticsManager repositoryStatisticsManager;
 
     private static final String TEST_REPO_ID = "test-repo";
 
-    private IMocksControl metadataRepositoryControl;
 
     private MetadataRepository metadataRepository;
 
@@ -66,8 +62,6 @@ public class RepositoryStatisticsManagerTest
     private static final SimpleDateFormat TIMESTAMP_FORMAT = createTimestampFormat();
 
     private RepositorySessionFactory repositorySessionFactory;
-    private IMocksControl factoryControl;
-    private IMocksControl sessionControl;
     private RepositorySession session;
 
     private static SimpleDateFormat createTimestampFormat()
@@ -77,25 +71,19 @@ public class RepositoryStatisticsManagerTest
         return fmt;
     }
 
-    @Override
-    @Before
+    @BeforeEach
     public void setUp()
         throws Exception
     {
-        super.setUp();
-
         repositoryStatisticsManager = new DefaultRepositoryStatisticsManager();
 
-        metadataRepositoryControl = createControl();
-        metadataRepository = metadataRepositoryControl.createMock( MetadataRepository.class );
+        metadataRepository = mock( MetadataRepository.class );
 
-        factoryControl = createControl();
-        repositorySessionFactory = factoryControl.createMock(RepositorySessionFactory.class);
+        repositorySessionFactory = mock(RepositorySessionFactory.class);
 
         repositoryStatisticsManager.setRepositorySessionFactory( repositorySessionFactory );
 
-        sessionControl = createControl( );
-        session = sessionControl.createMock( RepositorySession.class );
+        session = mock( RepositorySession.class );
 
     }
 
@@ -117,22 +105,16 @@ public class RepositoryStatisticsManagerTest
         stats.setTotalGroupCount( 529 );
         stats.setTotalFileCount( 56229 );
 
-
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
-        expect(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(
+
+        when(metadataRepository.getMetadataFacets(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).thenReturn(
                     Arrays.asList(FIRST_TEST_SCAN, SECOND_TEST_SCAN));
 
-        expect(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
-                    DefaultRepositoryStatistics.FACET_ID, SECOND_TEST_SCAN)).andReturn(stats);
-        metadataRepositoryControl.replay();
+        when(metadataRepository.getMetadataFacet(session, TEST_REPO_ID,
+                    DefaultRepositoryStatistics.FACET_ID, SECOND_TEST_SCAN)).thenReturn(stats);
 
         stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
         assertNotNull( stats );
@@ -146,7 +128,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( SECOND_TEST_SCAN, stats.getName() );
         assertEquals( endTime, stats.getScanEndTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -154,23 +135,16 @@ public class RepositoryStatisticsManagerTest
         throws Exception
     {
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
             Collections.<String>emptyList() );
-        metadataRepositoryControl.replay();
 
         RepositoryStatistics stats = repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID );
         assertNull( stats );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -184,24 +158,17 @@ public class RepositoryStatisticsManagerTest
 
         walkRepository( 1 );
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
             Arrays.asList( stats.getName() ) );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
-            DefaultRepositoryStatistics.FACET_ID, stats.getName() ) ).andReturn( stats );
-
-        metadataRepositoryControl.replay();
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
+            DefaultRepositoryStatistics.FACET_ID, stats.getName() ) ).thenReturn( stats );
 
         repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime, current, 56345,
                                                             45 );
@@ -217,7 +184,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( current.getTime() - 12345, stats.getScanStartTime().getTime() );
         assertEquals( current, stats.getScanEndTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -230,15 +196,9 @@ public class RepositoryStatisticsManagerTest
 
         Date startTime1 = new Date( current.getTime() - 12345 );
         DefaultRepositoryStatistics stats1 = createTestStats( startTime1, new Date( current.getTime() - 6000 ) );
-
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats1 );
 
@@ -247,20 +207,16 @@ public class RepositoryStatisticsManagerTest
         metadataRepository.addMetadataFacet(session , TEST_REPO_ID, stats2 );
 
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
-            Arrays.asList( stats1.getName(), stats2.getName() ) );
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
+            Arrays.asList( stats1.getName(), stats2.getName() ) ).thenReturn( Collections.emptyList() );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
-            DefaultRepositoryStatistics.FACET_ID, stats2.getName() ) ).andReturn( stats2 );
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID,
+            DefaultRepositoryStatistics.FACET_ID, stats2.getName() ) ).thenReturn( stats2 );
         metadataRepository.removeMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
-            Collections.<String>emptyList() );
-
-        metadataRepositoryControl.replay();
-
         repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime1,
-                                                            stats1.getScanEndTime(), 56345, 45 );
+            stats1.getScanEndTime(), 56345, 45 );
+
         repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, startTime2,
                                                             stats2.getScanEndTime(), 56345, 45 );
 
@@ -270,35 +226,27 @@ public class RepositoryStatisticsManagerTest
 
         assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
     public void testDeleteStatsWhenEmpty()
         throws Exception
     {
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn(
-            Collections.<String>emptyList() ).times( 2 );
+        when( metadataRepository.getMetadataFacets( session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn(
+            Collections.<String>emptyList( ) );
         metadataRepository.removeMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
 
-        metadataRepositoryControl.replay();
-
         assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
 
         repositoryStatisticsManager.deleteStatistics( TEST_REPO_ID );
 
         assertNull( repositoryStatisticsManager.getLastStatistics( TEST_REPO_ID ) );
+        verify( metadataRepository, times( 2 ) ).getMetadataFacets( session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -309,33 +257,24 @@ public class RepositoryStatisticsManagerTest
 
         Date current = new Date();
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
-
-
         addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
         addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
         addStats( new Date( current.getTime() - 1000 ), current );
 
         ArrayList<String> keys = new ArrayList<>( statsCreated.keySet() );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
 
         // only match the middle one
         String key = keys.get( 1 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
 
 
-        metadataRepositoryControl.replay();
-
         for ( RepositoryStatistics stats : statsCreated.values() )
         {
             repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -351,7 +290,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( 1, list.size() );
         assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -362,14 +300,9 @@ public class RepositoryStatisticsManagerTest
 
         Date current = new Date();
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
         addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -377,22 +310,20 @@ public class RepositoryStatisticsManagerTest
 
         List<String> keys = new ArrayList<>( statsCreated.keySet() );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
 
         String key = keys.get( 1 );
 
-        expect( metadataRepository.getMetadataFacet(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session, TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
 
         key = keys.get( 2 );
 
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
 
 
-        metadataRepositoryControl.replay();
-
         for ( RepositoryStatistics stats : statsCreated.values() )
         {
             repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -408,7 +339,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
         assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -419,14 +349,9 @@ public class RepositoryStatisticsManagerTest
 
         Date current = new Date();
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
         addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -434,19 +359,17 @@ public class RepositoryStatisticsManagerTest
 
         List<String> keys = new ArrayList<>( statsCreated.keySet() );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
 
         String key = keys.get( 0 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
         key = keys.get( 1 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
 
-        metadataRepositoryControl.replay();
-
         for ( RepositoryStatistics stats : statsCreated.values() )
         {
             repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -463,7 +386,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() );
         assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -474,14 +396,9 @@ public class RepositoryStatisticsManagerTest
 
         Date current = new Date();
 
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
         addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -489,23 +406,21 @@ public class RepositoryStatisticsManagerTest
 
         ArrayList<String> keys = new ArrayList<>( statsCreated.keySet() );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
 
         String key = keys.get( 0 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
         key = keys.get( 1 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
         key = keys.get( 2 );
 
-        expect( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).andReturn(
+        when( metadataRepository.getMetadataFacet(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key ) ).thenReturn(
             statsCreated.get( key ) );
 
-        metadataRepositoryControl.replay();
-
         for ( RepositoryStatistics stats : statsCreated.values() )
         {
             repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID,
@@ -522,7 +437,6 @@ public class RepositoryStatisticsManagerTest
         assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
         assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
 
-        metadataRepositoryControl.verify();
     }
 
     @Test
@@ -532,14 +446,9 @@ public class RepositoryStatisticsManagerTest
         walkRepository( 3 );
 
         Date current = new Date();
-        sessionControl.reset();
-        factoryControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        expect( session.getRepository() ).andStubReturn( metadataRepository );
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
+        when( session.getRepository() ).thenReturn( metadataRepository );
         session.close();
-        expectLastCall( ).anyTimes( );
-        factoryControl.replay();
-        sessionControl.replay();
 
         addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
         addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
@@ -547,9 +456,7 @@ public class RepositoryStatisticsManagerTest
 
         ArrayList<String> keys = new ArrayList<>( statsCreated.keySet() );
 
-        expect( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).andReturn( keys );
-
-        metadataRepositoryControl.replay();
+        when( metadataRepository.getMetadataFacets(session , TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID ) ).thenReturn( keys );
 
         for ( RepositoryStatistics stats : statsCreated.values() )
         {
@@ -565,7 +472,6 @@ public class RepositoryStatisticsManagerTest
 
         assertEquals( 0, list.size() );
 
-        metadataRepositoryControl.verify();
     }
 
     private void addStats( Date startTime, Date endTime )
@@ -616,114 +522,112 @@ public class RepositoryStatisticsManagerTest
     private void walkRepository( int count )
         throws Exception
     {
-        sessionControl.reset();
-        expect( repositorySessionFactory.createSession( ) ).andStubReturn( session );
-        factoryControl.replay();
+        when( repositorySessionFactory.createSession( ) ).thenReturn( session );
 
         for ( int i = 0; i < count; i++ )
         {
 
 
-            expect( metadataRepository.getRootNamespaces(session , TEST_REPO_ID ) ).andReturn( Arrays.asList( "com", "org" ) );
+            when( metadataRepository.getRootNamespaces(session , TEST_REPO_ID ) ).thenReturn( Arrays.asList( "com", "org" ) );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "com" ) ).andReturn( Arrays.<String>asList() );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "com" ) ).thenReturn( Arrays.<String>asList() );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com" ) ).andReturn( Arrays.asList( "example" ) );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com" ) ).thenReturn( Arrays.asList( "example" ) );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com.example" ) ).andReturn(
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "com.example" ) ).thenReturn(
                 Arrays.<String>asList() );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "com.example" ) ).andReturn(
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "com.example" ) ).thenReturn(
                 Arrays.asList( "example-project" ) );
 
-            expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "com.example", "example-project" ) ).andReturn(
+            when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "com.example", "example-project" ) ).thenReturn(
                 Arrays.asList( "1.0", "1.1" ) );
 
-            expect(
-                metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).andReturn(
+            when(
+                metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.0" ) ).thenReturn(
                 Arrays.asList( createArtifact( "com.example", "example-project", "1.0", "jar" ),
                                createArtifact( "com.example", "example-project", "1.0", "pom" ) ) );
 
-            expect(
-                metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).andReturn(
+            when(
+                metadataRepository.getArtifacts(session , TEST_REPO_ID, "com.example", "example-project", "1.1" ) ).thenReturn(
                 Arrays.asList( createArtifact( "com.example", "example-project", "1.1", "jar" ),
                                createArtifact( "com.example", "example-project", "1.1", "pom" ) ) );
 
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org" ) ).andReturn( Arrays.asList( "apache", "codehaus" ) );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org" ) ).thenReturn( Arrays.asList( "apache", "codehaus" ) );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.asList( "archiva", "maven" )  );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache" ) ).thenReturn( Arrays.asList( "archiva", "maven" )  );
 
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache" ) ).andReturn( Arrays.<String>asList() );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache" ) ).thenReturn( Arrays.<String>asList() );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.<String>asList() );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.archiva" ) ).thenReturn( Arrays.<String>asList() );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.archiva" ) ).andReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.archiva" ) ).thenReturn( Arrays.asList( "metadata-repository-api", "metadata-model" ) );
 
-            expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) )
-                .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" )  );
+            when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api" ) )
+                .thenReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" )  );
 
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT", "jar" ),
                                            createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3-SNAPSHOT",
                                                            "pom" ) )  );
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-repository-api", "1.3" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "jar" ),
                                            createArtifact( "org.apache.archiva", "metadata-repository-api", "1.3", "pom" ) ) );
 
-            expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) )
-                .andReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" )  );
+            when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model" ) )
+                .thenReturn( Arrays.asList( "1.3-SNAPSHOT", "1.3" )  );
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "jar" ),
                                            createArtifact( "org.apache.archiva", "metadata-model", "1.3-SNAPSHOT", "pom" ) ) );
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.archiva", "metadata-model", "1.3" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "metadata-model", "1.3", "jar" ),
                                            createArtifact( "org.apache.archiva", "metadata-model", "1.3", "pom" ) ) );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.maven" ) ).andReturn( Arrays.<String>asList() );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.apache.maven" ) ).thenReturn( Arrays.<String>asList() );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.maven" ) )
-                .andReturn( Arrays.asList( "maven-model" )  );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.apache.maven" ) )
+                .thenReturn( Arrays.asList( "maven-model" )  );
 
-            expect( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.maven", "maven-model" ) )
-                .andReturn( Arrays.asList( "2.2.1" ) );
+            when( metadataRepository.getProjectVersions(session , TEST_REPO_ID, "org.apache.maven", "maven-model" ) )
+                .thenReturn( Arrays.asList( "2.2.1" ) );
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.apache.maven", "maven-model", "2.2.1" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "jar" ),
                                            createArtifact( "org.apache.archiva", "maven-model", "2.2.1", "pom" ) ) );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus" ) ).andReturn( Arrays.asList( "plexus" ) );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus" ) ).thenReturn( Arrays.asList( "plexus" ) );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org" ) ).andReturn( Arrays.<String>asList(  ) );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org" ) ).thenReturn( Arrays.<String>asList(  ) );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
-                .andReturn( Arrays.<String>asList(  ) );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus" ) )
+                .thenReturn( Arrays.<String>asList(  ) );
 
-            expect( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
-                .andReturn( Arrays.<String>asList(  ) );
+            when( metadataRepository.getChildNamespaces(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
+                .thenReturn( Arrays.<String>asList(  ) );
 
-            expect( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
-                .andReturn( Arrays.asList( "plexus-spring" )  );
+            when( metadataRepository.getProjects(session , TEST_REPO_ID, "org.codehaus.plexus" ) )
+                .thenReturn( Arrays.asList( "plexus-spring" )  );
 
-            expect( metadataRepository.getProjectVersions(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) )
-                .andReturn( Arrays.asList( "1.0", "1.1", "1.2" ) );
+            when( metadataRepository.getProjectVersions(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring" ) )
+                .thenReturn( Arrays.asList( "1.0", "1.1", "1.2" ) );
 
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.0" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "jar" ),
                                            createArtifact( "org.codehaus.plexus", "plexus-spring", "1.0", "pom" ) ) );
 
-            expect( metadataRepository.getArtifacts(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
+            when( metadataRepository.getArtifacts(session, TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.1" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "jar" ),
                                            createArtifact( "org.codehaus.plexus", "plexus-spring", "1.1", "pom" ) )  );
 
-            expect( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) )
-                .andReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ),
+            when( metadataRepository.getArtifacts(session , TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2" ) )
+                .thenReturn( Arrays.asList( createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "jar" ),
                                            createArtifact( "org.codehaus.plexus", "plexus-spring", "1.2", "pom" ) )  );
         }
     }
diff --git a/pom.xml b/pom.xml
index a61ecc51d9cca8c6eebb0e00e42e4e66678427f7..3885563fb694ba3d57279605390337d185380790 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@
 
     <openjpaVersion>3.1.1</openjpaVersion>
 
-    <modelmapper.version>2.3.5</modelmapper.version>
+    <modelmapper.version>2.4.5</modelmapper.version>
 
     <sisu-inject-plexus.version>0.3.3</sisu-inject-plexus.version>
     <plexus-utils.version>3.2.1</plexus-utils.version>
@@ -94,8 +94,6 @@
 
     <springockito.version>1.0.9</springockito.version>
 
-    <easymock.version>4.1</easymock.version>
-
     <jacoco.plugin.version>0.7.9</jacoco.plugin.version>
 
     <joda.time.version>1.5.2</joda.time.version>
         <scope>test</scope>
       </dependency>
 
-      <dependency>
-        <groupId>org.easymock</groupId>
-        <artifactId>easymock</artifactId>
-        <version>${easymock.version}</version>
-        <scope>test</scope>
-      </dependency>
-
       <dependency>
         <groupId>org.json</groupId>
         <artifactId>json</artifactId>
     </dependency>
     
 
-    <!--
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymock</artifactId>
-      <version>3.2</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.easymock</groupId>
-      <artifactId>easymockclassextension</artifactId>
-      <version>3.2</version>
-      <scope>test</scope>
-    </dependency>
-    -->
   </dependencies>