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-web/archiva-rss | |
parent | 3756ba57f6ebc5e3d256c25c220ae5b83f41eb22 (diff) | |
download | archiva-e236e7f98d2849e96aea56cdc4e308a2911fe8f0.tar.gz archiva-e236e7f98d2849e96aea56cdc4e308a2911fe8f0.zip |
Unifying mocks to mockito
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rss')
3 files changed, 26 insertions, 55 deletions
diff --git a/archiva-modules/archiva-web/archiva-rss/pom.xml b/archiva-modules/archiva-web/archiva-rss/pom.xml index f67f8a4ee..d74c24847 100644 --- a/archiva-modules/archiva-web/archiva-rss/pom.xml +++ b/archiva-modules/archiva-web/archiva-rss/pom.xml @@ -92,11 +92,6 @@ <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> <version>${project.version}</version> @@ -107,6 +102,11 @@ <artifactId>spring-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java index 2e5913108..a92721477 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java @@ -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 ); diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java index 28b679a25..ddb35ff33 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java @@ -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 ) |