@@ -38,46 +38,48 @@ public void defaults() throws Exception {
3838 Config config = jedisConfig ()
3939 .withValue ("db" , ConfigValueFactory .fromAnyRef ("redis://localhost:6780" ));
4040 new MockUnit (Env .class , Binder .class )
41- .expect (
42- unit -> {
43- GenericObjectPoolConfig poolConfig = unit
44- .mockConstructor (GenericObjectPoolConfig .class );
45- poolConfig .setBlockWhenExhausted (true );
46- poolConfig
47- .setEvictionPolicyClassName ("org.apache.commons.pool2.impl.DefaultEvictionPolicy" );
48- poolConfig .setJmxEnabled (false );
49- poolConfig .setJmxNamePrefix ("redis-pool" );
50- poolConfig .setLifo (true );
51- poolConfig .setMaxIdle (10 );
52- poolConfig .setMaxTotal (128 );
53- poolConfig .setMaxWaitMillis (-1 );
54- poolConfig .setMinEvictableIdleTimeMillis (1800000L );
55- poolConfig .setMinIdle (10 );
56- poolConfig .setNumTestsPerEvictionRun (3 );
57- poolConfig .setSoftMinEvictableIdleTimeMillis (1800000L );
58- poolConfig .setTestOnBorrow (false );
59- poolConfig .setTestOnReturn (false );
60- poolConfig .setTestWhileIdle (false );
61- poolConfig .setTimeBetweenEvictionRunsMillis (-1 );
62-
63- unit .mockConstructor (
64- JedisPool .class ,
65- new Class []{GenericObjectPoolConfig .class , URI .class , int .class },
66- poolConfig , URI .create ("redis://localhost:6780" ), 2000 );
67-
68- ScopedBindingBuilder jpSBB = unit .mock (ScopedBindingBuilder .class );
69- jpSBB .asEagerSingleton ();
70-
71- AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
72- expect (jpABB .toProvider (isA (RedisProvider .class ))).andReturn (jpSBB );
73-
74- AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
75- expect (jABB .toProvider (isA (Provider .class ))).andReturn (null );
76-
77- Binder binder = unit .get (Binder .class );
78- expect (binder .bind (JedisPool .class )).andReturn (jpABB );
79- expect (binder .bind (Jedis .class )).andReturn (jABB );
80- })
41+ .expect (unit -> {
42+ GenericObjectPoolConfig poolConfig = unit
43+ .mockConstructor (GenericObjectPoolConfig .class );
44+ poolConfig .setBlockWhenExhausted (true );
45+ poolConfig
46+ .setEvictionPolicyClassName ("org.apache.commons.pool2.impl.DefaultEvictionPolicy" );
47+ poolConfig .setJmxEnabled (false );
48+ poolConfig .setJmxNamePrefix ("redis-pool" );
49+ poolConfig .setLifo (true );
50+ poolConfig .setMaxIdle (10 );
51+ poolConfig .setMaxTotal (128 );
52+ poolConfig .setMaxWaitMillis (-1 );
53+ poolConfig .setMinEvictableIdleTimeMillis (1800000L );
54+ poolConfig .setMinIdle (10 );
55+ poolConfig .setNumTestsPerEvictionRun (3 );
56+ poolConfig .setSoftMinEvictableIdleTimeMillis (1800000L );
57+ poolConfig .setTestOnBorrow (false );
58+ poolConfig .setTestOnReturn (false );
59+ poolConfig .setTestWhileIdle (false );
60+ poolConfig .setTimeBetweenEvictionRunsMillis (-1 );
61+
62+ unit .mockConstructor (
63+ JedisPool .class ,
64+ new Class []{GenericObjectPoolConfig .class , URI .class , int .class },
65+ poolConfig , URI .create ("redis://localhost:6780" ), 2000 );
66+
67+ ScopedBindingBuilder jpSBB = unit .mock (ScopedBindingBuilder .class );
68+ jpSBB .asEagerSingleton ();
69+
70+ AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
71+ expect (jpABB .toProvider (isA (RedisProvider .class ))).andReturn (jpSBB );
72+
73+ ScopedBindingBuilder sbbJABB = unit .mock (ScopedBindingBuilder .class );
74+ sbbJABB .asEagerSingleton ();
75+
76+ AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
77+ expect (jABB .toProvider (isA (Provider .class ))).andReturn (sbbJABB );
78+
79+ Binder binder = unit .get (Binder .class );
80+ expect (binder .bind (JedisPool .class )).andReturn (jpABB );
81+ expect (binder .bind (Jedis .class )).andReturn (jABB );
82+ })
8183 .run (unit -> {
8284 new Redis ().configure (unit .get (Env .class ), config , unit .get (Binder .class ));
8385 });
@@ -124,18 +126,24 @@ public void shouldGetJedisInstance() throws Exception {
124126 AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
125127 expect (jpABB .toProvider (isA (RedisProvider .class ))).andReturn (jpSBB );
126128
129+ ScopedBindingBuilder sbbJABB = unit .mock (ScopedBindingBuilder .class );
130+ sbbJABB .asEagerSingleton ();
131+
127132 AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
128- expect (jABB .toProvider (unit .capture (Provider .class ))).andReturn (null );
133+ expect (jABB .toProvider (unit .capture (Provider .class ))).andReturn (sbbJABB );
129134
130135 Binder binder = unit .get (Binder .class );
131136 expect (binder .bind (JedisPool .class )).andReturn (jpABB );
132137 expect (binder .bind (Jedis .class )).andReturn (jABB );
133138 })
134- .run (unit -> {
135- new Redis ().configure (unit .get (Env .class ), config , unit .get (Binder .class ));
136- }, unit -> {
137- assertEquals (unit .get (Jedis .class ), unit .captured (Provider .class ).iterator ().next ().get ());
138- });
139+ .run (
140+ unit -> {
141+ new Redis ().configure (unit .get (Env .class ), config , unit .get (Binder .class ));
142+ },
143+ unit -> {
144+ assertEquals (unit .get (Jedis .class ), unit .captured (Provider .class ).iterator ().next ()
145+ .get ());
146+ });
139147 }
140148
141149 @ SuppressWarnings ("unchecked" )
@@ -180,8 +188,11 @@ public void named() throws Exception {
180188 AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
181189 expect (jpABB .annotatedWith (Names .named ("db" ))).andReturn (jpLBB );
182190
191+ ScopedBindingBuilder sbbJABB = unit .mock (ScopedBindingBuilder .class );
192+ sbbJABB .asEagerSingleton ();
193+
183194 LinkedBindingBuilder <Jedis > jLBB = unit .mock (LinkedBindingBuilder .class );
184- expect (jLBB .toProvider (isA (Provider .class ))).andReturn (null );
195+ expect (jLBB .toProvider (isA (Provider .class ))).andReturn (sbbJABB );
185196
186197 AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
187198 expect (jABB .annotatedWith (Names .named ("db" ))).andReturn (jLBB );
@@ -234,16 +245,21 @@ public void unnamed() throws Exception {
234245 AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
235246 expect (jpABB .toProvider (isA (RedisProvider .class ))).andReturn (jpSBB );
236247
248+ ScopedBindingBuilder sbbJABB = unit .mock (ScopedBindingBuilder .class );
249+ sbbJABB .asEagerSingleton ();
250+
237251 AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
238- expect (jABB .toProvider (isA (Provider .class ))).andReturn (null );
252+ expect (jABB .toProvider (isA (Provider .class ))).andReturn (sbbJABB );
239253
240254 Binder binder = unit .get (Binder .class );
241255 expect (binder .bind (JedisPool .class )).andReturn (jpABB );
242256 expect (binder .bind (Jedis .class )).andReturn (jABB );
243257 })
244- .run (unit -> {
245- new Redis ("db1" ).unnamed ().configure (unit .get (Env .class ), config , unit .get (Binder .class ));
246- });
258+ .run (
259+ unit -> {
260+ new Redis ("db1" ).unnamed ().configure (unit .get (Env .class ), config ,
261+ unit .get (Binder .class ));
262+ });
247263 }
248264
249265 @ SuppressWarnings ("unchecked" )
@@ -286,8 +302,11 @@ public void jedisConfigOverride() throws Exception {
286302 AnnotatedBindingBuilder <JedisPool > jpABB = unit .mock (AnnotatedBindingBuilder .class );
287303 expect (jpABB .toProvider (isA (RedisProvider .class ))).andReturn (jpSBB );
288304
305+ ScopedBindingBuilder sbbJABB = unit .mock (ScopedBindingBuilder .class );
306+ sbbJABB .asEagerSingleton ();
307+
289308 AnnotatedBindingBuilder <Jedis > jABB = unit .mock (AnnotatedBindingBuilder .class );
290- expect (jABB .toProvider (isA (Provider .class ))).andReturn (null );
309+ expect (jABB .toProvider (isA (Provider .class ))).andReturn (sbbJABB );
291310
292311 Binder binder = unit .get (Binder .class );
293312 expect (binder .bind (JedisPool .class )).andReturn (jpABB );
@@ -300,7 +319,7 @@ public void jedisConfigOverride() throws Exception {
300319
301320 @ Test
302321 public void defaultConfig () throws Exception {
303- assertEquals (jedisConfig (), new Redis ().config ());
322+ assertEquals (jedisConfig (), new Redis ().config ());
304323 }
305324
306325 private Config jedisConfig () {
0 commit comments