### Question:
Script { public static Filter parse(String text) { String[] strings = text.split("\\s"); if (strings[0].equals("market_cap")) { String tmp = text.substring(strings[0].length() +1); String expression = tmp.substring(0, tmp.lastIndexOf("\"")); expression = expression.substring(expression.indexOf("\"") +1); return new MarketCap(new YahooMarketCapProvider(), expression); } else if (strings[0].equals("crossing_ma")) { CrossingMA filter = new CrossingMA( new YahooMAProvider(), TimeFrame.valueOf(strings[1]), MAType.valueOf(strings[2]), Integer.parseInt(strings[3]), MAType.valueOf(strings[4]), Integer.parseInt(strings[5]), Integer.parseInt(strings[6]) ); return filter; } throw new IllegalArgumentException("Unable to parse \"" + text + "\" as a filter"); } Script(File filepath); Filter toFilters(); static Filter parse(String text);  }### Answer:
@Test public void parse_return_marketcap() { Filter filter = Script.parse("market_cap \"value > 500000000\""); assertTrue(filter instanceof MarketCap); MarketCap marketcap = (MarketCap) filter; assertEquals("value > 500000000", marketcap.getExpression()); }
@Test public void parse_return_crossing_ma() { Filter filter = Script.parse("crossing_ma week sma 30 sma 10 5"); assertTrue(filter instanceof CrossingMA); CrossingMA crossingma = (CrossingMA) filter; assertEquals(TimeFrame.week, crossingma.getTimeFrame()); assertEquals(MAType.sma, crossingma.getFirstMAType()); assertEquals(30, crossingma.getFirstMAPeriods()); assertEquals(MAType.sma, crossingma.getSecondMAType()); assertEquals(10, crossingma.getSecondMAPeriods()); assertEquals(5, crossingma.getLastPeriods()); }