Try with resources

Fixed failing test