Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DummyInternalVersion with mocking object to make test conditi… #95

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,50 @@
*/
package org.apache.jackrabbit.core.version;

import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import junit.framework.TestCase;
import java.util.Arrays;

import org.apache.jackrabbit.core.id.NodeId;
import org.apache.jackrabbit.spi.Name;

public class VersionIteratorImplTest extends TestCase {

private static final int VERSION_COUNT = 10000;

private final class DummyInternalVersion implements InternalVersion {

private final InternalVersion[] successors;
private NodeId id;

public DummyInternalVersion(InternalVersion[] successors, NodeId id) {
this.successors = successors;
this.id = id;
}

public List<InternalVersion> getSuccessors() {
return Arrays.asList(successors);
}

public NodeId getId() {
return id;
}

public Calendar getCreated() {return null;}
public InternalFrozenNode getFrozenNode() {return null;}
public NodeId getFrozenNodeId() {return null;}
public Name[] getLabels() {return null;}
public Name getName() {return null;}
public InternalVersion[] getPredecessors() {return null;}
public InternalVersionHistory getVersionHistory() {return null;}
public boolean hasLabel(Name label) {return false;}
public boolean isMoreRecent(InternalVersion v) {return false;}
public boolean isRootVersion() {return false;}
public InternalVersionItem getParent() {return null;}
public InternalVersion getLinearSuccessor(InternalVersion baseVersion) { return null; }
public InternalVersion getLinearPredecessor() { return null; }
}

public void testVersionIterator() throws Exception {

InternalVersion version = new DummyInternalVersion(new InternalVersion[] {}, NodeId.randomId());
for (int i = 1; i < VERSION_COUNT; i++) {
version = new DummyInternalVersion(new InternalVersion[] {version}, NodeId.randomId());
}
import junit.framework.TestCase;

try {
VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version);
assertEquals(VERSION_COUNT, versionIteratorImpl.getSize());
} catch (StackOverflowError e) {
fail("Should be able to handle " + VERSION_COUNT + " versions.");
}
public class VersionIteratorImplTest extends TestCase {

}
public InternalVersion mockInternalVersion1(InternalVersion[] successors, NodeId id) {
InternalVersion[] mockFieldVariableSuccessors;
NodeId mockFieldVariableId;
InternalVersion mockInstance = mock(InternalVersion.class);
mockFieldVariableSuccessors = successors;
mockFieldVariableId = id;
when(mockInstance.getSuccessors()).thenAnswer((stubInvo) -> {
return Arrays.asList(mockFieldVariableSuccessors);
});
when(mockInstance.getId()).thenAnswer((stubInvo) -> {
return mockFieldVariableId;
});
return mockInstance;
}

private static final int VERSION_COUNT = 10000;

public void testVersionIterator() throws Exception {

// Construct mock object
InternalVersion version = mockInternalVersion1(new InternalVersion[] {}, NodeId.randomId());
for (int i = 1; i < VERSION_COUNT; i++) {
// Construct mock object
version = mockInternalVersion1(new InternalVersion[] { version }, NodeId.randomId());
}

try {
VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version);
assertEquals(VERSION_COUNT, versionIteratorImpl.getSize());
} catch (StackOverflowError e) {
fail("Should be able to handle " + VERSION_COUNT + " versions.");
}

}

}