Skip to content

Commit df42628

Browse files
authored
No productive code change: cleanup basic test data (#114)
* Erste Tests bereinigt * fix * noch mehr Tests bereinigt * modify output * reformat
1 parent ba300e3 commit df42628

5 files changed

Lines changed: 43 additions & 23 deletions

File tree

ebean-test/src/test/java/org/tests/batchinsert/TestBatchInsertFlush.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public void batchFlush() {
5555
DB.saveAll(customers);
5656

5757
txn.commit();
58+
} finally {
59+
DB.find(Customer.class).where().startsWith("name", "BatchFlush").delete();
60+
DB.find(Contact.class).where().startsWith("firstName", "Fred").startsWith("lastName", "Blue").delete();
5861
}
5962
}
6063

ebean-test/src/test/java/org/tests/batchload/TestLazyAddBeanList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public class TestLazyAddBeanList extends BaseTestCase {
2222

2323
private Customer cust;
24+
private List<Customer> custs;
2425
private OrderMaster orderMaster;
2526

2627
@BeforeEach
@@ -39,6 +40,7 @@ void init() {
3940
void tearDown() {
4041
DB.delete(cust);
4142
DB.delete(orderMaster);
43+
DB.deleteAll(custs);
4244
}
4345

4446
@Test
@@ -147,7 +149,7 @@ public void testBatch() {
147149
}
148150

149151
LoggedSql.start();
150-
List<Customer> custs = DB.find(Customer.class).where().startsWith("name", "batch").findList();
152+
custs = DB.find(Customer.class).where().startsWith("name", "batch").findList();
151153
assertThat(custs).hasSize(10);
152154
assertThat(LoggedSql.stop()).hasSize(1);
153155

ebean-test/src/test/java/org/tests/cache/TestBeanCacheContactLazyLoad.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,30 @@ public void testBeanCacheWithLazyLoading() {
5252

5353
DB.save(contact);
5454

55-
// Only get two properties, so we have to lazy-load later
56-
final Contact contactDb = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne();
57-
assertThat(contactDb).isNotNull();
58-
LoggedSql.start();
59-
contactDb.setLastName("Buttonnnn");
60-
List<String> sql = LoggedSql.collect();
61-
assertThat(sql).isEmpty(); // setter did not trigger lazy load
55+
try {
6256

63-
// trigger lazy load
64-
assertThat(contactDb.getPhone()).isEqualTo("1234567890");
65-
sql = LoggedSql.collect();
66-
assertThat(sql).isNotEmpty(); // Lazy-load took place
57+
// Only get two properties, so we have to lazy-load later
58+
final Contact contactDb = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne();
59+
assertThat(contactDb).isNotNull();
60+
LoggedSql.start();
61+
contactDb.setLastName("Buttonnnn");
62+
List<String> sql = LoggedSql.collect();
63+
assertThat(sql).isEmpty(); // setter did not trigger lazy load
6764

68-
final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne();
69-
sql = LoggedSql.stop();
70-
assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache
71-
assertThat(contactDb2).isNotNull();
72-
assertThat(contactDb2.getLastName()).isEqualTo("Button");
65+
// trigger lazy load
66+
assertThat(contactDb.getPhone()).isEqualTo("1234567890");
67+
sql = LoggedSql.collect();
68+
assertThat(sql).isNotEmpty(); // Lazy-load took place
69+
70+
final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne();
71+
sql = LoggedSql.stop();
72+
assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache
73+
assertThat(contactDb2).isNotNull();
74+
assertThat(contactDb2.getLastName()).isEqualTo("Button");
75+
} finally {
76+
DB.delete(customer);
77+
DB.find(Contact.class).where().eq("email", "tim@button.com").delete();
78+
}
7379
}
7480

7581
}

ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static synchronized void reset() {
2626
// OK, test data not modified
2727
outputCustomerIds();
2828
} else {
29-
outputState();
29+
outputState(true);
3030
}
3131
return;
3232
}
@@ -45,11 +45,11 @@ public static synchronized void reset() {
4545
me.insertProducts();
4646
me.insertTestCustAndOrders();
4747
});
48-
outputState();
48+
outputState(false);
4949
runOnce = true;
5050
}
5151

52-
private static void outputState() {
52+
private static void outputState(boolean warning) {
5353
StringBuilder sb = new StringBuilder();
5454
sb.append("CustomerIds:");
5555
server.find(Customer.class).findEach(c -> sb.append(' ').append(c.getId()));
@@ -59,8 +59,13 @@ private static void outputState() {
5959
server.find(Country.class).findEach(c -> sb.append(' ').append(c.getCode()));
6060
sb.append(", Products:");
6161
server.find(Product.class).findEach(c -> sb.append(' ').append(c.getId()));
62-
System.err.println("WARNING: basic test data was modified. Current content:");
63-
System.err.println(sb);
62+
if (warning) {
63+
System.err.println("WARNING: basic test data was modified. Current content:");
64+
System.err.println(sb);
65+
} else {
66+
System.out.println("ResetBasicData. basic test data was initialized Current content:");
67+
System.out.println(sb);
68+
}
6469
}
6570

6671
private static void outputCustomerIds() {

ebean-test/src/test/java/org/tests/transaction/TestExecuteComplete.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ public void implicit_save_expect_threadScopeCleanup() {
141141
cust.setName("Roland");
142142
DB.save(cust);
143143

144-
assertThat(getInScopeTransaction()).isNull();
144+
try {
145+
assertThat(getInScopeTransaction()).isNull();
146+
} finally {
147+
DB.delete(cust);
148+
}
145149
}
146150

147151
@ForPlatform(Platform.H2)

0 commit comments

Comments
 (0)