Example usage for java.lang Iterable toString

List of usage examples for java.lang Iterable toString

Introduction

In this page you can find the example usage for java.lang Iterable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.trenako.services.FormValuesServiceTests.java

@Test
public void shouldReturnTheErasList() {
    Iterable<LocalizedEnum<Era>> eras = service.eras();

    String expected = "[(i), (ii), (iii), (iv), (v), (vi)]";
    assertEquals(expected, eras.toString());
}

From source file:com.trenako.services.FormValuesServiceTests.java

@Test
public void shouldReturnThePowerMethodsList() {
    Iterable<LocalizedEnum<PowerMethod>> powerMethods = service.powerMethods();

    String expected = "[(dc), (ac)]";
    assertEquals(expected, powerMethods.toString());
}

From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java

@Test
public void shouldReturnTheOptionFamiliesList() {
    Iterable<LocalizedEnum<OptionFamily>> families = controller.families();
    assertEquals("[(dcc-interface), (headlights), (transmission), (coupler)]", families.toString());
}

From source file:com.trenako.values.LocalizedEnumTests.java

@Test
public void shouldCreateErasList() {
    Iterable<LocalizedEnum<Era>> eras = LocalizedEnum.list(Era.class);
    assertNotNull(eras);//from w  w  w  .ja  v  a  2  s . c o m
    assertEquals("[(i), (ii), (iii), (iv), (v), (vi)]", eras.toString());
}

From source file:com.trenako.services.FormValuesServiceTests.java

@Test
public void shouldReturnTheCategoriesList() {
    Iterable<LocalizedEnum<Category>> categories = service.categories();

    String expected = "[(steam-locomotives), (diesel-locomotives), (electric-locomotives), "
            + "(railcars), (electric-multiple-unit), (freight-cars), "
            + "(passenger-cars), (train-sets), (starter-sets)]";
    assertEquals(expected, categories.toString());
}

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * Join string.//from  ww w. j  ava 2s .c om
 *
 * @param items     the items
 * @param separator the separator
 * @return the string
 */
public static String join(final Iterable<?> items, final String separator) {
    if (items == null)
        return "";

    try {
        List<Object> strings = Lists.transform(Lists.newArrayList(items), new Function<Object, Object>() {
            @Nullable
            @Override
            public Object apply(@Nullable Object input) {
                return (input != null) ? input : NULL_STR;
            }
        });
        return Joiner.on(separator).join(strings);
    } catch (Throwable t) {
        return items.toString();
    }
}

From source file:airbrake.BacktraceTest.java

@Test
public void testIgnoreIgnomreCommonsBacktrace() {
    final Iterable<String> backtrace = new QuietRubyBacktrace(backtrace());
    final Iterable<String> filteredBacktrace = new QuietRubyBacktrace(filteredBacktrace());

    assertEquals(filteredBacktrace.toString(), backtrace.toString());
}

From source file:org.trancecode.xproc.AbstractXProcTest.java

private void test(final XProcTestCase test, final PipelineProcessor pipelineProcessor) {
    log.info(">>>> parse pipeline: {}", test.url());
    final Pipeline pipeline = pipelineProcessor.buildPipeline(test.getPipeline().asSource());
    log.info("<<<< parse pipeline");
    final RunnablePipeline runnablePipeline = pipeline.load();

    // Set inputs
    for (final String port : test.getInputs().keySet()) {
        final List<Source> sources = Lists.newArrayList();
        for (final Collection<XdmNode> inputDocCollection : test.getInputs().get(port)) {
            for (final XdmNode inputDoc : inputDocCollection) {
                sources.add(inputDoc.asSource());
            }/*from w  w w .ja  v  a  2 s  .  c  o  m*/
        }
        runnablePipeline.bindSourcePort(port, sources);
    }

    // Set options
    for (final QName name : test.getOptions().keySet()) {
        final String value = test.getOptions().get(name);
        LOG.trace("  option {} = {}", name, value);
        runnablePipeline.withOption(name, value);
    }

    // Set parameters
    // TODO how to deal with multiple parameter ports ?
    for (final String port : test.getParameters().keySet()) {
        for (final QName name : test.getParameters().get(port).keySet()) {
            final String value = test.getParameters().get(port).get(name);
            LOG.trace("  parameter {} = {}", name, value);
            runnablePipeline.withParam(name, value);
        }
    }

    log.info(">>>> run pipeline");
    final PipelineResult result = runnablePipeline.run();
    log.info("<<<< run pipeline");

    PipelineResult compareResult = null;
    if (test.getComparePipeline() != null) {
        log.info(">>>> parse compare pipeline");
        final Pipeline comparePipeline = pipelineProcessor.buildPipeline(test.getComparePipeline().asSource());
        log.info("<<<< parse compare pipeline");
        final RunnablePipeline compareRunnablePipeline = comparePipeline.load();
        for (final String port : test.getOutputs().keySet()) {
            final List<Source> sources = Lists.newArrayList();
            for (final XdmNode inputDoc : test.getOutputs().get(port)) {
                sources.add(inputDoc.asSource());
            }
            compareRunnablePipeline.bindSourcePort(port, sources);
        }
        for (final QName name : test.getOptions().keySet()) {
            compareRunnablePipeline.withOption(name, test.getOptions().get(name));
        }
        for (final String port : test.getParameters().keySet()) {
            for (final QName name : test.getParameters().get(port).keySet()) {
                compareRunnablePipeline.withParam(name, test.getParameters().get(port).get(name));
            }
        }
        compareResult = compareRunnablePipeline.run();
    }
    final PipelineResult resultPipeline = (test.getComparePipeline() != null) ? compareResult : result;
    assert resultPipeline != null;

    for (final String port : test.getOutputs().keySet()) {
        final Iterable<XdmNode> actualNodes = resultPipeline.readNodes(port);
        final Iterable<XdmNode> expectedNodes = test.getOutputs().get(port);
        AssertJUnit.assertEquals(port + " = " + actualNodes.toString(), Iterables.size(expectedNodes),
                Iterables.size(actualNodes));

        final Iterator<XdmNode> expectedNodesIterator = expectedNodes.iterator();
        final Iterator<XdmNode> actualNodesIterator = actualNodes.iterator();
        while (expectedNodesIterator.hasNext()) {
            assert actualNodesIterator.hasNext();
            final XdmNode expectedNode = expectedNodesIterator.next();
            final XdmNode actualNode = actualNodesIterator.next();
            TcAssert.compare(expectedNode, actualNode);
        }
        assert !actualNodesIterator.hasNext();
    }
}

