Created
May 31, 2013 10:44
-
-
Save arialdomartini/5684205 to your computer and use it in GitHub Desktop.
Uso di jMock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package UnitTest.JE.AdvertSearchStats.Words.Iterators; | |
import static org.junit.Assert.*; | |
import org.jmock.Expectations; | |
import org.jmock.Mockery; | |
import org.junit.Before; | |
import org.junit.Test; | |
import JE.AdvertSearchStats.Words.Iterators.ByScoreJoinedPhrasesPostgres; | |
import JE.AdvertSearchStats.Words.Iterators.ContainingWordsRepository; | |
public class ByScoreJoinedPhrasesPostgresTest { | |
private Mockery context; | |
private ContainingWordsRepository containingWordsRepository; | |
@Before | |
public void OnBeforeOneTest() { | |
context = new Mockery(); | |
containingWordsRepository = context.mock(ContainingWordsRepository.class); | |
} | |
@Test | |
public void HasNextShouldReturnFalseIfNoMoreRecordsAreAvailable() { | |
context.checking(new Expectations() {{ | |
oneOf(containingWordsRepository).getWordsForPhrase("phrase"); | |
will(returnValue(null)); | |
}}); | |
ByScoreJoinedPhrasesPostgres sut = new ByScoreJoinedPhrasesPostgres(containingWordsRepository, "phrase"); | |
Boolean hasNext = sut.HasNext(); | |
assertFalse(hasNext); | |
} | |
@Test | |
public void HasNextShouldReturnTrueIfThereAreRecordsAvailable() { | |
context.checking(new Expectations() {{ | |
oneOf(containingWordsRepository).getWordsForPhrase("phrase"); | |
will(returnValue("foo|bar")); | |
}}); | |
ByScoreJoinedPhrasesPostgres sut = new ByScoreJoinedPhrasesPostgres(containingWordsRepository, "phrase"); | |
Boolean hasNext = sut.HasNext(); | |
assertTrue(hasNext); | |
} | |
@Test | |
public void NextShouldReturnNullNoMoreRecordsAreAvailable() { | |
context.checking(new Expectations() {{ | |
oneOf(containingWordsRepository).getWordsForPhrase("phrase"); | |
will(returnValue(null)); | |
}}); | |
ByScoreJoinedPhrasesPostgres sut = new ByScoreJoinedPhrasesPostgres(containingWordsRepository, "phrase"); | |
String next = sut.Next(); | |
assertNull(next); | |
} | |
@Test | |
public void NextShouldReturnTheFirstElementRetrievedByTheRepository() { | |
context.checking(new Expectations() {{ | |
oneOf(containingWordsRepository).getWordsForPhrase("phrase"); | |
will(returnValue("foo|bar")); | |
}}); | |
ByScoreJoinedPhrasesPostgres sut = new ByScoreJoinedPhrasesPostgres(containingWordsRepository, "phrase"); | |
String next = sut.Next(); | |
assertEquals("foo", next); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment