|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This report was generated with an evaluation server license. Purchase Clover or configure your license. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MonthTest | Line # 42 | 75 | 0% | 15 | 3 | 96,6% |
0.9655172
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| (22) | |||
| Result | |||
|
0.1724138
|
net.sourceforge.pebble.domain.MonthTest.testGetBlogForDay
net.sourceforge.pebble.domain.MonthTest.testGetBlogForDay
|
1 PASS | |
|
0.1724138
|
net.sourceforge.pebble.domain.MonthTest.testGetBlogForDay
net.sourceforge.pebble.domain.MonthTest.testGetBlogForDay
|
1 PASS | |
|
0.13793103
|
net.sourceforge.pebble.domain.MonthTest.testGetDate
net.sourceforge.pebble.domain.MonthTest.testGetDate
|
1 PASS | |
|
0.13793103
|
net.sourceforge.pebble.domain.MonthTest.testGetDate
net.sourceforge.pebble.domain.MonthTest.testGetDate
|
1 PASS | |
|
0.12643678
|
net.sourceforge.pebble.domain.MonthTest.testBefore
net.sourceforge.pebble.domain.MonthTest.testBefore
|
1 PASS | |
|
0.12643678
|
net.sourceforge.pebble.domain.MonthTest.testBefore
net.sourceforge.pebble.domain.MonthTest.testBefore
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testGetNextMonth
net.sourceforge.pebble.domain.MonthTest.testGetNextMonth
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testLastDayInMonth
net.sourceforge.pebble.domain.MonthTest.testLastDayInMonth
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testLastDayInMonth
net.sourceforge.pebble.domain.MonthTest.testLastDayInMonth
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testGetPreviousMonth
net.sourceforge.pebble.domain.MonthTest.testGetPreviousMonth
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testGetNextMonth
net.sourceforge.pebble.domain.MonthTest.testGetNextMonth
|
1 PASS | |
|
0.10344828
|
net.sourceforge.pebble.domain.MonthTest.testGetPreviousMonth
net.sourceforge.pebble.domain.MonthTest.testGetPreviousMonth
|
1 PASS | |
|
0.08045977
|
net.sourceforge.pebble.domain.MonthTest.testGetPermalink
net.sourceforge.pebble.domain.MonthTest.testGetPermalink
|
1 PASS | |
|
0.08045977
|
net.sourceforge.pebble.domain.MonthTest.testGetPermalink
net.sourceforge.pebble.domain.MonthTest.testGetPermalink
|
1 PASS | |
|
0.03448276
|
net.sourceforge.pebble.domain.MonthTest.testGetAllDays
net.sourceforge.pebble.domain.MonthTest.testGetAllDays
|
1 PASS | |
|
0.03448276
|
net.sourceforge.pebble.domain.MonthTest.testGetAllDays
net.sourceforge.pebble.domain.MonthTest.testGetAllDays
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetRootBlog
net.sourceforge.pebble.domain.MonthTest.testGetRootBlog
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetRootBlog
net.sourceforge.pebble.domain.MonthTest.testGetRootBlog
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetYear
net.sourceforge.pebble.domain.MonthTest.testGetYear
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetMonth
net.sourceforge.pebble.domain.MonthTest.testGetMonth
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetMonth
net.sourceforge.pebble.domain.MonthTest.testGetMonth
|
1 PASS | |
|
0.022988506
|
net.sourceforge.pebble.domain.MonthTest.testGetYear
net.sourceforge.pebble.domain.MonthTest.testGetYear
|
1 PASS | |
| 1 | /* | |
| 2 | * Copyright (c) 2003-2006, Simon Brown | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions are met: | |
| 7 | * | |
| 8 | * - Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * | |
| 11 | * - Redistributions in binary form must reproduce the above copyright | |
| 12 | * notice, this list of conditions and the following disclaimer in | |
| 13 | * the documentation and/or other materials provided with the | |
| 14 | * distribution. | |
| 15 | * | |
| 16 | * - Neither the name of Pebble nor the names of its contributors may | |
| 17 | * be used to endorse or promote products derived from this software | |
| 18 | * without specific prior written permission. | |
| 19 | * | |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
| 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 30 | * POSSIBILITY OF SUCH DAMAGE. | |
| 31 | */ | |
| 32 | package net.sourceforge.pebble.domain; | |
| 33 | ||
| 34 | import java.util.Calendar; | |
| 35 | import java.util.Date; | |
| 36 | ||
| 37 | /** | |
| 38 | * Tests for the Month class. | |
| 39 | * | |
| 40 | * @author Simon Brown | |
| 41 | */ | |
| 42 | public class MonthTest extends SingleBlogTestCase { | |
| 43 | ||
| 44 | private Month month; | |
| 45 | ||
| 46 | 22 |
protected void setUp() throws Exception { |
| 47 | 22 | super.setUp(); |
| 48 | 22 | month = new Month(blog.getBlogForThisYear(), 7); |
| 49 | } | |
| 50 | ||
| 51 | /** | |
| 52 | * Tests that the root blog is setup correctly. | |
| 53 | */ | |
| 54 | 2 |
public void testGetRootBlog() { |
| 55 | 2 | assertEquals(blog, month.getBlog()); |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Tests the getter for the month property. | |
| 60 | */ | |
| 61 | 2 |
public void testGetMonth() { |
| 62 | 2 | assertEquals(7, month.getMonth()); |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Tests the getter for the yearly blog. | |
| 67 | */ | |
| 68 | 2 |
public void testGetYear() { |
| 69 | 2 | assertEquals(blog.getBlogForThisYear(), month.getYear()); |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * Tests that we can access the previous month. | |
| 74 | */ | |
| 75 | 2 |
public void testGetPreviousMonth() { |
| 76 | 2 | month = blog.getBlogForMonth(2003, 7); |
| 77 | 2 | Month previousMonth = month.getPreviousMonth(); |
| 78 | 2 | assertEquals(2003, previousMonth.getYear().getYear()); |
| 79 | 2 | assertEquals(6, previousMonth.getMonth()); |
| 80 | ||
| 81 | 2 | month = blog.getBlogForMonth(2003, 1); |
| 82 | 2 | previousMonth = month.getPreviousMonth(); |
| 83 | 2 | assertEquals(2002, previousMonth.getYear().getYear()); |
| 84 | 2 | assertEquals(12, previousMonth.getMonth()); |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Tests that we can access the next month. | |
| 89 | */ | |
| 90 | 2 |
public void testGetNextMonth() { |
| 91 | 2 | month = blog.getBlogForMonth(2003, 7); |
| 92 | 2 | Month nextMonth = month.getNextMonth(); |
| 93 | 2 | assertEquals(2003, nextMonth.getYear().getYear()); |
| 94 | 2 | assertEquals(8, nextMonth.getMonth()); |
| 95 | ||
| 96 | 2 | month = blog.getBlogForMonth(2002, 12); |
| 97 | 2 | nextMonth = month.getNextMonth(); |
| 98 | 2 | assertEquals(2003, nextMonth.getYear().getYear()); |
| 99 | 2 | assertEquals(1, nextMonth.getMonth()); |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * Tests that we can compare monthly blogs. | |
| 104 | */ | |
| 105 | 2 |
public void testBefore() { |
| 106 | 2 | Year year2002 = new Year(blog, 2002); |
| 107 | 2 | Year year2003 = new Year(blog, 2003); |
| 108 | 2 | Month month1 = new Month(year2003, 6); |
| 109 | 2 | Month month2 = new Month(year2003, 7); |
| 110 | 2 | assertTrue(month1.before(month2)); |
| 111 | 2 | assertFalse(month2.before(month1)); |
| 112 | ||
| 113 | 2 | month1 = new Month(year2002, 7); |
| 114 | 2 | month2 = new Month(year2003, 7); |
| 115 | 2 | assertTrue(month1.before(month2)); |
| 116 | 2 | assertFalse(month2.before(month1)); |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * Tests that we can get all days for a month. | |
| 121 | */ | |
| 122 | 2 |
public void testGetAllDays() { |
| 123 | 2 | month = new Month(blog.getBlogForThisYear(), 1); |
| 124 | 2 | assertEquals(31, month.getAllDays().length); |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Tests that we can get the day for a specific day. | |
| 129 | */ | |
| 130 | 2 |
public void testGetBlogForDay() { |
| 131 | 2 | Day day = month.getBlogForDay(1); |
| 132 | 2 | assertNotNull(day); |
| 133 | 2 | assertEquals(1, day.getDay()); |
| 134 | ||
| 135 | 2 | try { |
| 136 | 2 | day = month.getBlogForDay(-1); |
| 137 | 0 | fail(); |
| 138 | } catch (IllegalArgumentException iae) { | |
| 139 | } | |
| 140 | ||
| 141 | 2 | try { |
| 142 | 2 | day = month.getBlogForDay(0); |
| 143 | 0 | fail(); |
| 144 | } catch (IllegalArgumentException iae) { | |
| 145 | } | |
| 146 | ||
| 147 | 2 | Calendar cal = blog.getCalendar(); |
| 148 | 2 | cal.setTime(month.getDate()); |
| 149 | 2 | int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); |
| 150 | 2 | day = month.getBlogForDay(maxDay - 1); |
| 151 | 2 | day = month.getBlogForDay(maxDay); |
| 152 | 2 | try { |
| 153 | 2 | day = month.getBlogForDay(maxDay + 1); |
| 154 | 0 | fail(); |
| 155 | } catch (IllegalArgumentException iae) { | |
| 156 | } | |
| 157 | ||
| 158 | } | |
| 159 | ||
| 160 | /** | |
| 161 | * Tests the getter for the date property. | |
| 162 | */ | |
| 163 | 2 |
public void testGetDate() { |
| 164 | 2 | month = blog.getBlogForMonth(2003, 4); |
| 165 | 2 | Date date = month.getDate(); |
| 166 | 2 | Calendar cal = blog.getCalendar(); |
| 167 | 2 | cal.setTime(date); |
| 168 | 2 | assertEquals(2003, cal.get(Calendar.YEAR)); |
| 169 | 2 | assertEquals(4, cal.get(Calendar.MONTH) + 1); |
| 170 | 2 | assertEquals(1, cal.get(Calendar.DAY_OF_MONTH)); |
| 171 | 2 | assertEquals(0, cal.get(Calendar.HOUR)); |
| 172 | 2 | assertEquals(0, cal.get(Calendar.MINUTE)); |
| 173 | 2 | assertEquals(0, cal.get(Calendar.SECOND)); |
| 174 | 2 | assertEquals(0, cal.get(Calendar.MILLISECOND)); |
| 175 | } | |
| 176 | ||
| 177 | /** | |
| 178 | * Tests the permalink. | |
| 179 | */ | |
| 180 | 2 |
public void testGetPermalink() { |
| 181 | 2 | String permalink = blog.getUrl() + "2003/07.html"; |
| 182 | 2 | month = blog.getBlogForMonth(2003, 7); |
| 183 | 2 | assertEquals(permalink, month.getPermalink()); |
| 184 | ||
| 185 | 2 | permalink = blog.getUrl() + "2003/12.html"; |
| 186 | 2 | month = blog.getBlogForMonth(2003, 12); |
| 187 | 2 | assertEquals(permalink, month.getPermalink()); |
| 188 | } | |
| 189 | ||
| 190 | // /** | |
| 191 | // * Tests that all blog entries for a month can be accessed. | |
| 192 | // */ | |
| 193 | // public void testGetAllBlogEntries() { | |
| 194 | // assertTrue(month.getBlogEntries().isEmpty()); | |
| 195 | // | |
| 196 | // // now add an entry | |
| 197 | // BlogEntry blogEntry1 = new BlogEntry(blog); | |
| 198 | // BlogEntry blogEntry1 = month.getBlogForFirstDay().createBlogEntry(); | |
| 199 | // month.getBlogForFirstDay().addEntry(blogEntry1); | |
| 200 | // assertTrue(month.getBlogEntries().size() == 1); | |
| 201 | // assertTrue(month.getBlogEntries().contains(blogEntry1)); | |
| 202 | // | |
| 203 | // // now add a second | |
| 204 | // BlogEntry blogEntry2 = month.getBlogForLastDay().createBlogEntry(); | |
| 205 | // month.getBlogForLastDay().addEntry(blogEntry2); | |
| 206 | // assertTrue(month.getBlogEntries().size() == 2); | |
| 207 | // | |
| 208 | // // check they are reverse ordered by date | |
| 209 | // assertTrue(month.getBlogEntries().get(0) == blogEntry2); | |
| 210 | // assertTrue(month.getBlogEntries().get(1) == blogEntry1); | |
| 211 | // } | |
| 212 | ||
| 213 | 2 |
public void testLastDayInMonth() { |
| 214 | 2 | month = new Month(blog.getBlogForYear(2005), 1); |
| 215 | 2 | assertEquals(31, month.getLastDayInMonth()); |
| 216 | 2 | month = new Month(blog.getBlogForYear(2005), 2); |
| 217 | 2 | assertEquals(28, month.getLastDayInMonth()); |
| 218 | 2 | month = new Month(blog.getBlogForYear(2005), 3); |
| 219 | 2 | assertEquals(31, month.getLastDayInMonth()); |
| 220 | ||
| 221 | 2 | month = new Month(blog.getBlogForYear(2004), 2); |
| 222 | 2 | assertEquals(29, month.getLastDayInMonth()); |
| 223 | } | |
| 224 | ||
| 225 | } | |
|
||||||||||||