From 866fbdff7aa1633701ca1fc17992544d3d04262a Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 18 Mar 2010 04:26:23 +0000 Subject: [PATCH] [MRM-958] switch tests to Mockito and make it easier to abstract git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@924631 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugins/metadata-repository-file/pom.xml | 6 ++++++ .../file/FileMetadataRepositoryTest.java | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/archiva-modules/plugins/metadata-repository-file/pom.xml b/archiva-modules/plugins/metadata-repository-file/pom.xml index e93da3c15..e0cafb13c 100644 --- a/archiva-modules/plugins/metadata-repository-file/pom.xml +++ b/archiva-modules/plugins/metadata-repository-file/pom.xml @@ -25,6 +25,7 @@ org.apache.archiva 1.4-SNAPSHOT + metadata-repository-file File System Backed Metadata Repository @@ -59,5 +60,10 @@ plexus-spring test + + org.mockito + mockito-all + test + diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java index 4288c5a95..8c8e87a32 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java @@ -25,12 +25,13 @@ import org.apache.archiva.metadata.model.MetadataFacet; import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.codehaus.plexus.spring.PlexusInSpringTestCase; -import org.easymock.MockControl; import java.io.File; import java.util.ArrayList; @@ -44,13 +45,16 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * @todo should this be a generic MetadataRepository implementation test? */ public class FileMetadataRepositoryTest extends PlexusInSpringTestCase { - private FileMetadataRepository repository; + private MetadataRepository repository; private static final String TEST_REPO_ID = "test"; @@ -81,17 +85,15 @@ public class FileMetadataRepositoryTest { super.setUp(); - repository = new FileMetadataRepository(); + FileMetadataRepository repository = new FileMetadataRepository(); File directory = getTestFile( "target/test-repositories" ); FileUtils.deleteDirectory( directory ); - MockControl control = MockControl.createControl( ArchivaConfiguration.class ); - ArchivaConfiguration config = (ArchivaConfiguration) control.getMock(); + ArchivaConfiguration config = mock( ArchivaConfiguration.class ); Configuration configData = new Configuration(); configData.addManagedRepository( createManagedRepository( TEST_REPO_ID, directory ) ); configData.addManagedRepository( createManagedRepository( OTHER_REPO, directory ) ); - control.expectAndDefaultReturn( config.getConfiguration(), configData ); - control.replay(); + when( config.getConfiguration() ).thenReturn( configData ); repository.setConfiguration( config ); Map factories = new HashMap(); @@ -122,6 +124,8 @@ public class FileMetadataRepositoryTest } } ); repository.setMetadataFacetFactories( factories ); + + this.repository = repository; } private static ManagedRepositoryConfiguration createManagedRepository( String repoId, File directory ) @@ -150,6 +154,7 @@ public class FileMetadataRepositoryTest } public void testUpdateProjectVersionMetadataIncomplete() + throws MetadataResolutionException { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -161,6 +166,7 @@ public class FileMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithExistingFacets() + throws MetadataResolutionException { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); @@ -182,6 +188,7 @@ public class FileMetadataRepositoryTest } public void testUpdateProjectVersionMetadataWithNoExistingFacets() + throws MetadataResolutionException { ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_PROJECT_VERSION ); -- 2.39.5