Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .idea/modules/flashy_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'com.h2database:h2'
compile 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'

testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.springframework.security:spring-security-test'
testCompile 'com.github.springtestdbunit:spring-test-dbunit:1.3.0'
testCompile 'org.dbunit:dbunit:2.5.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FlashCard {
private String term;
private String definition;

protected FlashCard() {
public FlashCard() {
id = null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.teamtreehouse.flashy.services;

import com.teamtreehouse.flashy.domain.FlashCard;
import com.teamtreehouse.flashy.repositories.FlashCardRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.List;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class FlashCardServiceImplTest {

@Mock
private FlashCardRepository repository;

@InjectMocks
private FlashCardService service = new FlashCardServiceImpl();

@Test
public void getRandomFlashCards_ShouldReturnTwo() throws Exception {
List<FlashCard> flashCards = Arrays.asList(
new FlashCard(),
new FlashCard()
);

when(repository.findAll()).thenReturn(flashCards);

assertEquals("getRandomFlashCards should return two favorites", 2, service.getRandomFlashCards(2).size());
verify(repository).findAll();
}

@Test
public void findById_ShouldReturnOne() throws Exception {
when(repository.findOne(1L)).thenReturn(new FlashCard());
assertThat(service.getFlashCardById(1L), instanceOf(FlashCard.class));
}

}