44import static org .easymock .EasyMock .expectLastCall ;
55
66import org .jooby .Env ;
7+ import org .jooby .Env .ServiceKey ;
78import org .jooby .Routes ;
89import org .jooby .test .MockUnit ;
910import org .jooby .test .MockUnit .Block ;
@@ -94,13 +95,13 @@ public class CassandraTest {
9495
9596 @ Test
9697 public void connectViaProperty () throws Exception {
97- Cassandra .COUNTER .set (0 );
9898 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
9999 Configuration .class , Session .class )
100100 .expect (unit -> {
101101 Config conf = unit .get (Config .class );
102102 expect (conf .getString ("db" )).andReturn ("cassandra://localhost/beers" );
103103 })
104+ .expect (serviceKey (new Env .ServiceKey ()))
104105 .expect (clusterBuilder )
105106 .expect (contactPoints ("localhost" ))
106107 .expect (port (9042 ))
@@ -123,12 +124,19 @@ public void connectViaProperty() throws Exception {
123124 });
124125 }
125126
127+ private Block serviceKey (final ServiceKey serviceKey ) {
128+ return unit -> {
129+ Env env = unit .get (Env .class );
130+ expect (env .serviceKey ()).andReturn (serviceKey );
131+ };
132+ }
133+
126134 @ Test
127135 public void connectViaConnectionString () throws Exception {
128- Cassandra .COUNTER .set (0 );
129136 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
130137 Configuration .class , Session .class )
131138 .expect (clusterBuilder )
139+ .expect (serviceKey (new Env .ServiceKey ()))
132140 .expect (contactPoints ("localhost" ))
133141 .expect (port (9042 ))
134142 .expect (codecRegistry )
@@ -152,10 +160,10 @@ public void connectViaConnectionString() throws Exception {
152160
153161 @ Test
154162 public void onStop () throws Exception {
155- Cassandra .COUNTER .set (0 );
156163 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
157164 Configuration .class , Session .class )
158165 .expect (clusterBuilder )
166+ .expect (serviceKey (new Env .ServiceKey ()))
159167 .expect (contactPoints ("localhost" ))
160168 .expect (port (9042 ))
161169 .expect (codecRegistry )
@@ -188,10 +196,10 @@ public void onStop() throws Exception {
188196
189197 @ Test
190198 public void onStopSessionerr () throws Exception {
191- Cassandra .COUNTER .set (0 );
192199 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
193200 Configuration .class , Session .class )
194201 .expect (clusterBuilder )
202+ .expect (serviceKey (new Env .ServiceKey ()))
195203 .expect (contactPoints ("localhost" ))
196204 .expect (port (9042 ))
197205 .expect (codecRegistry )
@@ -226,11 +234,11 @@ public void onStopSessionerr() throws Exception {
226234 @ SuppressWarnings ("unchecked" )
227235 @ Test
228236 public void withAccessor () throws Exception {
229- Cassandra .COUNTER .set (0 );
230237 Object value = new Object ();
231238 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
232239 Configuration .class , Session .class )
233240 .expect (clusterBuilder )
241+ .expect (serviceKey (new Env .ServiceKey ()))
234242 .expect (contactPoints ("localhost" ))
235243 .expect (port (9042 ))
236244 .expect (codecRegistry )
@@ -265,10 +273,10 @@ public void withAccessor() throws Exception {
265273
266274 @ Test
267275 public void doWithCluster () throws Exception {
268- Cassandra .COUNTER .set (0 );
269276 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
270277 Configuration .class , Session .class , StateListener .class )
271278 .expect (clusterBuilder )
279+ .expect (serviceKey (new Env .ServiceKey ()))
272280 .expect (contactPoints ("localhost" ))
273281 .expect (port (9042 ))
274282 .expect (codecRegistry )
@@ -297,10 +305,10 @@ public void doWithCluster() throws Exception {
297305
298306 @ Test
299307 public void doWithClusterBuilder () throws Exception {
300- Cassandra .COUNTER .set (0 );
301308 new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
302309 Configuration .class , Session .class )
303310 .expect (clusterBuilder )
311+ .expect (serviceKey (new Env .ServiceKey ()))
304312 .expect (contactPoints ("localhost" ))
305313 .expect (port (9042 ))
306314 .expect (codecRegistry )
@@ -329,29 +337,6 @@ public void doWithClusterBuilder() throws Exception {
329337 });
330338 }
331339
332- @ Test
333- public void secondInstance () throws Exception {
334- Cassandra .COUNTER .set (1 );
335- new MockUnit (Env .class , Config .class , Binder .class , Cluster .class , Cluster .Builder .class ,
336- Configuration .class , Session .class )
337- .expect (clusterBuilder )
338- .expect (contactPoints ("localhost" ))
339- .expect (port (9042 ))
340- .expect (codecRegistry )
341- .expect (bind ("beers" , Cluster .class ))
342- .expect (bind ("beers" , Session .class ))
343- .expect (connect ("beers" ))
344- .expect (mapper )
345- .expect (bind ("beers" , MappingManager .class ))
346- .expect (datastore )
347- .expect (bind ("beers" , Datastore .class ))
348- .expect (routeMapper ).expect (onStop )
349- .run (unit -> {
350- new Cassandra ("cassandra://localhost/beers" )
351- .configure (unit .get (Env .class ), unit .get (Config .class ), unit .get (Binder .class ));
352- });
353- }
354-
355340 private Block connect (final String keyspace ) {
356341 return unit -> {
357342 Cluster cluster = unit .get (Cluster .class );
0 commit comments