@Test(expectedExceptions = IllegalArgumentException.class) public void invalidDataElement() { Object data = new Object(); new InvocationTreeElement(data); } }
@Test public void bothTimestampsAreNull() { InvocationTreeElement e1 = new InvocationTreeElement(mock(InvocationSequenceData.class)); InvocationTreeElement e2 = new InvocationTreeElement(mock(InvocationSequenceData.class)); int result = e1.compareTo(e2); assertThat(result, is(0)); }
@Test public void spanIdentDataElement() { Object data = mock(SpanIdent.class); InvocationTreeElement element = new InvocationTreeElement(data); assertThat(element.getDataElement(), is(data)); }
@Test public void secondTimeIsNull() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(mock(InvocationSequenceData.class)); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(1)); }
@Test public void invocationSequenceDataElement() { Object data = mock(InvocationSequenceData.class); InvocationTreeElement element = new InvocationTreeElement(data); assertThat(element.getDataElement(), is(data)); }
@Test public void firstTimeIsNull() { InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(mock(InvocationSequenceData.class)); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(-1)); } }
@Test public void descendingTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(20)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(1)); }
@Test public void equalTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(10)); int result = e1.compareTo(e2); assertThat(result, is(0)); }
@Test public void spanDataElement() { Object data = mock(Span.class); InvocationTreeElement element = new InvocationTreeElement(data); assertThat(element.getDataElement(), is(data)); assertThat(element.getDataElement(), is(instanceOf(Span.class))); }
@Test public void ascendingTime() { InvocationSequenceData sequence1 = mock(InvocationSequenceData.class); InvocationSequenceData sequence2 = mock(InvocationSequenceData.class); InvocationTreeElement e1 = new InvocationTreeElement(sequence1); InvocationTreeElement e2 = new InvocationTreeElement(sequence2); when(sequence1.getTimeStamp()).thenReturn(new Timestamp(10)); when(sequence2.getTimeStamp()).thenReturn(new Timestamp(20)); int result = e1.compareTo(e2); assertThat(result, is(-1)); }
/** * Creates a new {@link InvocationTreeElement} which is related to the given parent and contains * the given data objet. * * @param dataElement * the data element of the created {@link InvocationTreeElement} * @param parent * the parent element * @return the newly created {@link InvocationTreeElement} */ private InvocationTreeElement createTreeElement(Object dataElement, InvocationTreeElement parent) { InvocationTreeElement element = new InvocationTreeElement(dataElement); if (parent != null) { parent.addChild(element); } if (dataElement instanceof Span) { Span span = (Span) dataElement; // put the span into the `spansExistingInTree` map in order to mark that it is existing // in the tree, now spansExistingInTree.put(span.getSpanIdent().getId(), element); } return element; }