diff options
author | Martin Schreier <martin_s@apache.org> | 2022-01-04 20:46:35 +0100 |
---|---|---|
committer | Martin Schreier <martin_s@apache.org> | 2022-01-04 20:46:35 +0100 |
commit | e236e7f98d2849e96aea56cdc4e308a2911fe8f0 (patch) | |
tree | eaa583e66ee8f8ebc0d074965caf4e551d912a93 /archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers | |
parent | 3756ba57f6ebc5e3d256c25c220ae5b83f41eb22 (diff) | |
download | archiva-e236e7f98d2849e96aea56cdc4e308a2911fe8f0.tar.gz archiva-e236e7f98d2849e96aea56cdc4e308a2911fe8f0.zip |
Unifying mocks to mockito
Diffstat (limited to 'archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers')
6 files changed, 34 insertions, 134 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml index c7c69e428..752e88dac 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/pom.xml @@ -168,11 +168,6 @@ <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> <scope>test</scope> diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java index fa4cee018..9dd1d7639 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java @@ -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 ); } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java index 8e497dc2c..0a50b3043 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurgeTest.java @@ -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) ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java index 0deb60d6e..62a894f0c 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/DaysOldRepositoryPurgeTest.java @@ -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); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java index 3af6a44b3..e4f42d8ad 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RepositoryPurgeConsumerTest.java @@ -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 ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java index 97afa7b92..1081380d9 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/RetentionCountRepositoryPurgeTest.java @@ -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); |