LimitProcess implements Serializable { public IEvent[] process(IEvent[] theEvents) { if (null == theEvents || theEvents.length == 0 || theEvents.length <= limitNum) { return theEvents; } else { return Arrays.copyOfRange(theEvents, 0, limitNum); } } LimitProcess(int limitNum); IEvent[] process(IEvent[] theEvents);  }
@Test public void testProcess1() { try { LimitProcess limitProcess = new LimitProcess(0); IEvent[] events = new TupleEvent[SupportConst.I_TEN]; IEvent[] actualResult = limitProcess.process(events); IEvent[] expectedResult = null; Assert.assertArrayEquals(expectedResult, actualResult); } catch (IllegalArgumentException e) { Assert.assertEquals("The limitNum is invalid,limitNum=0", e.getMessage()); } }
@Test public void testProcess2() { LimitProcess limitProcess = new LimitProcess(SupportConst.I_FIVE); IEvent[] actualResult = limitProcess.process(null); IEvent[] expectedResult = null; Assert.assertArrayEquals(expectedResult, actualResult); Assert.assertArrayEquals(null, actualResult); }
@Test public void testProcess3() { LimitProcess limitProcess = new LimitProcess(SupportConst.I_FIVE); IEvent[] events = new TupleEvent[0]; IEvent[] actualResult = limitProcess.process(events); IEvent[] expectedResult = events; Assert.assertArrayEquals(expectedResult, actualResult); }
@Test public void testProcess4() { LimitProcess limitProcess = new LimitProcess(SupportConst.I_TEN); IEvent[] events = new TupleEvent[SupportConst.I_TEN]; IEvent[] actualResult = limitProcess.process(events); IEvent[] expectedResult = events; Assert.assertEquals(expectedResult.length, actualResult.length); }
@Test public void testProcess5() { LimitProcess limitProcess = new LimitProcess(SupportConst.I_TWENTY); IEvent[] events = new TupleEvent[SupportConst.I_TEN]; IEvent[] actualResult = limitProcess.process(events); IEvent[] expectedResult = events; Assert.assertEquals(expectedResult.length, actualResult.length); }
@Test public void testProcess6() { LimitProcess limitProcess = new LimitProcess(SupportConst.I_FIVE); IEvent[] events = new TupleEvent[SupportConst.I_TEN]; IEvent[] actualResult = limitProcess.process(events); Assert.assertEquals(SupportConst.I_FIVE, actualResult.length); }