/*
 * Copyright (C) 2010 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */
package org.trancecode.parallel;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.trancecode.AbstractTest;
import org.trancecode.math.NumberFunctions;

/**
 * Tests for {@link ParallelIterables}.
 * 
 * @author Herve Quiroz
 */
public final class ParallelIterablesTest extends AbstractTest
{
    private static final int MANY_ELEMENTS = 1000;

    private static void assertEquals(final Iterable<?> actual, final Iterable<?> expected)
    {
        Assert.assertEquals(ImmutableList.copyOf(actual), ImmutableList.copyOf(expected));
    }

    @Test
    public void transform()
    {
        final List<String> strings = ImmutableList.of("1", "2", "3", "4", "5");
        final List<Integer> integers = ImmutableList.of(1, 2, 3, 4, 5);

        final ExecutorService executor = Executors.newFixedThreadPool(3);
        final Iterable<Integer> result = ParallelIterables.transform(strings, NumberFunctions.parseInt(), executor);

        assertEquals(result, integers);
    }

    @Test
    public void transformMany()
    {
        transformMany(Executors.newFixedThreadPool(3));
    }

    @Test
    public void transformManyWithSingleThread()
    {
        transformMany(Executors.newSingleThreadExecutor());
    }

    private void transformMany(final ExecutorService executor)
    {
        final List<String> strings = Lists.newArrayList();
        for (int i = 0; i < MANY_ELEMENTS; i++)
        {
            strings.add(Integer.toString(i));
        }
        final Iterable<Integer> result = ParallelIterables.transform(strings, NumberFunctions.parseInt(), executor);
        Assert.assertEquals(Iterables.size(result), MANY_ELEMENTS);
    }
}

@@ -1671,48 +1671,24 @@
 s = 
-ImmutableList.of(%221%22, %222%22, %223%22, %224%22, %225%22
+buildInputList(5
 );%0A 
@@ -1742,16 +1742,19 @@
 List.of(
+0, 
 1, 2, 3,
@@ -1759,11 +1759,8 @@
 3, 4
-, 5
 );%0A%0A
@@ -2252,16 +2252,23 @@
 private 
+static 
 void tra
@@ -2308,32 +2308,373 @@
 executor)%0A    %7B%0A
+        final List%3CString%3E strings = buildInputList(MANY_ELEMENTS);%0A        final Iterable%3CInteger%3E result = ParallelIterables.transform(strings, NumberFunctions.parseInt(), executor);%0A        Assert.assertEquals(Iterables.size(result), MANY_ELEMENTS);%0A    %7D%0A%0A    private static List%3CString%3E buildInputList(final int numberOfElements)%0A    %7B%0A
         final Li
@@ -2744,29 +2744,32 @@
  0; i %3C 
-MANY_ELEMENTS
+numberOfElements
 ; i++)%0A 
@@ -2845,183 +2845,22 @@
     
-final Iterable%3CInteger%3E result = ParallelIterables.transform(strings, NumberFunctions.parseInt(), executor);%0A        Assert.assertEquals(Iterables.size(result), MANY_ELEMENTS)
+return strings
 ;%0A  

Improve code style