package com.xebia.fitnesse; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import junit.framework.TestCase; import fitlibrary.runner.MakeParse; public class StackingDoFixtureTest extends TestCase { public void testMovingUpAndDown() throws Exception { StackingDoFixture fixture = new StackingDoFixture(createTestTree()); MakeParse makeParse = new MakeParse("test page"); makeParse.addTable("| ignored!! |"); makeParse.addRow("| child1 |"); makeParse.addRow("| check | number | 12 |"); makeParse.addRow("| pop |"); makeParse.addRow("| check | string | test |"); makeParse.addRow("| child2 |"); makeParse.addRow("| check | value | bla |"); fixture.doTable(makeParse.getTables()); assertEquals(0, fixture.counts.exceptions); assertEquals(0, fixture.counts.wrong); assertEquals(3, fixture.counts.right); } public void testList() throws Exception { Parent parent = new Parent("test", null, null); parent.children.add(new Child1(4)); parent.children.add(new Child1(3)); parent.children.add(new Child1(2)); parent.children.add(new Child1(1)); StackingDoFixture fixture = new StackingDoFixture(parent); MakeParse makeParse = new MakeParse("test page"); makeParse.addTable("| ignored!! |"); makeParse.addRow("| children |"); makeParse.addRow("| get | 0 |"); makeParse.addRow("| check | number | 4 |"); makeParse.addRow("| pop |"); makeParse.addRow("| get | 1 |"); makeParse.addRow("| check | number | 3 |"); makeParse.addRow("| pop |"); makeParse.addRow("| get | 2 |"); makeParse.addRow("| check | number | 2 |"); makeParse.addRow("| pop |"); makeParse.addRow("| get | 3 |"); makeParse.addRow("| check | number | 1 |"); makeParse.addRow("| pop |"); makeParse.addRow("| pop |"); makeParse.addRow("| check | string | test |"); fixture.doTable(makeParse.getTables()); assertEquals(0, fixture.counts.exceptions); assertEquals(0, fixture.counts.wrong); assertEquals(5, fixture.counts.right); } public void testSet() throws Exception { Child2 child2 = new Child2("1"); child2.getNames().add("2"); child2.getNames().add("3"); child2.getNames().add("4"); StackingDoFixture fixture = new StackingDoFixture(child2); MakeParse makeParse = new MakeParse("test page"); makeParse.addTable("| ignored!! |"); makeParse.addRow("| names |"); makeParse.addRow("| check | get | 0 | 2 |"); makeParse.addRow("| check | get | 1 | 3 |"); makeParse.addRow("| check | get | 2 | 4 |"); makeParse.addRow("| check | size | 3 |"); makeParse.addRow("| pop |"); makeParse.addRow("| check | value | 1 |"); fixture.doTable(makeParse.getTables()); assertEquals(0, fixture.counts.exceptions); assertEquals(0, fixture.counts.wrong); assertEquals(5, fixture.counts.right); } private Object createTestTree() { return new Parent("test", new Child1(12), new Child2("bla")); } public static class Parent { public Parent(String string, Child1 child1, Child2 child2) { this.string = string; this.child1 = child1; this.child2 = child2; } private String string; private Child1 child1; private Child2 child2; private List children = new ArrayList(); public String getString() { return string; } public Child1 getChild1() { return child1; } public Child2 getChild2() { return child2; } public List getChildren() { return children; } } public static class Child1 { public Child1(int i) { number = i; } private int number; public int getNumber() { return number; } } public static class Child2 { public Child2(String string) { value = string; } private String value; private SortedSet names = new TreeSet(); public String getValue() { return value; } public Set getNames() { return names; } } }