2525import static com .jnape .palatable .lambda .adt .Try .failure ;
2626import static com .jnape .palatable .lambda .adt .Try .success ;
2727import static com .jnape .palatable .lambda .adt .Try .trying ;
28+ import static com .jnape .palatable .lambda .adt .Try .withResources ;
2829import static com .jnape .palatable .lambda .functions .builtin .fn1 .Constantly .constantly ;
2930import static com .jnape .palatable .lambda .functions .builtin .fn1 .Id .id ;
3031import static com .jnape .palatable .lambda .functor .builtin .Lazy .lazy ;
@@ -173,38 +174,38 @@ public void tryingCatchesAnyThrowableThrownDuringEvaluation() {
173174 @ Test
174175 public void withResourcesCleansUpAutoCloseableInSuccessCase () {
175176 AtomicBoolean closed = new AtomicBoolean (false );
176- assertEquals (success (1 ), Try . withResources (() -> () -> closed .set (true ), resource -> success (1 )));
177+ assertEquals (success (1 ), withResources (() -> ( AutoCloseable ) () -> closed .set (true ), resource -> success (1 )));
177178 assertTrue (closed .get ());
178179 }
179180
180181 @ Test
181182 public void withResourcesCleansUpAutoCloseableInFailureCase () {
182183 AtomicBoolean closed = new AtomicBoolean (false );
183184 RuntimeException exception = new RuntimeException ();
184- assertEquals (Try .failure (exception ), Try . withResources (() -> () -> closed .set (true ),
185- resource -> { throw exception ; }));
185+ assertEquals (Try .failure (exception ), withResources (() -> ( AutoCloseable ) () -> closed .set (true ),
186+ resource -> { throw exception ; }));
186187 assertTrue (closed .get ());
187188 }
188189
189190 @ Test
190191 public void withResourcesExposesResourceCreationFailure () {
191192 IOException ioException = new IOException ();
192- assertEquals (Try .failure (ioException ), Try . withResources (() -> { throw ioException ; }, resource -> success (1 )));
193+ assertEquals (Try .failure (ioException ), withResources (() -> { throw ioException ; }, resource -> success (1 )));
193194 }
194195
195196 @ Test
196197 public void withResourcesExposesResourceCloseFailure () {
197198 IOException ioException = new IOException ();
198- assertEquals (Try .failure (ioException ), Try . withResources (() -> () -> { throw ioException ; },
199- resource -> success (1 )));
199+ assertEquals (Try .failure (ioException ), withResources (() -> ( AutoCloseable ) () -> { throw ioException ; },
200+ resource -> success (1 )));
200201 }
201202
202203 @ Test
203204 public void withResourcesPreservesSuppressedExceptionThrownDuringClose () {
204205 RuntimeException rootException = new RuntimeException ();
205206 IOException nestedIOException = new IOException ();
206- Try <Throwable > failure = Try . withResources (() -> () -> { throw nestedIOException ; },
207- resource -> { throw rootException ; });
207+ Try <Throwable > failure = withResources (() -> ( AutoCloseable ) () -> { throw nestedIOException ; },
208+ resource -> { throw rootException ; });
208209 Throwable thrown = failure .recover (id ());
209210
210211 assertEquals (thrown , rootException );
@@ -214,10 +215,10 @@ public void withResourcesPreservesSuppressedExceptionThrownDuringClose() {
214215 @ Test
215216 public void cascadingWithResourcesClosesInInverseOrder () {
216217 List <String > closeMessages = new ArrayList <>();
217- assertEquals (success (1 ), Try . withResources (() -> (AutoCloseable ) () -> closeMessages .add ("close a" ),
218- a -> () -> closeMessages .add ("close b" ),
219- b -> () -> closeMessages .add ("close c" ),
220- c -> success (1 )));
218+ assertEquals (success (1 ), withResources (() -> (AutoCloseable ) () -> closeMessages .add ("close a" ),
219+ a -> () -> closeMessages .add ("close b" ),
220+ b -> () -> closeMessages .add ("close c" ),
221+ c -> success (1 )));
221222 assertEquals (asList ("close c" , "close b" , "close a" ), closeMessages );
222223 }
223224
0 commit comments