package de.ugoe.cs.eventbench.data;
import java.util.LinkedList;
import java.util.List;
import junitx.framework.ListAssert;
import de.ugoe.cs.eventbench.IReplayDecorator;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.*;
import static org.junit.Assert.*;
/**
* The class ReplayableEventTest
contains tests for the class
* {@link ReplayableEvent}
.
*
* @generatedBy CodePro at 12/20/11 10:17 AM
* @author Steffen Herbold
* @version 1.0
*/
public class ReplayableEventTest {
private static class MockReplayable implements IReplayable {
private static final long serialVersionUID = 1L;
final String replay;
final String target;
public MockReplayable(String replay, String target) {
this.replay = replay;
this.target = target;
}
@Override
public String getReplay() {
return replay;
}
@Override
public String getTarget() {
return target;
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof MockReplayable) {
if (replay != null && target != null) {
return replay.equals(((MockReplayable) other).replay)
&& target.equals(((MockReplayable) other).target);
} else if (replay != null && target == null) {
return replay.equals(((MockReplayable) other).replay)
&& ((MockReplayable) other).target == null;
} else if (replay == null && target != null) {
return ((MockReplayable) other).replay == null
&& target.equals(((MockReplayable) other).target);
} else {
return ((MockReplayable) other).replay == null
&& ((MockReplayable) other).target == null;
}
}
return false;
}
@Override
public int hashCode() {
int hashCode = 17;
if( replay!=null ) {
hashCode *= replay.hashCode();
}
if( target!=null ) {
hashCode *= target.hashCode();
}
return hashCode;
}
}
private static class StubReplayDecorator implements IReplayDecorator {
private static final long serialVersionUID = 1L;
@Override
public String getHeader() {
return null;
}
@Override
public String getFooter() {
return null;
}
@Override
public String getSessionHeader(int sessionId) {
return null;
}
@Override
public String getSessionFooter(int sessionId) {
return null;
}
}
@Test
public void testReplayableEvent_1() throws Exception {
String type = "typeString";
ReplayableEvent result = new ReplayableEvent(
type);
assertNotNull(result);
assertNotNull(result.replayEvents);
assertTrue(result.replayEvents.isEmpty());
assertEquals(true, result.replayValid);
assertEquals(null, result.decorator);
}
@Test(expected = java.security.InvalidParameterException.class)
public void testReplayableEvent_2() throws Exception {
new ReplayableEvent(null);
}
@Test
public void testAddReplayEvent_1() throws Exception {
String type = "typeString";
String replayableReplay = "replayString";
String replaybleTarget = "replayTargetString";
MockReplayable replayable = new MockReplayable(replayableReplay,
replaybleTarget);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.addReplayEvent(replayable);
assertEquals(1, fixture.replayEvents.size());
assertEquals(replayable, fixture.replayEvents.get(0));
}
@Test
public void testAddReplayEvent_2() throws Exception {
String type = "typeString";
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replaybleTarget1 = "replayTargetString1";
String replaybleTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replaybleTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replaybleTarget2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.addReplayEvent(replayable1);
fixture.addReplayEvent(replayable2);
assertEquals(2, fixture.replayEvents.size());
assertEquals(replayable1, fixture.replayEvents.get(0));
assertEquals(replayable2, fixture.replayEvents.get(1));
}
@Test(expected = java.security.InvalidParameterException.class )
public void testAddReplayEvent_fixture_3() throws Exception {
String type = "typeString";
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.addReplayEvent(null);
}
@Test
public void testAddReplaySequence_1() throws Exception {
String type = "typeString";
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replaybleTarget1 = "replayTargetString1";
String replaybleTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replaybleTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replaybleTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.addReplaySequence(replaySequence);
assertEquals(2, fixture.replayEvents.size());
assertEquals(replayable1, fixture.replayEvents.get(0));
assertEquals(replayable2, fixture.replayEvents.get(1));
}
@Test(expected = java.security.InvalidParameterException.class )
public void testAddReplaySequence_2() throws Exception {
String type = "typeString";
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.addReplaySequence(null);
}
@Test
public void testEquals_1() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
String typeOther = "typeString";
boolean replayValidOther = true;
String replayableReplayOther1 = "replayString1";
String replayableReplayOther2 = "replayString2";
String replaybleTargetOther1 = "replayTargetString1";
String replaybleTargetOther2 = "replayTargetString2";
MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
replaybleTargetOther1);
MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
List replaySequenceOther = new LinkedList();
replaySequenceOther.add(replayableOther1);
replaySequenceOther.add(replayableOther2);
ReplayableEvent other = new ReplayableEvent(
typeOther);
other.replayEvents = replaySequenceOther;
other.replayValid = replayValidOther;
boolean result = fixture.equals(other);
assertEquals(true, result);
}
@Test
public void testEquals_2() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
String typeOther = "typeString2";
boolean replayValidOther = true;
String replayableReplayOther1 = "replayString1";
String replayableReplayOther2 = "replayString2";
String replaybleTargetOther1 = "replayTargetString1";
String replaybleTargetOther2 = "replayTargetString2";
MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
replaybleTargetOther1);
MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
List replaySequenceOther = new LinkedList();
replaySequenceOther.add(replayableOther1);
replaySequenceOther.add(replayableOther2);
ReplayableEvent other = new ReplayableEvent(
typeOther);
other.replayEvents = replaySequenceOther;
other.replayValid = replayValidOther;
boolean result = fixture.equals(other);
assertEquals(false, result);
}
@Test
public void testEquals_3() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
String typeOther = "typeString";
boolean replayValidOther = true;
String replayableReplayOther1 = "replayString3";
String replayableReplayOther2 = "replayString2";
String replaybleTargetOther1 = "replayTargetString1";
String replaybleTargetOther2 = "replayTargetString2";
MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
replaybleTargetOther1);
MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
List replaySequenceOther = new LinkedList();
replaySequenceOther.add(replayableOther1);
replaySequenceOther.add(replayableOther2);
ReplayableEvent other = new ReplayableEvent(
typeOther);
other.replayEvents = replaySequenceOther;
other.replayValid = replayValidOther;
boolean result = fixture.equals(other);
assertEquals(false, result);
}
@Test
public void testEquals_4() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
String typeOther = "typeString";
boolean replayValidOther = true;
String replayableReplayOther1 = "replayString1";
String replayableReplayOther2 = "replayString3";
String replaybleTargetOther1 = "replayTargetString1";
String replaybleTargetOther2 = "replayTargetString2";
MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
replaybleTargetOther1);
MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
List replaySequenceOther = new LinkedList();
replaySequenceOther.add(replayableOther1);
replaySequenceOther.add(replayableOther2);
ReplayableEvent other = new ReplayableEvent(
typeOther);
other.replayEvents = replaySequenceOther;
other.replayValid = replayValidOther;
boolean result = fixture.equals(other);
assertEquals(false, result);
}
@Test
public void testEquals_5() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
String typeOther = "typeString";
boolean replayValidOther = false;
String replayableReplayOther1 = "replayString1";
String replayableReplayOther2 = "replayString2";
String replaybleTargetOther1 = "replayTargetString1";
String replaybleTargetOther2 = "replayTargetString2";
MockReplayable replayableOther1 = new MockReplayable(replayableReplayOther1,
replaybleTargetOther1);
MockReplayable replayableOther2 = new MockReplayable(replayableReplayOther2, replaybleTargetOther2);
List replaySequenceOther = new LinkedList();
replaySequenceOther.add(replayableOther1);
replaySequenceOther.add(replayableOther2);
ReplayableEvent other = new ReplayableEvent(
typeOther);
other.replayEvents = replaySequenceOther;
other.replayValid = replayValidOther;
boolean result = fixture.equals(other);
assertEquals(false, result);
}
@Test
public void testEquals_6() throws Exception {
String type = "typeString";
boolean replayValid = true;
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
fixture.replayValid = replayValid;
boolean result = fixture.equals(fixture);
assertEquals(true, result);
}
@Test
public void testEqualsContract() throws Exception {
EqualsVerifier.forClass(ReplayableEvent.class)
.suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).withRedefinedSuperclass()
.verify();
}
@Test
public void testGetReplayDecorator_1() throws Exception {
String type = "typeString";
StubReplayDecorator decorator = new StubReplayDecorator();
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.decorator = decorator;
IReplayDecorator result = fixture.getReplayDecorator();
assertEquals(decorator, result);
}
@Test
public void testGetReplayMessages_1() throws Exception {
String type = "typeString";
String replayableReplay1 = "replayString1";
String replayableReplay2 = "replayString2";
String replayableTarget1 = "replayTargetString1";
String replayableTarget2 = "replayTargetString2";
MockReplayable replayable1 = new MockReplayable(replayableReplay1,
replayableTarget1);
MockReplayable replayable2 = new MockReplayable(replayableReplay2, replayableTarget2);
List replaySequence = new LinkedList();
replaySequence.add(replayable1);
replaySequence.add(replayable2);
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayEvents = replaySequence;
List result = fixture.getReplayMessages();
ListAssert.assertEquals(replaySequence, result);
}
@Test
public void testHasValidReplay_1() throws Exception {
String type = "typeString";
boolean replayValid = true;
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayValid = replayValid;
boolean result = fixture.hasValidReplay();
assertEquals(replayValid, result);
}
@Test
public void testHasValidReplay_2() throws Exception {
String type = "typeString";
boolean replayValid = false;
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.replayValid = replayValid;
boolean result = fixture.hasValidReplay();
assertEquals(replayValid, result);
}
@Test
public void testInvalidateReplay_1() throws Exception {
String type = "typeString";
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.invalidateReplay();
assertFalse(fixture.replayValid);
}
@Test
public void testInvalidateReplay_2() throws Exception {
String type = "typeString";
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.invalidateReplay();
fixture.invalidateReplay();
assertFalse(fixture.replayValid);
}
@Test
public void testSetDecorator_fixture_1() throws Exception {
String type = "typeString";
StubReplayDecorator decorator = new StubReplayDecorator();
ReplayableEvent fixture = new ReplayableEvent(
type);
fixture.setDecorator(decorator);
assertEquals(decorator, fixture.decorator);
}
public static void main(String[] args) {
new org.junit.runner.JUnitCore().run(ReplayableEventTest.class);
}
}