public void testExecute() { String spriteName = "spriteName"; Sprite sprite = stage.getSpriteManager().getSprite(spriteName, true); String scriptName = "scriptName"; StartScript startScript = new StartScript(sprite, scriptName); ForeverBrick repeatBrick = new ForeverBrick(spriteName); LoopEndBrick loopEndBrick = new LoopEndBrick(spriteName, repeatBrick); repeatBrick.setLoopEndBrick(loopEndBrick); startScript.addBrick(repeatBrick); startScript.addBrick(loopEndBrick); sprite.addScript(startScript); repeatBrick.execute(); assertEquals(LoopEndBrick.FOREVER, loopEndBrick.getTimesToRepeat()); }
public void testForeverNextCostume() { CatScheduler.get().clear(); String spriteName = "spriteName"; Sprite sprite = stage.getSpriteManager().getSprite(spriteName, true); String costumeName1 = "costume1"; String costumeName2 = "costume2"; String costumeName3 = "costume3"; LookData costumeData1 = createCostumeData(costumeName1); LookData costumeData2 = createCostumeData(costumeName2); LookData costumeData3 = createCostumeData(costumeName3); sprite.addLookData(costumeData1); sprite.addLookData(costumeData2); sprite.addLookData(costumeData3); String scriptName = "scriptName"; StartScript startScript = new StartScript(sprite, scriptName); NextLookBrick nextLookBrick = new NextLookBrick(spriteName); ForeverBrick repeatBrick = new ForeverBrick(spriteName); LoopEndBrick loopEndBrick = new LoopEndBrick(spriteName, repeatBrick); repeatBrick.setLoopEndBrick(loopEndBrick); startScript.addBrick(repeatBrick); startScript.addBrick(nextLookBrick); startScript.addBrick(loopEndBrick); sprite.addScript(startScript); // simulate SetLookBrick sprite.getLook().setLookData(costumeData1); sprite.getLook().hide(); CatThread thread = new CatThread("threadName", startScript); CatScheduler.get().schedule(thread); CatScheduler.get().execute(); // repeat CatScheduler.get().execute(); // next CatScheduler.get().execute(); // loop end assertEquals(costumeName2, sprite.getLook().getLookData().getName()); CatScheduler.get().execute(); // next CatScheduler.get().execute(); // loop end assertEquals(costumeName3, sprite.getLook().getLookData().getName()); CatScheduler.get().execute(); // next CatScheduler.get().execute(); // loop end assertEquals(costumeName1, sprite.getLook().getLookData().getName()); CatScheduler.get().execute(); // next CatScheduler.get().execute(); // loop end assertEquals(costumeName2, sprite.getLook().getLookData().getName()); assertEquals(LoopEndBrick.FOREVER, loopEndBrick.getTimesToRepeat()); assertEquals(1, CatScheduler.get().getThreadCount()); CatScheduler.get().clear(); }