Skip to content

Commit

Permalink
minor improvements in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Aug 1, 2013
1 parent b0d91f9 commit 61a8063
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;

public class ChannelTest {

Expand All @@ -31,7 +30,7 @@ public class ChannelTest {

@Before
public void setup() {
Node node = spy(new Node(mock(AbstractAntTransceiver.class)));
Node node = new Node(mock(AbstractAntTransceiver.class));
channel = new Channel(node, 0);
}

Expand Down Expand Up @@ -157,8 +156,8 @@ public void receiveMessage(CombinedBurst message) {
count++;
}

boolean recievedAtLeastAsLongSent = (bursts.get(1).getData().length >= data2.length);
assertTrue(recievedAtLeastAsLongSent);
boolean receivedAtLeastAsLongSent = (bursts.get(1).getData().length >= data2.length);
assertTrue(receivedAtLeastAsLongSent);
}


Expand Down
27 changes: 19 additions & 8 deletions jformica_core/src/test/java/org/cowboycoders/ant/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,42 @@
import org.junit.Test;

import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.*;

public class NodeTest {

Node node;
Channel channel1;

@Before
public void setup() {
node = spy(new Node(mock(AbstractAntTransceiver.class)));
Channel channel1 = new Channel(node, 0);
node = new Node(mock(AbstractAntTransceiver.class));
channel1 = mock(Channel.class);

new Mirror().on(node).set().field("channels").withValue(new Channel[]{channel1});
}

@Test
public void shouldSetChannelFreeFlagToFalse() {
assertFalse(node.getFreeChannel().isFree());
when(channel1.isFree()).thenReturn(true);
Channel channel = node.getFreeChannel();

assertSame(channel1, channel);
verify(channel1).setFree(false);
}

@Test
public void shouldNotReturnNonFreeChannels() {
node.getFreeChannel();
public void shouldNotGetNonFreeChannels() {
when(channel1.isFree()).thenReturn(false);

assertNull(node.getFreeChannel());
}

@Test
public void shouldReturnFreeChannelToPool() {
node.freeChannel(channel1);

verify(channel1).setFree(true);
}
}

0 comments on commit 61a8063

Please sign in to comment.