Skip to content

Commit

Permalink
Switch to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Sep 17, 2023
1 parent c430b3b commit 7618b74
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 124 deletions.
4 changes: 2 additions & 2 deletions mrm-api/pom.xml
Expand Up @@ -49,8 +49,8 @@
<artifactId>archetype-common</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
@@ -1,16 +1,16 @@
package org.codehaus.mojo.mrm.api;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class AbstractEntryTest {
class AbstractEntryTest {

// MMOCKRM-13
@Test
public void testPathForRootEntry() {
void testPathForRootEntry() {
FileSystem fileSystem = mock(FileSystem.class);
DefaultDirectoryEntry entry = new DefaultDirectoryEntry(fileSystem, null, "/favicon.ico");

Expand Down
Expand Up @@ -15,13 +15,14 @@
*/
package org.codehaus.mojo.mrm.api.maven;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

class ArtifactTest {

public class ArtifactTest {
@Test
public void testSmokes() throws Exception {
void testSmokes() throws Exception {
assertEquals(new Artifact("foo", "bar", "1.0", "jar"), new Artifact("foo", "bar", "1.0", null, "jar"));
}
}
4 changes: 2 additions & 2 deletions mrm-maven-plugin/pom.xml
Expand Up @@ -112,8 +112,8 @@

<!-- tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -32,20 +32,22 @@
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ProxyArtifactStoreTest {
class ProxyArtifactStoreTest {

private MavenSession mavenSession;

@Before
public void setUp() {
@BeforeEach
void setUp() {
mavenSession = mock(MavenSession.class);
when(mavenSession.getCurrentProject()).thenReturn(new MavenProject() {
{
Expand All @@ -56,8 +58,8 @@ public void setUp() {
when(mavenSession.getRepositorySession()).thenReturn(new DefaultRepositorySystemSession());
}

@Test(expected = ArtifactNotFoundException.class)
public void verifyArtifactNotFoundExceptionOnGet() throws Exception {
@Test
void verifyArtifactNotFoundExceptionOnGet() throws Exception {
RepositorySystem repositorySystem = mock(RepositorySystem.class);
doThrow(ArtifactResolutionException.class).when(repositorySystem).resolveArtifact(any(), any());
FactoryHelper factoryHelper = mock(FactoryHelper.class);
Expand All @@ -68,13 +70,15 @@ public void verifyArtifactNotFoundExceptionOnGet() throws Exception {

ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);

store.get(new Artifact("localhost", "test", "1.0-SNAPSHOT", "pom"));
assertThrowsExactly(
ArtifactNotFoundException.class,
() -> store.get(new Artifact("localhost", "test", "1.0-SNAPSHOT", "pom")));
}

@Test(expected = RuntimeException.class)
public void verifyArtifactResolutionExceptionOnGet() throws Exception {
@Test
void verifyArtifactResolutionExceptionOnGet() throws Exception {
RepositorySystem repositorySystem = mock(RepositorySystem.class);
doThrow(RuntimeException.class).when(repositorySystem).resolveArtifact(any(), any());
doThrow(new RuntimeException("test123")).when(repositorySystem).resolveArtifact(any(), any());
FactoryHelper factoryHelper = mock(FactoryHelper.class);
when(factoryHelper.getRepositorySystem()).thenReturn(repositorySystem);
when(factoryHelper.getRepositoryMetadataManager()).then(i -> mock(RepositoryMetadataManager.class));
Expand All @@ -83,20 +87,23 @@ public void verifyArtifactResolutionExceptionOnGet() throws Exception {

ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);

store.get(new Artifact("localhost", "test", "1.0-SNAPSHOT", "pom"));
RuntimeException exception = assertThrowsExactly(
RuntimeException.class, () -> store.get(new Artifact("localhost", "test", "1.0-SNAPSHOT", "pom")));
assertEquals("test123", exception.getMessage());
}

@Test(expected = RuntimeException.class)
public void verifyArchetypeCatalogNotFoundException() throws Exception {
@Test
void verifyArchetypeCatalogNotFoundException() throws Exception {
ArchetypeManager archetypeManager = mock(ArchetypeManager.class);
doThrow(RuntimeException.class).when(archetypeManager).getLocalCatalog(any());
doThrow(new RuntimeException("test123")).when(archetypeManager).getLocalCatalog(any());
FactoryHelper factoryHelper = mock(FactoryHelper.class);
when(factoryHelper.getRepositorySystem()).then(i -> mock(RepositorySystem.class));
when(factoryHelper.getRepositoryMetadataManager()).then(i -> mock(RepositoryMetadataManager.class));
when(factoryHelper.getArtifactFactory()).then(i -> mock(ArtifactFactory.class));
when(factoryHelper.getArchetypeManager()).thenReturn(archetypeManager);
ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);

store.getArchetypeCatalog();
RuntimeException exception = assertThrowsExactly(RuntimeException.class, store::getArchetypeCatalog);
assertEquals("test123", exception.getMessage());
}
}
4 changes: 2 additions & 2 deletions mrm-servlet/pom.xml
Expand Up @@ -75,8 +75,8 @@
<artifactId>plexus-archiver</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -4,38 +4,39 @@
import org.codehaus.mojo.mrm.api.DirectoryEntry;
import org.codehaus.mojo.mrm.api.FileSystem;
import org.codehaus.mojo.mrm.api.maven.ArtifactStore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ArchetypeCatalogFileEntryTest {
class ArchetypeCatalogFileEntryTest {

@Test
public void testCleanArchetypeCatalogFileEntry() throws Exception {
void testCleanArchetypeCatalogFileEntry() throws Exception {
ArchetypeCatalogFileEntry entry = new ArchetypeCatalogFileEntry(null, null, null);
assertEquals(null, entry.getFileSystem());
assertEquals(null, entry.getParent());
assertNull(entry.getFileSystem());
assertNull(entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
}

@Test
public void testFileSystem() throws Exception {
void testFileSystem() throws Exception {
FileSystem fileSystem = mock(FileSystem.class);
DirectoryEntry root = mock(DirectoryEntry.class);
when(fileSystem.getRoot()).thenReturn(root);
ArchetypeCatalogFileEntry entry = new ArchetypeCatalogFileEntry(fileSystem, null, null);
assertEquals(fileSystem, entry.getFileSystem());
assertEquals(null, entry.getParent());
assertNull(entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
assertEquals("archetype-catalog.xml", entry.toPath());
}

@Test
public void testParent() throws Exception {
void testParent() throws Exception {
FileSystem fileSystem = mock(FileSystem.class);
DirectoryEntry parent = mock(DirectoryEntry.class);
when(fileSystem.getRoot()).thenReturn(parent);
Expand All @@ -47,7 +48,7 @@ public void testParent() throws Exception {
}

@Test
public void testArtifactStore() throws Exception {
void testArtifactStore() throws Exception {
final long lastModified = System.currentTimeMillis();
FileSystem fileSystem = mock(FileSystem.class);
DirectoryEntry parent = mock(DirectoryEntry.class);
Expand All @@ -62,10 +63,6 @@ public void testArtifactStore() throws Exception {
assertEquals("archetype-catalog.xml", entry.toPath());
assertEquals(entry.getLastModified(), lastModified);
assertTrue(entry.getSize() > 0);
try {
assertNotNull(entry.getInputStream());
} finally {
entry.getInputStream().close();
}
assertNotNull(entry.getInputStream());
}
}
Expand Up @@ -25,20 +25,20 @@
import org.codehaus.mojo.mrm.api.maven.Artifact;
import org.codehaus.mojo.mrm.api.maven.ArtifactNotFoundException;
import org.codehaus.mojo.mrm.api.maven.ArtifactStore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ArtifactStoreFileSystemTest {
class ArtifactStoreFileSystemTest {

@Test
public void testGroupMetadataRegex() {
void testGroupMetadataRegex() {
Matcher matcher = ArtifactStoreFileSystem.METADATA.matcher("/commons/maven-metadata.xml");
assertTrue(matcher.matches());
assertEquals("commons/", matcher.group(1));
Expand All @@ -52,7 +52,7 @@ public void testGroupMetadataRegex() {
}

@Test
public void testArtifactRegex() {
void testArtifactRegex() {
Matcher matcher = ArtifactStoreFileSystem.ARTIFACT.matcher("/commons/maven-metadata.xml");
assertFalse(matcher.matches());
matcher = ArtifactStoreFileSystem.ARTIFACT.matcher("/org/apache/maven/maven-metadata.xml");
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testArtifactRegex() {
}

@Test
public void testSnapshotArtifactRegex() {
void testSnapshotArtifactRegex() {
Matcher matcher = ArtifactStoreFileSystem.SNAPSHOT_ARTIFACT.matcher("/commons/maven-metadata.xml");
assertFalse(matcher.matches());
matcher = ArtifactStoreFileSystem.SNAPSHOT_ARTIFACT.matcher("/org/apache/maven/maven-metadata.xml");
Expand Down Expand Up @@ -148,7 +148,7 @@ public void testSnapshotArtifactRegex() {

// MMOCKRM-5
@Test
public void testSiteXmlReleaseVersion() throws Exception {
void testSiteXmlReleaseVersion() throws Exception {
ArtifactStore store = mock(ArtifactStore.class);
when(store.getSize(isA(Artifact.class))).thenThrow(ArtifactNotFoundException.class);
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem(store);
Expand All @@ -157,7 +157,7 @@ public void testSiteXmlReleaseVersion() throws Exception {
}

@Test
public void testSiteXmlSnapshotVersion() throws Exception {
void testSiteXmlSnapshotVersion() throws Exception {
ArtifactStore store = mock(ArtifactStore.class);
when(store.getSize(isA(Artifact.class))).thenThrow(ArtifactNotFoundException.class);
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem(store);
Expand All @@ -167,7 +167,7 @@ public void testSiteXmlSnapshotVersion() throws Exception {
}

@Test
public void testArchetypeCatalogNotFound() throws Exception {
void testArchetypeCatalogNotFound() throws Exception {
ArtifactStore store = mock(ArtifactStore.class);
when(store.getArchetypeCatalogLastModified()).thenThrow(ArchetypeCatalogNotFoundException.class);
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem(store);
Expand All @@ -176,7 +176,7 @@ public void testArchetypeCatalogNotFound() throws Exception {
}

@Test
public void testArchetypeCatalog() throws Exception {
void testArchetypeCatalog() throws Exception {
ArtifactStore store = mock(ArtifactStore.class);
when(store.getArchetypeCatalog()).thenReturn(new ArchetypeCatalog());
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem(store);
Expand Down
Expand Up @@ -2,15 +2,16 @@

import org.apache.maven.archetype.catalog.ArchetypeCatalog;
import org.codehaus.mojo.mrm.api.maven.ArtifactStore;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class CompositeArtifactStoreTest {
class CompositeArtifactStoreTest {

@Test
public void testGetArchetypeCatalog() throws Exception {
void testGetArchetypeCatalog() throws Exception {
ArtifactStore store = mock(ArtifactStore.class);
when(store.getArchetypeCatalog()).thenReturn(new ArchetypeCatalog());
ArtifactStore[] stores = new ArtifactStore[] {store};
Expand Down
Expand Up @@ -4,16 +4,16 @@

import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.archetype.catalog.ArchetypeCatalog;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class DiskArtifactStoreTest {
class DiskArtifactStoreTest {

// MMOCKRM-10
@Test
public void testArchetypeCatalog() throws Exception {
void testArchetypeCatalog() throws Exception {
DiskArtifactStore artifactStore = new DiskArtifactStore(new File("src/test/resources/mmockrm-10"));
ArchetypeCatalog catalog = artifactStore.getArchetypeCatalog();
assertNotNull(catalog);
Expand Down

0 comments on commit 7618b74

Please sign in to comment.