-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from hossain-khan/feature/add-tests-by-ai
[ADDED] Tests by AI (github copilot)
- Loading branch information
Showing
8 changed files
with
310 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
src/test/kotlin/dev/hossain/githubstats/util/ErrorProcessorTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package dev.hossain.githubstats.util | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.ResponseBody.Companion.toResponseBody | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import retrofit2.HttpException | ||
import retrofit2.Response | ||
|
||
/** | ||
* Test for [ErrorProcessor] | ||
*/ | ||
class ErrorProcessorTest { | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
} | ||
|
||
@AfterEach | ||
fun tearDown() { | ||
} | ||
|
||
@Test | ||
fun `getDetailedError - given HttpException with error body - returns IllegalStateException with detailed message`() { | ||
val httpException = HttpException(Response.error<Any>(404, "Not found".toResponseBody("text/plain".toMediaTypeOrNull()))) | ||
val errorProcessor = ErrorProcessor() | ||
|
||
val exception = errorProcessor.getDetailedError(httpException) | ||
|
||
assertThat(exception).isInstanceOf(IllegalStateException::class.java) | ||
assertThat(exception.message).contains("HTTP 404") | ||
assertThat(exception.message).contains("Not found") | ||
} | ||
|
||
@Test | ||
fun `getDetailedError - given HttpException without error body - returns IllegalStateException with detailed message`() { | ||
val httpException = HttpException(Response.error<Any>(404, "".toResponseBody("text/plain".toMediaTypeOrNull()))) | ||
val errorProcessor = ErrorProcessor() | ||
|
||
val exception = errorProcessor.getDetailedError(httpException) | ||
|
||
assertThat(exception).isInstanceOf(IllegalStateException::class.java) | ||
assertThat(exception.message).contains("HTTP 404") | ||
} | ||
|
||
@Test | ||
fun `getDetailedError - given non HttpException - returns IllegalStateException with detailed message`() { | ||
val exception = Exception("Some error") | ||
val errorProcessor = ErrorProcessor() | ||
|
||
val detailedException = errorProcessor.getDetailedError(exception) | ||
|
||
assertThat(detailedException).isInstanceOf(IllegalStateException::class.java) | ||
assertThat(detailedException.message).contains("Some error") | ||
} | ||
} |
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
81 changes: 81 additions & 0 deletions
81
src/test/kotlin/dev/hossain/time/DurationExtensionKtTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dev.hossain.time | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import kotlin.time.Duration | ||
|
||
/** | ||
* Contains unit tests for [DurationExtension]. | ||
*/ | ||
class DurationExtensionKtTest { | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
} | ||
|
||
@AfterEach | ||
fun tearDown() { | ||
} | ||
|
||
@Test | ||
fun toWorkingHour() { | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration less than working hours - returns same duration`() { | ||
val duration = "2h".duration() | ||
|
||
val result = duration.toWorkingHour() | ||
|
||
assertThat(result).isEqualTo("2h") | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration equal to working hours - returns one day`() { | ||
val duration = "8h".duration() | ||
|
||
val result = duration.toWorkingHour() | ||
|
||
assertThat(result).isEqualTo("1 day [Based on 8h on a working day]") | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration more than working hours but less than two working days - returns days and hours`() { | ||
val duration = "10h".duration() | ||
|
||
val result = duration.toWorkingHour() | ||
|
||
assertThat(result).isEqualTo("1 day and 2h [Based on 8h on a working day]") | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration equal to two working days - returns two days`() { | ||
val duration = "16h".duration() | ||
|
||
val result = duration.toWorkingHour() | ||
|
||
assertThat(result).isEqualTo("2 days [Based on 8h on a working day]") | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration of one day - returns three days`() { | ||
val duration = "24h".duration() | ||
|
||
val result = duration.toWorkingHour() | ||
|
||
assertThat(result).isEqualTo("3 days [Based on 8h on a working day]") | ||
} | ||
|
||
@Test | ||
fun `toWorkingHour - given duration of one day and custom working hours - returns custom days`() { | ||
val duration = "24h".duration() | ||
|
||
val result = duration.toWorkingHour(6) | ||
|
||
assertThat(result).isEqualTo("4 days [Based on 6h on a working day]") | ||
} | ||
|
||
private fun String.duration(): Duration = Duration.parse(this) | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/kotlin/dev/hossain/time/InstantExtensionKtTest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.hossain.time | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.datetime.Instant | ||
import org.junit.jupiter.api.Test | ||
|
||
/** | ||
* Contains unit tests for [InstantExtensionKt]. | ||
*/ | ||
class InstantExtensionKtTest { | ||
@Test | ||
fun `toZdt - given Instant - returns ZonedDateTime at New York timezone`() { | ||
val instant: Instant = Instant.parse("2022-09-05T10:00:00Z") | ||
|
||
val zonedDateTime = instant.toZdt() | ||
|
||
assertThat(zonedDateTime.zone.id).isEqualTo("America/New_York") | ||
} | ||
|
||
@Test | ||
fun `format - given Instant - returns formatted string in New York timezone`() { | ||
val instant: Instant = Instant.parse("2022-09-05T10:00:00Z") | ||
|
||
val formattedString = instant.format() | ||
|
||
assertThat(formattedString).isEqualTo("Monday, September 5, 2022 at 6:00:00 AM Eastern Daylight Time") | ||
} | ||
} |
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