11package domain.use_cases
22
3- import com.google.common.truth.Truth
43import com.google.common.truth.Truth.assertThat
54import domain.models.CurrentWeather
65import domain.repository.WeatherRepository
@@ -37,34 +36,31 @@ class GetCurrentWeatherUseCaseTest {
3736 }
3837
3938 @Test
40- fun `should get the current weather from the WeatherRepository when getting the current weather` () =
41- runTest {
42- // Given
43- coEvery { weatherRepository.getCurrentWeather(latitude, longitude) } returns expectedWeather
39+ fun `getCurrentWeather() should call repository with given coordinates` () = runTest {
40+ // Given
41+ coEvery { weatherRepository.getCurrentWeather(latitude, longitude) } returns expectedWeather
4442
45- // When
46- getCurrentWeatherUseCase.getCurrentWeather(latitude, longitude)
43+ // When
44+ getCurrentWeatherUseCase.getCurrentWeather(latitude, longitude)
4745
48- // Then
49- coVerify(exactly = 1 ) { weatherRepository.getCurrentWeather(latitude, longitude) }
50- }
46+ // Then
47+ coVerify(exactly = 1 ) { weatherRepository.getCurrentWeather(latitude, longitude) }
48+ }
5149
5250 @Test
53- fun `should return current weather for given coordinates when getting the current weather ` () = runTest {
51+ fun `getCurrentWeather() should return expected weather for given coordinates` () = runTest {
5452 // Given
5553 coEvery { weatherRepository.getCurrentWeather(latitude, longitude) } returns expectedWeather
5654
5755 // When
5856 val result = getCurrentWeatherUseCase.getCurrentWeather(latitude, longitude)
5957
6058 // Then
61- Truth . assertThat(expectedWeather ).isEqualTo(result )
59+ assertThat(result ).isEqualTo(expectedWeather )
6260 }
6361
6462 @Test
65-
66- fun `fun getCurrentWeather() should throw exception when repository fails` () = runTest {
67-
63+ fun `getCurrentWeather() should throw exception when repository fails` () = runTest {
6864 // Given
6965 val exceptionMessage = " API error"
7066 coEvery { weatherRepository.getCurrentWeather(latitude, longitude) } throws RuntimeException (exceptionMessage)
@@ -74,39 +70,37 @@ class GetCurrentWeatherUseCaseTest {
7470 getCurrentWeatherUseCase.getCurrentWeather(latitude, longitude)
7571 }
7672
77- // Assert
7873 assertThat(exception.message).isEqualTo(exceptionMessage)
7974 }
8075
8176 @Test
82- fun `getCurrentWeather() should return expected weather data when valid latitude and longitude are provided()` () =
83- runTest {
84- // Given
85- val testLat = 33.3
86- val testLon = 44.4
87- val expected = expectedWeather.copy(temperature2m = 25.0 )
88- coEvery { weatherRepository.getCurrentWeather(testLat, testLon) } returns expected
89-
90- // When
91- val result = getCurrentWeatherUseCase.getCurrentWeather(testLat, testLon)
92-
93- // Then
94- coVerify { weatherRepository.getCurrentWeather(testLat, testLon) }
95- assertThat(result).isEqualTo(expected)
96- }
77+ fun `getCurrentWeather() should return weather for different coordinates` () = runTest {
78+ // Given
79+ val testLat = 33.3
80+ val testLon = 44.4
81+ val expected = expectedWeather.copy(temperature2m = 25.0 )
82+ coEvery { weatherRepository.getCurrentWeather(testLat, testLon) } returns expected
83+
84+ // When
85+ val result = getCurrentWeatherUseCase.getCurrentWeather(testLat, testLon)
9786
87+ // Then
88+ coVerify { weatherRepository.getCurrentWeather(testLat, testLon) }
89+ assertThat(result).isEqualTo(expected)
90+ }
9891
9992 @Test
100- fun `getCurrentWeather() should call repository with zero coordinates when latitude and longitude are both zeros ` () =
101- runTest {
102- val zeroLat = 0.0
103- val zeroLon = 0.0
104- coEvery { weatherRepository.getCurrentWeather(zeroLat, zeroLon) } returns expectedWeather
93+ fun `getCurrentWeather() should work with zero coordinates` () = runTest {
94+ // Given
95+ val zeroLat = 0.0
96+ val zeroLon = 0.0
97+ coEvery { weatherRepository.getCurrentWeather(zeroLat, zeroLon) } returns expectedWeather
10598
106- // When
107- getCurrentWeatherUseCase.getCurrentWeather(zeroLat, zeroLon)
99+ // When
100+ val result = getCurrentWeatherUseCase.getCurrentWeather(zeroLat, zeroLon)
108101
109- // Then
110- coVerify { weatherRepository.getCurrentWeather(zeroLat, zeroLon) }
111- }
112- }
102+ // Then
103+ coVerify { weatherRepository.getCurrentWeather(zeroLat, zeroLon) }
104+ assertThat(result).isEqualTo(expectedWeather)
105+ }
106+ }
0 commit comments