Skip to content

Commit

Permalink
80-HGStorageImplementation-interface-test: progress on refactoring ex…
Browse files Browse the repository at this point in the history
…isting test cases
  • Loading branch information
mellsrc committed May 23, 2016
1 parent 0f6c161 commit 9630f50
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 223 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package hgtest.storage.bje.BJETxLock;

import static org.junit.rules.ExpectedException.none;

import org.easymock.EasyMock;
import org.hypergraphdb.HyperGraph;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

public class BJETxLockTestBasis
{
protected final HyperGraph mockedGraph = EasyMock
.createStrictMock(HyperGraph.class);

@Rule
public final ExpectedException below = none();

@Before
public void resetAndReplayMock() throws Exception
{
EasyMock.reset(mockedGraph);
EasyMock.replay(mockedGraph);
}

@After
public void verifyMock() throws Exception
{
EasyMock.verify(mockedGraph);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hgtest.storage.bje.BJETxLock;

import org.hypergraphdb.storage.bje.BJETxLock;
import org.junit.Test;

public class BJETxLock_constructorWithArrayOfBytesTest extends
BJETxLockTestBasis
{
@Test
public void doesNotFail_whenGraphIsNull() throws Exception
{
final byte[] objectId = new byte[] { 0, 0, 0, 1 };

new BJETxLock(null, objectId);
}

@Test
public void throwsException_whenObjectIdIsNull() throws Exception
{
final byte[] objectId = null;

below.expect(NullPointerException.class);
new BJETxLock(mockedGraph, objectId);
}

@Test
public void happyPath() throws Exception
{
final byte[] objectId = new byte[] { 0, 0, 0, 1 };

new BJETxLock(mockedGraph, objectId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package hgtest.storage.bje.BJETxLock;

import org.hypergraphdb.storage.bje.BJETxLock;
import org.junit.Test;

import com.sleepycat.je.DatabaseEntry;

public class BJETxLock_constructorWithDatabaseEntryTest extends
BJETxLockTestBasis
{
@Test
public void doesNotFail_whenGraphIsNull() throws Exception
{
final DatabaseEntry objectId = new DatabaseEntry(new byte[] { 0, 0, 0,
1 });

new BJETxLock(null, objectId);
}

@Test
public void throwsException_whenObjectIdIsNull() throws Exception
{
final DatabaseEntry objectId = null;

below.expect(NullPointerException.class);
new BJETxLock(mockedGraph, objectId);
}

@Test
public void happyPath() throws Exception
{
final DatabaseEntry objectId = new DatabaseEntry(new byte[] { 0, 0, 0,
1 });

new BJETxLock(mockedGraph, objectId);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package hgtest.storage.bje.BJETxLock;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import org.hypergraphdb.HyperGraph;
import org.hypergraphdb.storage.bje.BJETxLock;
import org.powermock.api.easymock.PowerMock;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author Yuriy Sechko
*/
public class BJETxLock_getGraphTest
public class BJETxLock_getGraphTest extends BJETxLockTestBasis
{
@Test
public void graphIsNull() throws Exception
public void returnsNullInstance_whenGraphIsNull() throws Exception
{
final byte[] objectId = new byte[] { 0, 0, 0, 1 };
final BJETxLock bjeLock = new BJETxLock(null, objectId);
Expand All @@ -25,17 +21,15 @@ public void graphIsNull() throws Exception
}

@Test
public void graphIsNotNull() throws Exception
public void returnsTheSameInstance_whenGraphIsNotNull() throws Exception
{
final HyperGraph expectedGraph = PowerMock
.createStrictMock(HyperGraph.class);
PowerMock.replayAll();
final HyperGraph expectedGraph = mockedGraph;

final byte[] objectId = new byte[] { 0, 0, 0, 1 };
final BJETxLock bjeLock = new BJETxLock(expectedGraph, objectId);

final HyperGraph actualGraph = bjeLock.getGraph();

assertEquals(actualGraph, expectedGraph);
PowerMock.verifyAll();
assertSame(expectedGraph, actualGraph);
}
}
Loading

0 comments on commit 9630f50

Please sign in to comment.