1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.rss

File RssMacroTest.java

 

Code metrics

0
14
4
1
82
41
5
0.36
3.5
4
1.25

Classes

Class Line # Actions
RssMacroTest 36 14 0% 5 1
0.944444494.4%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.internal.macro.rss;
21   
22    import org.xwiki.rendering.macro.MacroExecutionException;
23    import org.xwiki.rendering.macro.rss.RssMacroParameters;
24    import org.jmock.Mockery;
25    import org.jmock.Expectations;
26    import org.junit.Test;
27    import org.junit.Before;
28    import org.junit.Assert;
29   
30    /**
31    * Unit tests for {@link RssMacro}.
32    *
33    * @version $Id: 9cdf84e431d75d112c9ef83cf8d8f4fe11c082bb $
34    * @since 1.9
35    */
 
36    public class RssMacroTest
37    {
38    private RssMacro macro;
39   
 
40  2 toggle @Before
41    public void setUp()
42    {
43  2 this.macro = new RssMacro();
44    }
45   
46    /**
47    * Tests whether the macro throws the appropriate exception
48    * in cases where the required 'feed' parameter is missing.
49    */
 
50  1 toggle @Test
51    public void testRequiredParameterMissing() throws Exception
52    {
53  1 try {
54  1 this.macro.execute(new RssMacroParameters(), null, null);
55  0 Assert.fail("Should have thrown an exception");
56    } catch (MacroExecutionException expected) {
57  1 Assert.assertEquals("The required 'feed' parameter is missing", expected.getMessage());
58    }
59    }
60   
61    /**
62    * Tests the macro's behavior when the server hosting the feeds doesn't respond.
63    */
 
64  1 toggle @Test(expected = MacroExecutionException.class)
65    public void testInvalidDocument() throws Exception
66    {
67    // Use a Mock SyndFeedInput to control what it returns for the test.
68  1 Mockery context = new Mockery();
69  1 final RomeFeedFactory mockFactory = context.mock(RomeFeedFactory.class);
70  1 final RssMacroParameters parameters = new RssMacroParameters();
 
71  1 toggle context.checking(new Expectations() {{
72  1 oneOf(mockFactory).createFeed(with(same(parameters))); will(throwException(
73    new MacroExecutionException("Error")));
74    }});
75  1 this.macro.setFeedFactory(mockFactory);
76   
77    // Dummy URL since a feed URL is mandatory
78  1 parameters.setFeed("http://www.xwiki.org");
79   
80  1 this.macro.execute(parameters, null, null);
81    }
82    }