mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 18:59:10 +00:00
Added tests for lazy-loading pattern
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.iluwatar.lazy.loading;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertSame;
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
|
||||
/**
|
||||
* Date: 12/19/15 - 11:58 AM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
*/
|
||||
public abstract class AbstractHolderTest {
|
||||
|
||||
/**
|
||||
* Get the internal state of the holder value
|
||||
*
|
||||
* @return The internal value
|
||||
*/
|
||||
abstract Heavy getInternalHeavyValue() throws Exception;
|
||||
|
||||
/**
|
||||
* Request a lazy loaded {@link Heavy} object from the holder.
|
||||
*
|
||||
* @return The lazy loaded {@link Heavy} object
|
||||
*/
|
||||
abstract Heavy getHeavy() throws Exception;
|
||||
|
||||
/**
|
||||
* This test shows that the heavy field is not instantiated until the method getHeavy is called
|
||||
*/
|
||||
@Test(timeout = 3000)
|
||||
public void testGetHeavy() throws Exception {
|
||||
assertNull(getInternalHeavyValue());
|
||||
assertNotNull(getHeavy());
|
||||
assertNotNull(getInternalHeavyValue());
|
||||
assertSame(getHeavy(), getInternalHeavyValue());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user