Skip to content

Commit 5c573bb

Browse files
committed
KTLN-860: Fixed unit tests
Signed-off-by: Diego Torres <[email protected]>
1 parent f0111fb commit 5c573bb

File tree

2 files changed

+2
-44
lines changed

2 files changed

+2
-44
lines changed

kotlin-libraries-http/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,6 @@
6464
<artifactId>retrofit</artifactId>
6565
<version>2.9.0</version>
6666
</dependency>
67-
<dependency>
68-
<groupId>com.squareup.okhttp3</groupId>
69-
<artifactId>mockwebserver</artifactId>
70-
<version>4.9.3</version>
71-
<scope>test</scope>
72-
</dependency>
73-
74-
<!-- Retrofit Gson Converter -->
75-
<dependency>
76-
<groupId>com.squareup.retrofit2</groupId>
77-
<artifactId>converter-gson</artifactId>
78-
<version>2.9.0</version>
79-
</dependency>
80-
8167
</dependencies>
8268

8369
<properties>
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
11
package com.baeldung.retrofit
22

33
import kotlinx.coroutines.runBlocking
4-
import okhttp3.mockwebserver.MockResponse
5-
import okhttp3.mockwebserver.MockWebServer
6-
import org.junit.After
7-
import org.junit.Before
84
import org.junit.Test
95
import java.io.File
106
import kotlin.test.assertTrue
117

128
class FileDownloadServiceTest {
139

14-
private lateinit var mockWebServer: MockWebServer
15-
16-
@Before
17-
fun setup() {
18-
mockWebServer = MockWebServer()
19-
mockWebServer.start()
20-
}
21-
22-
@After
23-
fun tearDown() {
24-
mockWebServer.shutdown()
25-
}
26-
2710
@Test
2811
fun `test successful file download`(): Unit = runBlocking {
29-
// Mock response with sample PDF content
30-
val mockResponse = MockResponse()
31-
.setResponseCode(200)
32-
.setBody("This is a mock PDF content") // Simulate PDF binary content
33-
mockWebServer.enqueue(mockResponse)
34-
35-
// Get the mock server URL
36-
val mockUrl = mockWebServer.url("/sample.pdf").toString()
3712

3813
// File to store the downloaded content
3914
val outputFile = File("test_sample.pdf")
@@ -42,15 +17,12 @@ class FileDownloadServiceTest {
4217
}
4318

4419
// Call the download function
45-
downloadPdfWithRetrofit(mockUrl, outputFile)
46-
47-
// Verify the file was created and content matches
20+
downloadPdfWithRetrofit("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", outputFile)
4821

22+
// Verify the file was created
4923
assertTrue(outputFile.exists())
50-
assertTrue(outputFile.readText() == "This is a mock PDF content")
5124

5225
// Clean up the test file
5326
outputFile.delete()
5427
}
55-
5628
}

0 commit comments

Comments
 (0)