1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.changes;
20
21 import java.io.IOException;
22 import java.io.StringWriter;
23 import java.io.Writer;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27
28 import junit.framework.TestCase;
29 import org.apache.maven.plugins.changes.model.Release;
30
31
32
33
34 public class FeedGeneratorTest extends TestCase {
35
36
37
38 public void testIsSupportedFeedType() {
39 final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
40
41 assertTrue("rss_0.9 not supported?", generator.isSupportedFeedType("rss_0.9"));
42 assertTrue("rss_0.91N not supported?", generator.isSupportedFeedType("rss_0.91N"));
43 assertTrue("rss_0.91U not supported?", generator.isSupportedFeedType("rss_0.91U"));
44 assertTrue("rss_0.92 not supported?", generator.isSupportedFeedType("rss_0.92"));
45 assertTrue("rss_0.93 not supported?", generator.isSupportedFeedType("rss_0.93"));
46 assertTrue("rss_0.94 not supported?", generator.isSupportedFeedType("rss_0.94"));
47 assertTrue("rss_1.0 not supported?", generator.isSupportedFeedType("rss_1.0"));
48 assertTrue("rss_2.0 not supported?", generator.isSupportedFeedType("rss_2.0"));
49 assertTrue("atom_0.3 not supported?", generator.isSupportedFeedType("atom_0.3"));
50 assertTrue("atom_1.0 not supported?", generator.isSupportedFeedType("atom_1.0"));
51
52 assertFalse(generator.isSupportedFeedType(""));
53 assertFalse(generator.isSupportedFeedType(null));
54 assertFalse(generator.isSupportedFeedType("rss"));
55 }
56
57
58
59
60
61
62 public void testExport() throws Exception {
63 final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
64 generator.setAuthor("author");
65 generator.setTitle("title");
66 generator.setLink("url");
67 generator.setDateFormat(null);
68
69 Release release = new Release();
70 release.setVersion("1.0");
71 List<Release> releases = new ArrayList<>(1);
72
73 try {
74
75 generator.export(releases, "rss_0.9", new StringWriter(512));
76 fail("0 releases not allowed!");
77 } catch (IOException ex) {
78 assertNotNull(ex.getMessage());
79 }
80
81 releases.add(release);
82
83 for (String type : generator.getSupportedFeedTypes()) {
84 try (Writer writer = new StringWriter(512)) {
85 generator.export(releases, type, writer);
86 String result = writer.toString();
87 assertNotNull(result);
88 assertTrue(result.length() > 0);
89 }
90 }
91 }
92 }