[myblog] r433 committed - change the easymock test.

0 views
Skip to first unread message

myb...@googlecode.com

unread,
May 16, 2011, 7:46:20 AM5/16/11
to mybl...@googlegroups.com
Revision: 433
Author: rory.cn
Date: Mon May 16 04:45:33 2011
Log: change the easymock test.
http://code.google.com/p/myblog/source/detail?r=433

Modified:
/trunk/myblog-core/src/main/java/com/jdkcn/myblog/util/Range.java

/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page/EntriesPageTest.java

=======================================
--- /trunk/myblog-core/src/main/java/com/jdkcn/myblog/util/Range.java Sat
May 7 09:23:20 2011
+++ /trunk/myblog-core/src/main/java/com/jdkcn/myblog/util/Range.java Mon
May 16 04:45:33 2011
@@ -29,6 +29,9 @@

import java.io.Serializable;

+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
/**
* @author <a href="mailto:ror...@gmail.com">Rory</a>
* @version $Id$
@@ -64,4 +67,31 @@
public int getEnd() {
return start + size;
}
-}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+ Range other = (Range) obj;
+ return new
EqualsBuilder().appendSuper(super.equals(obj)).append(getStart(),
other.getStart())
+ .append(getSize(), other.getSize()).isEquals();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("start",
getStart()).append("end", getEnd()).append("size", getSize()).toString();
+ }
+}
=======================================
---
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page/EntriesPageTest.java
Mon May 16 02:15:23 2011
+++
/trunk/myblog-web/src/test/java/com/jdkcn/myblog/web/page/EntriesPageTest.java
Mon May 16 04:45:33 2011
@@ -30,12 +30,12 @@
import java.util.LinkedList;
import java.util.List;

+import org.easymock.Capture;
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;
@@ -45,7 +45,6 @@
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;
@@ -63,13 +62,11 @@

List<Entry> list = new LinkedList<Entry>();
list.add(new Entry());
+ Capture<Range> captureRange = new Capture<Range>();
+
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);
+ expect(entryServiceMock.search(EasyMock.anyObject(Condition.class),
EasyMock.capture(captureRange),
EasyMock.anyObject(Sorter.class))).andReturn(ps)
+ .once();

Entries entries = new Entries(entryServiceMock);

@@ -78,7 +75,37 @@
entries.get();

Assert.assertEquals(1, entries.getEntries().size());
+ Assert.assertEquals(Constants.DEFAULT_PAGE_SIZE,
captureRange.getValue().getSize());
verify(entryServiceMock);

+ }
+
+ @Test
+ public void testEntriesPageSearch() throws Exception {
+
+ EntryService entryServiceMock =
EasyMock.createMock(EntryServiceImpl.class);
+
+ List<Entry> list = new LinkedList<Entry>();
+ list.add(new Entry());
+ Capture<Range> captureRange = new Capture<Range>();
+
+ PaginationSupport<Entry> ps = new PaginationSupport<Entry>(list,
list.size());
+ expect(entryServiceMock.search(EasyMock.anyObject(Condition.class),
EasyMock.capture(captureRange),
EasyMock.anyObject(Sorter.class))).andReturn(ps)
+ .once();
+
+ Entries entries = new Entries(entryServiceMock);
+ entries.setP(2);
+ entries.setSize(5);
+
+ replay(entryServiceMock);
+
+ entries.get();
+
+ Assert.assertEquals(1, entries.getEntries().size());
+ Assert.assertEquals(5, captureRange.getValue().getSize());
+ Assert.assertEquals(5, captureRange.getValue().getStart());
+ Assert.assertEquals(10, captureRange.getValue().getEnd());
+ verify(entryServiceMock);
+
}
}

Reply all
Reply to author
Forward
0 new messages