/*
 * Copyright 2010 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.ning.http.client.async;

import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.ListenableFuture;
import com.ning.http.client.Response;
import org.testng.annotations.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.testng.Assert.assertEquals;

public abstract class ListenableFutureTest extends AbstractBasicTest {

    @Test(groups = {"standalone", "default_provider"})
    public void testListenableFuture() throws Throwable {
        final AtomicInteger statusCode = new AtomicInteger(500);
        AsyncHttpClient ahc = getAsyncHttpClient(null);
        final CountDownLatch latch = new CountDownLatch(1);
        final Future<Response> future = ahc.prepareGet(getTargetUrl()).execute();
        ((ListenableFuture)future).addListener(new Runnable(){

            public void run() {
                try {
                    statusCode.set(future.get().getStatusCode());
                    latch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
            }
        }, Executors.newFixedThreadPool(1));

        latch.await(10, TimeUnit.SECONDS);
        assertEquals(statusCode.get(), 200);
        ahc.close();
    }
}

@@ -13,53 +13,88 @@
 ght 
-2010 Ning, Inc.%0A *%0A * Ning licenses this file
+(c) 2010-2011 Sonatype, Inc. All rights reserved.%0A *%0A * This program is licensed
  to 
@@ -125,11 +125,10 @@
 ense
-, v
+ V
 ersi
@@ -137,28 +137,16 @@
  2.0
+,
 %0A * 
-(the %22License%22);
+and
  you
@@ -197,27 +197,31 @@
 with the
-%0A *
+ Apache
  License
 .  You m
@@ -212,18 +212,32 @@
  License
-.
  
+Version 2.0.%0A *
  You may
@@ -258,24 +258,31 @@
  of the 
+Apache 
 License 
 at:%0A *%0A 
@@ -277,20 +277,22 @@
 nse 
-at:%0A *%0A *   
+Version 2.0 at
  htt
@@ -330,16 +330,17 @@
 ENSE-2.0
+.
 %0A *%0A * U
@@ -396,16 +396,19 @@
 writing,
+%0A *
  softwar
@@ -408,19 +408,16 @@
 software
-%0A *
  distrib
@@ -431,24 +431,31 @@
 der the 
+Apache 
 License 
 is distr
@@ -446,16 +446,28 @@
 License 
+Version 2.0 
 is distr
@@ -478,16 +478,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -504,19 +504,16 @@
  WITHOUT
-%0A *
  WARRANT
@@ -573,17 +573,19 @@
 ied.
- 
+%0A *
  See the
 %0A * 
@@ -580,19 +580,23 @@
  See the
-%0A *
+ Apache
  License
@@ -596,16 +596,28 @@
 License 
+Version 2.0 
 for the 
@@ -675,29 +675,20 @@
 ions
-%0A * under the License
+ there under
 .%0A *

Fix headers