-
Notifications
You must be signed in to change notification settings - Fork 10
/
ArchetypeCatalogFileEntryTest.java
68 lines (61 loc) · 3 KB
/
ArchetypeCatalogFileEntryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.codehaus.mojo.mrm.impl.maven;
import org.apache.maven.archetype.catalog.ArchetypeCatalog;
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.jupiter.api.Test;
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;
class ArchetypeCatalogFileEntryTest {
@Test
void testCleanArchetypeCatalogFileEntry() throws Exception {
ArchetypeCatalogFileEntry entry = new ArchetypeCatalogFileEntry(null, null, null);
assertNull(entry.getFileSystem());
assertNull(entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
}
@Test
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());
assertNull(entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
assertEquals("archetype-catalog.xml", entry.toPath());
}
@Test
void testParent() throws Exception {
FileSystem fileSystem = mock(FileSystem.class);
DirectoryEntry parent = mock(DirectoryEntry.class);
when(fileSystem.getRoot()).thenReturn(parent);
ArchetypeCatalogFileEntry entry = new ArchetypeCatalogFileEntry(fileSystem, parent, null);
assertEquals(fileSystem, entry.getFileSystem());
assertEquals(parent, entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
assertEquals("archetype-catalog.xml", entry.toPath());
}
@Test
void testArtifactStore() throws Exception {
final long lastModified = System.currentTimeMillis();
FileSystem fileSystem = mock(FileSystem.class);
DirectoryEntry parent = mock(DirectoryEntry.class);
when(fileSystem.getRoot()).thenReturn(parent);
ArtifactStore store = mock(ArtifactStore.class);
when(store.getArchetypeCatalog()).thenReturn(new ArchetypeCatalog());
when(store.getArchetypeCatalogLastModified()).thenReturn(lastModified);
ArchetypeCatalogFileEntry entry = new ArchetypeCatalogFileEntry(fileSystem, parent, store);
assertEquals(fileSystem, entry.getFileSystem());
assertEquals(parent, entry.getParent());
assertEquals("archetype-catalog.xml", entry.getName());
assertEquals("archetype-catalog.xml", entry.toPath());
assertEquals(entry.getLastModified(), lastModified);
assertTrue(entry.getSize() > 0);
assertNotNull(entry.getInputStream());
}
}