Skip to content

Commit bc935b6

Browse files
committed
use onSuccess to avoid boilerplate code
1 parent fb7526e commit bc935b6

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

vertx-web-session-stores/vertx-web-sstore-cookie/src/test/java/io/vertx/ext/web/sstore/cookie/tests/CookieSessionHandlerTest.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,13 @@ public void testGetSession() throws Exception {
4343
Session session = store.createSession(30_000);
4444
String cookieId = session.id();
4545

46-
store.get(session.value()).onComplete(get -> {
47-
if (get.failed()) {
48-
fail(get.cause());
49-
} else {
50-
assertNotNull(get.result());
51-
assertEquals(cookieId, get.result().id());
46+
store
47+
.get(session.value())
48+
.onComplete(onSuccess(c -> {
49+
assertNotNull(c);
50+
assertEquals(cookieId, c.id());
5251
testComplete();
53-
}
54-
});
52+
}));
5553

5654
await();
5755
}
@@ -61,18 +59,16 @@ public void testParse() {
6159
Session session = store.createSession(30_000);
6260
String cookieValue = session.value();
6361

64-
store.get(cookieValue).onComplete(get -> {
65-
if (get.failed()) {
66-
fail(get.cause());
67-
} else {
68-
assertNotNull(get.result());
62+
store
63+
.get(cookieValue)
64+
.onComplete(onSuccess(c -> {
65+
assertNotNull(c);
6966
// the session id must be the same
70-
assertEquals(session.id(), get.result().id());
67+
assertEquals(session.id(), c.id());
7168
// the session value will not be the same as IV is random
72-
assertFalse(cookieValue.equals(get.result().value()));
69+
assertFalse(cookieValue.equals(c.value()));
7370
testComplete();
74-
}
75-
});
71+
}));
7672

7773
await();
7874
}
@@ -124,18 +120,16 @@ public void testInterStoreCommunication() throws Exception {
124120
Session session = store1.createSession(30_000);
125121
String cookieValue = session.value();
126122

127-
store2.get(cookieValue).onComplete(get -> {
128-
if (get.failed()) {
129-
fail(get.cause());
130-
} else {
131-
assertNotNull(get.result());
123+
store2
124+
.get(cookieValue)
125+
.onComplete(onSuccess(c -> {
126+
assertNotNull(c);
132127
// the session id must be the same
133-
assertEquals(session.id(), get.result().id());
128+
assertEquals(session.id(), c.id());
134129
// the session value will not be the same as IV is random
135-
assertFalse(cookieValue.equals(get.result().value()));
130+
assertFalse(cookieValue.equals(c.value()));
136131
testComplete();
137-
}
138-
});
132+
}));
139133
await();
140134
}
141135

@@ -186,15 +180,13 @@ public void testSessionFields() throws Exception {
186180
}, 200, "OK", null);
187181

188182

189-
store.get(rsession.get()).onComplete(get -> {
190-
if (get.failed()) {
191-
fail(get.cause());
192-
} else {
193-
assertNotNull(get.result());
194-
assertEquals(rid.get(), get.result().id());
183+
store
184+
.get(rsession.get())
185+
.onComplete(onSuccess(c -> {
186+
assertNotNull(c);
187+
assertEquals(rid.get(), c.id());
195188
testComplete();
196-
}
197-
});
189+
}));
198190

199191
await();
200192
}

0 commit comments

Comments
 (0)