Added tests for null-object pattern

This commit is contained in:
Jeroen Meulemeester
2015-12-26 23:53:07 +01:00
parent b4dcec45ef
commit 8f6f171a3f
4 changed files with 203 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package com.iluwatar.nullobject;
import org.junit.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
/**
* Date: 12/26/15 - 11:47 PM
*
* @author Jeroen Meulemeester
*/
public class NullNodeTest extends StdOutTest {
/**
* Verify if {@link NullNode#getInstance()} actually returns the same object instance
*/
@Test
public void testGetInstance() {
final NullNode instance = NullNode.getInstance();
assertNotNull(instance);
assertSame(instance, NullNode.getInstance());
}
@Test
public void testFields() {
final NullNode node = NullNode.getInstance();
assertEquals(0, node.getTreeSize());
assertNull(node.getName());
assertNull(node.getLeft());
assertNull(node.getRight());
}
@Test
public void testWalk() throws Exception {
NullNode.getInstance().walk();
Mockito.verifyZeroInteractions(getStdOutMock());
}
}