Skip to content
Snippets Groups Projects
Commit 2b51ec2c authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Checkstyle issues; Added various tests

parent bc1d0334
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,6 @@
<module name="IllegalThrows"/>
<module name="PackageDeclaration"/>
<module name="ReturnCount"/>
<module name="IllegalType"/>
<module name="DeclarationOrder"/>
<module name="ParameterAssignment"/>
<module name="ExplicitInitialization"/>
......
......@@ -21,13 +21,13 @@ import java.util.List;
public abstract class AbstractExecution<T extends AbstractExecution<T>> {
protected final String container;
protected final String component;
protected final String operation;
private final String container;
private final String component;
private final String operation;
protected String failedCause;
protected T parent;
protected final List<T> children = new ArrayList<>();
private String failedCause;
private T parent;
private final List<T> children = new ArrayList<>();
public AbstractExecution(final String container, final String component, final String operation) {
this.container = container;
......@@ -98,13 +98,18 @@ public abstract class AbstractExecution<T extends AbstractExecution<T>> {
return this.children;
}
@SuppressWarnings("unchecked")
public final void addExecutionEntry(final T entry) {
this.children.add(entry);
entry.parent = (T) this;
entry.setParent((T) this);
}
public final T getParent() {
return this.parent;
}
public void setParent(final T parent) {
this.parent = parent;
}
}
......@@ -56,12 +56,12 @@ public final class Execution extends AbstractExecution<Execution> {
}
private void updatePercent() {
if (this.parent != null) {
this.percent = (this.duration * 100.0f) / this.parent.duration;
if (this.getParent() != null) {
this.percent = (this.duration * 100.0f) / this.getParent().duration;
} else {
this.percent = 100.0f;
}
for (final Execution executionEntry : this.children) {
for (final Execution executionEntry : this.getChildren()) {
executionEntry.updatePercent();
}
}
......@@ -70,11 +70,11 @@ public final class Execution extends AbstractExecution<Execution> {
public int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((this.children == null) ? 0 : this.children.hashCode());
result = (prime * result) + ((this.component == null) ? 0 : this.component.hashCode());
result = (prime * result) + ((this.container == null) ? 0 : this.container.hashCode());
result = (prime * result) + ((this.failedCause == null) ? 0 : this.failedCause.hashCode());
result = (prime * result) + ((this.operation == null) ? 0 : this.operation.hashCode());
result = (prime * result) + ((this.getChildren() == null) ? 0 : this.getChildren().hashCode());
result = (prime * result) + ((this.getComponent() == null) ? 0 : this.getComponent().hashCode());
result = (prime * result) + ((this.getContainer() == null) ? 0 : this.getContainer().hashCode());
result = (prime * result) + ((this.getFailedCause() == null) ? 0 : this.getFailedCause().hashCode());
result = (prime * result) + ((this.getOperation() == null) ? 0 : this.getOperation().hashCode());
return result;
}
......@@ -87,30 +87,30 @@ public final class Execution extends AbstractExecution<Execution> {
return false;
}
final Execution otherEntry = (Execution) other;
if (!this.container.equals(otherEntry.container)) {
if (!this.getContainer().equals(otherEntry.getContainer())) {
return false;
}
if (!this.component.equals(otherEntry.component)) {
if (!this.getComponent().equals(otherEntry.getComponent())) {
return false;
}
if (!this.operation.equals(otherEntry.operation)) {
if (!this.getOperation().equals(otherEntry.getOperation())) {
return false;
}
if (this.failedCause == null) {
if (otherEntry.failedCause != null) {
if (this.getFailedCause() == null) {
if (otherEntry.getFailedCause() != null) {
return false;
}
} else {
if (!this.failedCause.equals(otherEntry.failedCause)) {
if (!this.getFailedCause().equals(otherEntry.getFailedCause())) {
return false;
}
}
if (this.children.size() != otherEntry.children.size()) {
if (this.getChildren().size() != otherEntry.getChildren().size()) {
return false;
}
final Iterator<Execution> ownChildrenIterator = this.children.iterator();
final Iterator<Execution> otherChildrenIterator = otherEntry.children.iterator();
final Iterator<Execution> ownChildrenIterator = this.getChildren().iterator();
final Iterator<Execution> otherChildrenIterator = otherEntry.getChildren().iterator();
while (ownChildrenIterator.hasNext()) {
final Execution ownChild = ownChildrenIterator.next();
......@@ -123,5 +123,4 @@ public final class Execution extends AbstractExecution<Execution> {
return true;
}
}
......@@ -9,44 +9,54 @@ public abstract class AbstractExecutionTest<T extends AbstractExecution<T>> {
@Test
public void traceDepthCalculationInCommonCaseShouldWork() {
final AbstractExecution<T> execution = this.createEmptyExecution();
final T execution = this.createEmptyExecution();
execution.addExecutionEntry(this.createEmptyExecution());
execution.addExecutionEntry(this.createEmptyExecution());
execution.addExecutionEntry(this.createEmptyExecution());
execution.children.get(0).addExecutionEntry(this.createEmptyExecution());
execution.getChildren().get(0).addExecutionEntry(this.createEmptyExecution());
assertThat(execution.getTraceDepth(), is(2));
}
@Test
public void traceDepthCalculationForNoChildrenShouldWork() {
final AbstractExecution<T> execution = this.createEmptyExecution();
final T execution = this.createEmptyExecution();
assertThat(execution.getTraceDepth(), is(0));
}
@Test
public void traceSizeCalculationInCommonCaseShouldWork() {
final AbstractExecution<T> execution = this.createEmptyExecution();
final T execution = this.createEmptyExecution();
execution.addExecutionEntry(this.createEmptyExecution());
execution.addExecutionEntry(this.createEmptyExecution());
execution.addExecutionEntry(this.createEmptyExecution());
execution.children.get(0).addExecutionEntry(this.createEmptyExecution());
execution.getChildren().get(0).addExecutionEntry(this.createEmptyExecution());
assertThat(execution.getTraceSize(), is(5));
}
@Test
public void traceSizeCalculationForNoChildrenShouldWork() {
final AbstractExecution<T> execution = this.createEmptyExecution();
final T execution = this.createEmptyExecution();
assertThat(execution.getTraceSize(), is(1));
}
@Test
public void addingChildrenShouldUpdateTheParent() {
final T execution = this.createEmptyExecution();
final T child = this.createEmptyExecution();
execution.addExecutionEntry(child);
assertThat(child.getParent(), is(execution));
}
protected abstract T createEmptyExecution();
}
package kieker.gui.common.domain;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public final class ExecutionTest extends AbstractExecutionTest<Execution> {
@Override
......@@ -7,4 +15,89 @@ public final class ExecutionTest extends AbstractExecutionTest<Execution> {
return new Execution(0, "", "", "");
}
@Test
public void equalsWithNullShouldNotLeadToException() {
final Execution fstExecution = new Execution(0, "", "", "");
final Execution sndExecution = null;
assertThat(fstExecution, is(not(equalTo(sndExecution))));
}
@Test
public void equalsForSameInstanceShouldWork() {
final Execution fstExecution = new Execution(0, "", "", "");
final Execution sndExecution = fstExecution;
assertThat(fstExecution, is(equalTo(sndExecution)));
}
@Test
public void equalsForSameValuesShouldWork() {
final Execution fstExecution = new Execution(42, "container", "component", "operation");
final Execution sndExecution = new Execution(42, "container", "component", "operation");
assertThat(fstExecution, is(equalTo(sndExecution)));
}
@Test
public void equalsForDifferentTraceIDsShouldWork() {
final Execution fstExecution = new Execution(42, "container", "component", "operation");
final Execution sndExecution = new Execution(43, "container", "component", "operation");
assertThat(fstExecution, is(equalTo(sndExecution)));
}
@Test
public void equalsForDifferentContainerShouldReturnFalse() {
final Execution fstExecution = new Execution(42, "container1", "component", "operation");
final Execution sndExecution = new Execution(42, "container2", "component", "operation");
assertThat(fstExecution, is(not(equalTo(sndExecution))));
}
@Test
public void equalsForDifferentComponentsShouldReturnFalse() {
final Execution fstExecution = new Execution(42, "container", "component1", "operation");
final Execution sndExecution = new Execution(42, "container", "component2", "operation");
assertThat(fstExecution, is(not(equalTo(sndExecution))));
}
@Test
public void equalsForDifferentOperationsShouldReturnFalse() {
final Execution fstExecution = new Execution(42, "container", "component", "operation1");
final Execution sndExecution = new Execution(42, "container", "component", "operation2");
assertThat(fstExecution, is(not(equalTo(sndExecution))));
}
@Test
public void percentCalculationShouldWork() {
final Execution execution = new Execution(42, "", "", "");
final Execution child1 = new Execution(42, "", "", "");
final Execution child2 = new Execution(42, "", "", "");
final Execution child3 = new Execution(42, "", "", "");
final Execution child4 = new Execution(42, "", "", "");
execution.setDuration(100);
child1.setDuration(70);
child2.setDuration(15);
child3.setDuration(36);
child4.setDuration(18);
execution.addExecutionEntry(child1);
execution.addExecutionEntry(child2);
execution.addExecutionEntry(child3);
child3.addExecutionEntry(child4);
execution.recalculateValues();
assertThat((double) execution.getPercent(), is(closeTo(100.0, 1e-3)));
assertThat((double) child1.getPercent(), is(closeTo(70.0, 1e-3)));
assertThat((double) child2.getPercent(), is(closeTo(15.0, 1e-3)));
assertThat((double) child3.getPercent(), is(closeTo(36.0, 1e-3)));
assertThat((double) child4.getPercent(), is(closeTo(50.0, 1e-3)));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment