Przeglądaj źródła

Test licenses in CoreAboutDialogModel.

pull/180/head
Greg Holmes 9 lat temu
rodzic
commit
13a9746721

+ 3
- 1
src/com/dmdirc/ui/core/about/CoreAboutDialogModel.java Wyświetl plik

@@ -148,7 +148,9 @@ public class CoreAboutDialogModel implements AboutDialogModel {
148 148
         try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
149 149
             stream.forEach(p -> {
150 150
                 try {
151
-                    componentLicences.add(Licence.create(p.getFileName().toString(),
151
+                    final String filename = p.getFileName().toString();
152
+                    final String[] parts = filename.split(" - ");
153
+                    componentLicences.add(Licence.create(parts[0], parts[1],
152 154
                             Joiner.on('\n').join(Files.readAllLines(p))));
153 155
                 } catch (IOException ex) {
154 156
                     LOGGER.warn("Error reading licence", ex);

+ 3
- 2
src/com/dmdirc/ui/core/about/Licence.java Wyświetl plik

@@ -30,11 +30,12 @@ import com.google.auto.value.AutoValue;
30 30
 @AutoValue
31 31
 public abstract class Licence {
32 32
 
33
+    public abstract String getComponent();
33 34
     public abstract String getName();
34 35
     public abstract String getBody();
35 36
 
36
-    public static Licence create(final String name, final String body) {
37
-        return new AutoValue_Licence(name, body);
37
+    public static Licence create(final String component, final String name, final String body) {
38
+        return new AutoValue_Licence(component, name, body);
38 39
     }
39 40
 
40 41
 }

+ 1
- 0
test-res/com/dmdirc/licences/dmdirc - license4 Wyświetl plik

@@ -0,0 +1 @@
1
+License4-Body

+ 1
- 0
test-res/com/dmdirc/ui/core/about/license1/component1 - license1 Wyświetl plik

@@ -0,0 +1 @@
1
+License1-Body

+ 1
- 0
test-res/com/dmdirc/ui/core/about/license1/component2 - license2 Wyświetl plik

@@ -0,0 +1 @@
1
+License2-Body

+ 1
- 0
test-res/com/dmdirc/ui/core/about/license2/component3 - license3 Wyświetl plik

@@ -0,0 +1 @@
1
+License3-Body

+ 41
- 1
test/com/dmdirc/ui/core/about/CoreAboutDialogModelTest.java Wyświetl plik

@@ -24,10 +24,16 @@ package com.dmdirc.ui.core.about;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27
+import com.dmdirc.plugins.PluginInfo;
27 28
 import com.dmdirc.plugins.PluginManager;
29
+import com.dmdirc.plugins.PluginMetaData;
28 30
 import com.dmdirc.util.ClientInfo;
31
+import com.dmdirc.util.io.FileUtils;
32
+
33
+import com.google.common.collect.Lists;
29 34
 
30 35
 import java.nio.file.Path;
36
+import java.util.List;
31 37
 
32 38
 import org.junit.Before;
33 39
 import org.junit.Test;
@@ -47,14 +53,29 @@ public class CoreAboutDialogModelTest {
47 53
     @Mock private Path path;
48 54
     @Mock private DMDircMBassador eventBus;
49 55
     @Mock private PluginManager pluginManager;
56
+    @Mock private PluginMetaData pluginMetaData1;
57
+    @Mock private PluginMetaData pluginMetaData2;
58
+    @Mock private PluginInfo pluginInfo1;
59
+    @Mock private PluginInfo pluginInfo2;
60
+    private Path pluginPath1;
61
+    private Path pluginPath2;
50 62
     private CoreAboutDialogModel instance;
51 63
 
52 64
     @Before
53 65
     public void setUp() throws Exception {
66
+        pluginPath1 = FileUtils.getPathForResource(getClass().getResource("license1"));
67
+        pluginPath2 = FileUtils.getPathForResource(getClass().getResource("license2"));
54 68
         when(clientInfo.getVersionInformation()).thenReturn("DMDirc Version");
55 69
         when(clientInfo.getOperatingSystemInformation()).thenReturn("OS Version");
56 70
         when(clientInfo.getJavaInformation()).thenReturn("Java Version");
57 71
         when(globalConfig.getOption("identity", "modealiasversion")).thenReturn("ModeAlias Version");
72
+        when(pluginManager.getPluginInfos()).thenReturn(Lists.newArrayList(pluginInfo1, pluginInfo2));
73
+        when(pluginInfo1.getPath("/META-INF/licenses/")).thenReturn(pluginPath1);
74
+        when(pluginInfo2.getPath("/META-INF/licenses/")).thenReturn(pluginPath2);
75
+        when(pluginInfo1.getMetaData()).thenReturn(pluginMetaData1);
76
+        when(pluginInfo2.getMetaData()).thenReturn(pluginMetaData2);
77
+        when(pluginMetaData1.getFriendlyName()).thenReturn("Plugin1");
78
+        when(pluginMetaData2.getFriendlyName()).thenReturn("Plugin2");
58 79
         instance = new CoreAboutDialogModel(globalConfig, path, clientInfo, eventBus, pluginManager);
59 80
         instance.load();
60 81
     }
@@ -88,6 +109,25 @@ public class CoreAboutDialogModelTest {
88 109
 
89 110
     @Test
90 111
     public void testGetLicensedComponents() throws Exception {
91
-        // TODO: Add a virtual file system, mock plugin manager test licences
112
+        final List<LicensedComponent> licensedComponents = instance.getLicensedComponents();
113
+        assertEquals(3, licensedComponents.size());
114
+        assertEquals("DMDirc", licensedComponents.get(0).getName());
115
+        assertEquals("Plugin1", licensedComponents.get(1).getName());
116
+        assertEquals("Plugin2", licensedComponents.get(2).getName());
117
+        assertEquals(1, licensedComponents.get(0).getLicences().size());
118
+        assertEquals("dmdirc", licensedComponents.get(0).getLicences().get(0).getComponent());
119
+        assertEquals("license4", licensedComponents.get(0).getLicences().get(0).getName());
120
+        assertEquals("License4-Body", licensedComponents.get(0).getLicences().get(0).getBody());
121
+        assertEquals(2, licensedComponents.get(1).getLicences().size());
122
+        assertEquals("component1", licensedComponents.get(1).getLicences().get(0).getComponent());
123
+        assertEquals("license1", licensedComponents.get(1).getLicences().get(0).getName());
124
+        assertEquals("License1-Body", licensedComponents.get(1).getLicences().get(0).getBody());
125
+        assertEquals("component2", licensedComponents.get(1).getLicences().get(1).getComponent());
126
+        assertEquals("license2", licensedComponents.get(1).getLicences().get(1).getName());
127
+        assertEquals("License2-Body", licensedComponents.get(1).getLicences().get(1).getBody());
128
+        assertEquals(1, licensedComponents.get(2).getLicences().size());
129
+        assertEquals("component3", licensedComponents.get(2).getLicences().get(0).getComponent());
130
+        assertEquals("license3", licensedComponents.get(2).getLicences().get(0).getName());
131
+        assertEquals("License3-Body", licensedComponents.get(2).getLicences().get(0).getBody());
92 132
     }
93 133
 }

+ 3
- 1
test/com/dmdirc/ui/core/about/LicenceTest.java Wyświetl plik

@@ -30,9 +30,11 @@ public class LicenceTest {
30 30
 
31 31
     @Test
32 32
     public void testLicence() throws Exception {
33
+        final String component = "component";
33 34
         final String name = "name";
34 35
         final String body = "body";
35
-        final Licence licence = Licence.create(name, body);
36
+        final Licence licence = Licence.create(component, name, body);
37
+        assertEquals(component, licence.getComponent());
36 38
         assertEquals(name, licence.getName());
37 39
         assertEquals(body, licence.getBody());
38 40
     }

Ładowanie…
Anuluj
Zapisz