[myblog] r431 committed - add easyMock for page test.

3 views
Skip to first unread message

myb...@googlecode.com

unread,
May 16, 2011, 5:05:57 AM5/16/11
to mybl...@googlegroups.com
Revision: 431
Author: rory.cn
Date: Mon May 16 02:05:31 2011
Log: add easyMock for page test.
http://code.google.com/p/myblog/source/detail?r=431

Added:
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page

/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page/EntriesPageTest.java
Deleted:
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/AppTest.java
Modified:
/trunk/myblog-web/pom.xml

/trunk/myblog-web/src/main/java/com/jdkcn/myblog/web/page/admin/Entries.java

=======================================
--- /dev/null
+++
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page/EntriesPageTest.java
Mon May 16 02:05:31 2011
@@ -0,0 +1,57 @@
+package com.jdkcn.myblog.web.page;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.jdkcn.myblog.Constants;
+import com.jdkcn.myblog.condition.EntryCondition;
+import com.jdkcn.myblog.domain.Entry;
+import com.jdkcn.myblog.hibernate.Condition;
+import com.jdkcn.myblog.service.EntryService;
+import com.jdkcn.myblog.service.impl.EntryServiceImpl;
+import com.jdkcn.myblog.util.PaginationSupport;
+import com.jdkcn.myblog.util.Range;
+import com.jdkcn.myblog.util.Sorter;
+import com.jdkcn.myblog.web.page.admin.Entries;
+
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @author <a href="mailto:ror...@gmail.com">Rory</a>
+ * @version $Id$
+ */
+public class EntriesPageTest {
+
+ @Test
+ public void testEntriesPage() throws Exception {
+
+ EntryService entryServiceMock =
EasyMock.createMock(EntryServiceImpl.class);
+
+ List<Entry> list = new LinkedList<Entry>();
+ list.add(new Entry());
+ PaginationSupport<Entry> ps = new PaginationSupport<Entry>(list,
list.size());
+
+ expect(entryServiceMock.search(EasyMock.anyObject(Condition.class),
EasyMock.anyObject(Range.class),
EasyMock.anyObject(Sorter.class))).andReturn(ps)
+ .times(1);
+
+ // expect(sorter.desc("createDate")).andReturn(sorter).times(1);
+ // expect(range).andReturn(new Range(0,
Constants.DEFAULT_PAGE_SIZE)).times(1);
+
+ Entries entries = new Entries(entryServiceMock);
+
+ replay(entryServiceMock);
+
+ entries.get();
+
+ Assert.assertEquals(1, entries.getEntries().size());
+ verify(entryServiceMock);
+
+ }
+}
=======================================
--- /trunk/myblog-web/src/test/java/com/jdkcn/myblog/AppTest.java Wed Apr
27 22:43:33 2011
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Copyright (c) 2005-2011, Rory Ye
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
met:
- *
- * * Redistributions of source code must retain the above copyright
notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
notice,
- * this list of conditions and the following disclaimer in the
documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the Jdkcn.com nor the names of its
contributors may
- * be used to endorse or promote products derived from this software
without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.jdkcn.myblog;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}
=======================================
--- /trunk/myblog-web/pom.xml Thu May 12 19:20:20 2011
+++ /trunk/myblog-web/pom.xml Mon May 16 02:05:31 2011
@@ -70,5 +70,12 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>3.0</version>
+ <type>jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
=======================================
---
/trunk/myblog-web/src/main/java/com/jdkcn/myblog/web/page/admin/Entries.java
Thu May 12 00:42:10 2011
+++
/trunk/myblog-web/src/main/java/com/jdkcn/myblog/web/page/admin/Entries.java
Mon May 16 02:05:31 2011
@@ -49,7 +49,6 @@
@Decorated
public class Entries extends AdminLayout{

- @Inject
private EntryService entryService;

private PaginationSupport<Entry> ps;
@@ -59,6 +58,11 @@
private Integer size;

private List<Entry> entries;
+
+ @Inject
+ public Entries(EntryService entryService) {
+ this.entryService = entryService;
+ }

public List<Entry> getEntries() {
return entries;

Reply all
Reply to author
Forward
0 new messages