Created
June 12, 2019 19:15
-
-
Save jbleduigou/8dcc7d6451e106aceb9c92670b6fec39 to your computer and use it in GitHub Desktop.
BeerServiceTestV2
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 com.github.jbleduigou.beer.service; | |
import com.github.jbleduigou.beer.model.Beer; | |
import com.github.jbleduigou.beer.repository.BeerRepository; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.InjectMocks; | |
import org.mockito.Mock; | |
import org.mockito.junit.MockitoJUnitRunner; | |
import java.util.Optional; | |
import static com.github.jbleduigou.beer.matchers.BeerMatchers.beerWithAbv; | |
import static com.github.jbleduigou.beer.matchers.BeerMatchers.beerWithName; | |
import static org.hamcrest.Matchers.both; | |
import static org.junit.Assert.assertThat; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.verifyNoMoreInteractions; | |
import static org.mockito.Mockito.when; | |
@RunWith(MockitoJUnitRunner.class) | |
public class BeerServiceTest { | |
@InjectMocks | |
private BeerService service; | |
@Mock | |
private BeerRepository repository; | |
@Before | |
public void setupMocks() { | |
when(repository.findById(9531L)).thenReturn(Optional.of(new Beer(9531L, "Nanny State", 0.5))); | |
} | |
@Test | |
public void getBeerShouldReturnNannyState() { | |
Beer result = service.getBeerById(9531L); | |
assertThat(result, both(beerWithName("Nanny State")).and(beerWithAbv(0.5))); | |
verify(repository).findById(9531L); | |
verifyNoMoreInteractions(repository); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment