aloverso
10/29/2018 - 3:21 PM

Station Repository Test

Station Repository Test


class DefaultStationRepositoryTest {

    lateinit var stationRepository: DefaultStationRepository
    lateinit var spyRestTemplate: SpyRestTemplate

    @Before
    fun setUp() {
        spyRestTemplate = SpyRestTemplate()
        stationRepository = DefaultStationRepository(spyRestTemplate)
    }

    @Test
    fun `getStations() returns a list of fetched stations`() {
        spyRestTemplate.stubbedGet = """
            {
              "result": [
                {
                  "id": "1234",
                  "name": "Grand Central - 42 St"
                }
              ]
            }
        """.trimIndent()
      
        val stations = stationRepository.getStations()

        assertThat(stations).isEqualTo(listOf(
                Station(
                        name = "Grand Central - 42 St",
                        id = "1234"
                )
        ))

        assertThat(spyRestTemplate.get_urlCalledWith).isEqualTo("http://mtaapi.herokuapp.com/stations")
    }