Skip to content

Commit 583d170

Browse files
committed
#374 Unit tests for Base.find() and RowProcessor back
1 parent 5857754 commit 583d170

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

activejdbc/src/test/java/org/javalite/activejdbc/BaseTest.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
/*
2-
Copyright 2009-2014 Igor Polevoy
2+
Copyright 2009-2015 Igor Polevoy
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
77
8-
http://www.apache.org/licenses/LICENSE-2.0
8+
http://www.apache.org/licenses/LICENSE-2.0
99
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
1515
*/
16-
17-
1816
package org.javalite.activejdbc;
1917

20-
import org.javalite.activejdbc.Base;
21-
import org.javalite.activejdbc.RowListenerAdapter;
2218
import org.javalite.activejdbc.test.ActiveJDBCTest;
2319
import org.junit.Test;
2420

@@ -36,7 +32,7 @@ public void before() throws Exception {
3632
}
3733

3834
@Test
39-
public void testBaseFinder() {
35+
public void testBaseFindWith() {
4036
final List<Map> records = new ArrayList<Map>();
4137
Base.findWith(new RowListenerAdapter() {
4238
@Override public void onNext(Map record) {
@@ -48,23 +44,32 @@ public void testBaseFinder() {
4844
}
4945

5046
@Test
51-
public void testBaseFindAll() {
47+
public void testBaseFind() {
48+
final List<Map> records = new ArrayList<Map>();
49+
Base.find("select * from people order by id", new RowListenerAdapter() {
50+
@Override public void onNext(Map record) {
51+
records.add(record);
52+
}
53+
});
54+
the(records.get(0).get("name")).shouldBeEqual("John");
55+
the(records.get(3).get("name")).shouldBeEqual("Joe");
56+
}
5257

58+
@Test
59+
public void testBaseFindAll() {
5360
List<Map> records = Base.findAll("select * from people");
5461
a(records.size()).shouldBeEqual(4);
5562
}
5663

5764
@Test
5865
public void testBaseFindAllParametrized() {
59-
6066
List<Map> records = Base.findAll("select * from people where last_name = ? and name = ?", "Smith", "John");
6167
a(records.size()).shouldBeEqual(1);
6268
}
6369

6470
@Test
6571
public void testExec() {
6672
int count = Base.exec("insert into people (NAME, LAST_NAME, DOB) values('Mic', 'Jagger', ?)", getTimestamp(1962, 6, 13));
67-
6873
List<Map> results = Base.findAll("select * from people where last_name='Jagger'");
6974
a(1).shouldBeEqual(results.size());
7075
a(1).shouldBeEqual(count);
@@ -79,18 +84,30 @@ public void testExecDelete() {
7984
@Test
8085
public void testExecParametrized() {
8186
Base.exec("insert into people (name, last_name, dob) values(?, ?, ?)", "John", "Silver", getTimestamp(1934, 2, 5));
82-
8387
List<Map> results = Base.findAll("select * from people where last_name=?", "Silver");
8488
a(1).shouldBeEqual(results.size());
8589
}
8690

8791
@Test
88-
public void testFindParametrized(){
92+
public void testFindWithParametrized() {
93+
final StringBuilder sb = new StringBuilder();
8994
Base.findWith(new RowListenerAdapter() {
9095
@Override public void onNext(Map<String, Object> row) {
91-
System.out.println(row);
96+
sb.append(row.get("last_name"));
97+
}
98+
}, true, "select last_name from people where id > ? order by id", 1);
99+
the(sb.toString()).shouldBeEqual("JonstonAliPesci");
100+
}
101+
102+
@Test
103+
public void testFindParametrized() {
104+
final StringBuilder sb = new StringBuilder();
105+
Base.find("select last_name from people where id > ? order by id", 1).with(new RowListenerAdapter() {
106+
@Override public void onNext(Map<String, Object> row) {
107+
sb.append(row.get("last_name"));
92108
}
93-
}, true, "select * from people where id > ? and dob > ?", 1, getTimestamp(1935, 1, 1));
109+
});
110+
the(sb.toString()).shouldBeEqual("JonstonAliPesci");
94111
}
95112

96113
@Test

0 commit comments

Comments
 (0)