From source file:com.trenako.values.LocalizedEnumTests.java

@Test
public void shouldCreateCategoriesList() {
    Iterable<LocalizedEnum<Category>> categories = LocalizedEnum.list(Category.class);

    assertNotNull(categories);//from  w  ww .  j a v a  2  s.  c o  m
    String expected = "[(steam-locomotives), (diesel-locomotives), " + "(electric-locomotives), (railcars), "
            + "(electric-multiple-unit), (freight-cars), " + "(passenger-cars), (train-sets), (starter-sets)]";

    assertEquals(expected, categories.toString());
}

From source file:uk.ac.imperial.presage2.web.export.TestDataExport.java

@Test
public void testIndependentVariables() throws JSONException {
    Random rand = new Random();

    // prepare test data
    logger.info("Creating testIndependentVariables data set");
    int simCount = 10;
    long[] simIds = new long[simCount];
    Map<String, Map<String, Integer>> expected = new HashMap<String, Map<String, Integer>>();

    for (int s = 0; s < simCount; s++) {
        int finishAt = 100;
        PersistentSimulation sim = sto.createSimulation("Test", "test", "TEST", finishAt);
        sim.setCurrentTime(finishAt);/*  ww  w.  j a  v  a  2  s  .  c  om*/
        String x = Integer.toString(s % 4);
        String y = (s < 5) ? "a" : "b";
        sim.addParameter("x", x);
        sim.addParameter("y", y);
        PersistentEnvironment env = sim.getEnvironment();
        int datapoint = rand.nextInt(100);
        env.setProperty("test", Integer.toString(datapoint));
        if (!expected.containsKey(x)) {
            expected.put(x, new HashMap<String, Integer>());
        }
        if (!expected.get(x).containsKey(y)) {
            expected.get(x).put(y, datapoint);
        } else {
            expected.get(x).put(y, expected.get(x).get(y) + datapoint);
        }
        simIds[s] = sim.getID();
        logger.info("Sim " + sim.getID() + ", " + finishAt + " steps.");
    }

    JSONObject inputJson = new JSONObject();
    inputJson.put("sources", new JSONArray(simIds));
    inputJson.put("parameters", new JSONArray(new String[] { "x", "y" }));

    JSONObject test1 = new JSONObject();
    test1.put("type", "ENV");
    test1.put("property", "test");
    test1.put("function", "SUM");

    inputJson.put("columns", new JSONArray(new JSONObject[] { test1 }));

    logger.info("Test json input: " + inputJson.toString());

    // test servlet
    Iterable<Iterable<String>> actual = servletUnderTest.processRequest(inputJson);

    int row = -1;
    int col = 0;
    for (Iterable<String> iterable : actual) {
        logger.info("Test results row: " + row);
        logger.info(iterable.toString());
        String x = null;
        String y = null;
        for (String string : iterable) {
            if (row > -1) {
                switch (col) {
                // x col
                case 0:
                    x = string;
                    break;
                // y col
                case 1:
                    y = string;
                    break;
                // sum col
                case 2:
                    assertEquals(expected.get(x).get(y).intValue(), Integer.parseInt(string));
                    break;
                }
                col++;
            }
            col = 0;
            row++;
        }
    }
}