-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
src/test/java/com/infoq/myqapp/service/ConferenceServiceTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.infoq.myqapp.service; | ||
|
||
import com.infoq.myqapp.domain.Conference; | ||
import com.infoq.myqapp.repository.ConferenceRepository; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration("/config/spring/spring-servlet.xml") | ||
public class ConferenceServiceTest { | ||
|
||
@Mock | ||
private ConferenceRepository conferenceRepository; | ||
|
||
@Mock | ||
private MongoTemplate mongoTemplate; | ||
|
||
@Autowired | ||
@InjectMocks | ||
private ConferenceService conferenceService; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void testCreateOrUpdate() { | ||
//Given | ||
Conference conf = new Conference(); | ||
conf.setLocation("Paris"); | ||
conf.setName("Allo Conf"); | ||
conf.setStartDate(new Date()); | ||
conf.setEndDate(new Date()); | ||
conf.setWebsite("http://google.com"); | ||
|
||
//When | ||
conferenceService.createOrUpdate(conf); | ||
|
||
//Then | ||
verify(conferenceRepository).save(conf); | ||
verifyNoMoreInteractions(conferenceRepository); | ||
verifyZeroInteractions(mongoTemplate); | ||
} | ||
|
||
@Test | ||
public void testDelete() { | ||
//When | ||
conferenceService.delete("Test"); | ||
|
||
//Then | ||
verify(conferenceRepository).delete(eq("Test")); | ||
verifyNoMoreInteractions(conferenceRepository); | ||
verifyZeroInteractions(mongoTemplate); | ||
} | ||
|
||
@Test | ||
public void testGetAllFutureConfs() { | ||
//Given | ||
//List<Conference> confs = new ArrayList<>(); | ||
//confs | ||
//when(mongoTemplate.find(any(Query.class), Conference.class)).thenReturn() | ||
|
||
//When | ||
//conferenceService.getAllFutureConfs(); | ||
|
||
//Then | ||
} | ||
} |
25 changes: 16 additions & 9 deletions
25
src/test/java/com/infoq/myqapp/service/FeedServiceTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
package com.infoq.myqapp.service; | ||
|
||
import com.infoq.myqapp.domain.FeedEntry; | ||
import com.infoq.myqapp.repository.FeedRepository; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.List; | ||
|
||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration("/config/spring/spring-servlet.xml") | ||
public class FeedServiceTest { | ||
|
||
@Autowired | ||
@InjectMocks | ||
private FeedService feedService; | ||
|
||
@Mock | ||
private FeedRepository feedRepository; | ||
|
||
@Before | ||
public void setUp(){ | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void testReadFeed() throws Exception { | ||
// List<FeedEntry> feedEntries = feedService.retrieveFeedTask(); | ||
// | ||
// assertThat(feedEntries).isNotEmpty(); | ||
public void testRetrieveFeedTask() throws Exception { | ||
} | ||
} |