@Test public void testIsConditionMet1() throws Exception { boolean result; List<ConditionSegment> conditionSegments = new ArrayList<ConditionSegment>(); ConditionSegment conditionSegment = mock(ConditionSegment.class); ConditionSegment conditionSegment1 = mock(ConditionSegment.class); ConditionParameterTargetValue conditionParameterTargetValue = mock(ConditionParameterTargetValue.class); ConditionParameterTargetValue conditionParameterTargetValue1 = mock(ConditionParameterTargetValue.class); ConditionParameterName conditionParameterName = mock(ConditionParameterName.class); ConditionParameterName conditionParameterName1 = mock(ConditionParameterName.class); Assert.assertTrue(conditionSegments.size() == 0); result = ConditionDeterminer.isConditionMet(conditionSegments); Assert.assertEquals(true, result); conditionSegments.add(conditionSegment); conditionSegments.add(conditionSegment1); when(conditionSegment.getPrecursorRelationOperator()).thenReturn(Not); when(conditionSegment1.getPrecursorRelationOperator()).thenReturn(Or); when(conditionSegment.getConditionParameterName()).thenReturn(conditionParameterName); when(conditionSegment1.getConditionParameterName()).thenReturn(conditionParameterName1); when(conditionParameterName.getValue()) .thenReturn(new String("test")) .thenReturn(new String("time")); when(conditionParameterName1.getValue()) .thenReturn(new String("test")) .thenReturn(new String("time")); result = ConditionDeterminer.isConditionMet(conditionSegments); Assert.assertTrue(result == false); Assert.assertTrue(conditionSegments.get(0) == conditionSegment && conditionSegments.get(1) == conditionSegment1); verify(conditionSegment, times(2)).getPrecursorRelationOperator(); verify(conditionSegment1, times(2)).getPrecursorRelationOperator(); when(conditionSegment.getConditionParameterMatchPattern()) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.GreaterThan ) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.NotGreaterThan ) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.LessThan ); when(conditionSegment.getConditionParameterTargetValue()).thenReturn(conditionParameterTargetValue); when(conditionParameterTargetValue.getStringValue()) .thenReturn(new String("")) .thenReturn(new String("")) .thenReturn(new String("")); when(conditionSegment1.getConditionParameterMatchPattern()) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.NotLessThan ) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.Between ) .thenReturn(ConditionSegment.ConditionParameterMatchPattern.GreaterThan ); when(conditionSegment1.getConditionParameterTargetValue()).thenReturn(conditionParameterTargetValue1); when(conditionParameterTargetValue1.getStringValue()) .thenReturn(new String("2011-11-11 11:11:11")) .thenReturn(new String("1991-01-31 11:11:11")) .thenReturn(new String("")); result = ConditionDeterminer.isConditionMet(conditionSegments); Assert.assertTrue(result == true); result = ConditionDeterminer.isConditionMet(conditionSegments); Assert.assertTrue(result == false); result = ConditionDeterminer.isConditionMet(conditionSegments); Assert.assertTrue(result == false); verify(conditionSegment, times(5)).getPrecursorRelationOperator(); verify(conditionSegment1, times(5)).getPrecursorRelationOperator(); }
public static boolean isConditionMet(List<ConditionSegment> conditionSegments) { if (conditionSegments == null || conditionSegments.size() == 0) { log.debug("No condition."); return true; } sortSegments(conditionSegments); ConditionSegment firstSegment = conditionSegments.get(0); if (!None.equals(firstSegment.getPrecursorRelationOperator())) { log.warn("Segment: order:[{}],name:[{}],value[{}] with precursor not \"None\",ignored precursor."); } int index = 0; while (index < conditionSegments.size()) { ArrayList<ConditionSegment> subSegments = new ArrayList<ConditionSegment>(); subSegments.add(conditionSegments.get(index)); index = index + 1; for (; index < conditionSegments.size(); index++) { ConditionSegment nextSegment = conditionSegments.get(index); PrecursorRelationOperator nextOperator = nextSegment.getPrecursorRelationOperator(); if (!Or.equals(nextOperator)) { subSegments.add(nextSegment); } else { break; } } boolean subCondition = isSubConditionMet(subSegments); if (subCondition) { return true; } } return false; }
ConditionDeterminer { public static boolean isConditionMet(List<ConditionSegment> conditionSegments) { if (conditionSegments == null || conditionSegments.size() == 0) { log.debug("No condition."); return true; } sortSegments(conditionSegments); ConditionSegment firstSegment = conditionSegments.get(0); if (!None.equals(firstSegment.getPrecursorRelationOperator())) { log.warn("Segment: order:[{}],name:[{}],value[{}] with precursor not \"None\",ignored precursor."); } int index = 0; while (index < conditionSegments.size()) { ArrayList<ConditionSegment> subSegments = new ArrayList<ConditionSegment>(); subSegments.add(conditionSegments.get(index)); index = index + 1; for (; index < conditionSegments.size(); index++) { ConditionSegment nextSegment = conditionSegments.get(index); PrecursorRelationOperator nextOperator = nextSegment.getPrecursorRelationOperator(); if (!Or.equals(nextOperator)) { subSegments.add(nextSegment); } else { break; } } boolean subCondition = isSubConditionMet(subSegments); if (subCondition) { return true; } } return false; } }
ConditionDeterminer { public static boolean isConditionMet(List<ConditionSegment> conditionSegments) { if (conditionSegments == null || conditionSegments.size() == 0) { log.debug("No condition."); return true; } sortSegments(conditionSegments); ConditionSegment firstSegment = conditionSegments.get(0); if (!None.equals(firstSegment.getPrecursorRelationOperator())) { log.warn("Segment: order:[{}],name:[{}],value[{}] with precursor not \"None\",ignored precursor."); } int index = 0; while (index < conditionSegments.size()) { ArrayList<ConditionSegment> subSegments = new ArrayList<ConditionSegment>(); subSegments.add(conditionSegments.get(index)); index = index + 1; for (; index < conditionSegments.size(); index++) { ConditionSegment nextSegment = conditionSegments.get(index); PrecursorRelationOperator nextOperator = nextSegment.getPrecursorRelationOperator(); if (!Or.equals(nextOperator)) { subSegments.add(nextSegment); } else { break; } } boolean subCondition = isSubConditionMet(subSegments); if (subCondition) { return true; } } return false; }  }
ConditionDeterminer { public static boolean isConditionMet(List<ConditionSegment> conditionSegments) { if (conditionSegments == null || conditionSegments.size() == 0) { log.debug("No condition."); return true; } sortSegments(conditionSegments); ConditionSegment firstSegment = conditionSegments.get(0); if (!None.equals(firstSegment.getPrecursorRelationOperator())) { log.warn("Segment: order:[{}],name:[{}],value[{}] with precursor not \"None\",ignored precursor."); } int index = 0; while (index < conditionSegments.size()) { ArrayList<ConditionSegment> subSegments = new ArrayList<ConditionSegment>(); subSegments.add(conditionSegments.get(index)); index = index + 1; for (; index < conditionSegments.size(); index++) { ConditionSegment nextSegment = conditionSegments.get(index); PrecursorRelationOperator nextOperator = nextSegment.getPrecursorRelationOperator(); if (!Or.equals(nextOperator)) { subSegments.add(nextSegment); } else { break; } } boolean subCondition = isSubConditionMet(subSegments); if (subCondition) { return true; } } return false; }  static boolean isConditionMet(List<ConditionSegment> conditionSegments); static void main(String[] args); }
ConditionDeterminer { public static boolean isConditionMet(List<ConditionSegment> conditionSegments) { if (conditionSegments == null || conditionSegments.size() == 0) { log.debug("No condition."); return true; } sortSegments(conditionSegments); ConditionSegment firstSegment = conditionSegments.get(0); if (!None.equals(firstSegment.getPrecursorRelationOperator())) { log.warn("Segment: order:[{}],name:[{}],value[{}] with precursor not \"None\",ignored precursor."); } int index = 0; while (index < conditionSegments.size()) { ArrayList<ConditionSegment> subSegments = new ArrayList<ConditionSegment>(); subSegments.add(conditionSegments.get(index)); index = index + 1; for (; index < conditionSegments.size(); index++) { ConditionSegment nextSegment = conditionSegments.get(index); PrecursorRelationOperator nextOperator = nextSegment.getPrecursorRelationOperator(); if (!Or.equals(nextOperator)) { subSegments.add(nextSegment); } else { break; } } boolean subCondition = isSubConditionMet(subSegments); if (subCondition) { return true; } } return false; }  static boolean isConditionMet(List<ConditionSegment> conditionSegments); static void main(String[] args);  }