Skip to content

Commit 3c724a1

Browse files
Merge remote-tracking branch 'origin/main' into dependabot/gradle/ktor-3.2.1
2 parents 8b6ffaa + 2947864 commit 3c724a1

File tree

20 files changed

+224
-27
lines changed

20 files changed

+224
-27
lines changed

.aiignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
.idea/
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild
9+
.cxx
10+
local.properties

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Pull Request
2+
3+
## Description
4+
<!-- Provide a clear and concise description of the changes you've made -->
5+
6+
## Type of Change
7+
<!-- Mark the appropriate option with an [x] -->
8+
- [ ] Bug fix (non-breaking change that fixes an issue)
9+
- [ ] New feature (non-breaking change that adds functionality)
10+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
11+
- [ ] Documentation update
12+
- [ ] Refactoring (no functional changes)
13+
- [ ] Performance improvement
14+
- [ ] Test addition or update
15+
- [ ] CI/CD configuration change
16+
- [ ] Other (please describe):
17+
18+
## How to Test
19+
<!-- Describe how to test your changes. Include steps to reproduce and verification steps. -->
20+
21+
## Checklist
22+
<!-- Mark completed items with an [x] -->
23+
- [ ] My code follows the project's code style
24+
- [ ] I have performed a self-review of my own code
25+
- [ ] I have commented my code, particularly in hard-to-understand areas
26+
- [ ] I have updated the documentation accordingly (if applicable)
27+
- [ ] I have added tests that prove my fix is effective or that my feature works
28+
29+
## Additional Notes
30+
<!-- Add any other context about the PR here. -->

.github/workflows/build.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Set up JDK 17
17-
uses: actions/setup-java@v3
17+
uses: actions/setup-java@v4
1818
with:
1919
java-version: '17'
2020
distribution: 'temurin'
2121
cache: gradle
2222

2323
- name: Setup Android SDK
24-
uses: android-actions/setup-android@v2
24+
uses: android-actions/setup-android@v3
2525

2626
- name: Cache Gradle packages
27-
uses: actions/cache@v3
27+
uses: actions/cache@v4
2828
with:
2929
path: |
3030
~/.gradle/caches
@@ -36,6 +36,12 @@ jobs:
3636
- name: Build with Gradle
3737
run: ./gradlew build check
3838

39+
- name: Enable KVM for faster android tests
40+
run: |
41+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
42+
sudo udevadm control --reload-rules
43+
sudo udevadm trigger --name-match=kvm
44+
3945
- name: Run Android Tests
4046
uses: reactivecircus/android-emulator-runner@v2
4147
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
.externalNativeBuild
99
.cxx
1010
local.properties
11+
pr-description.tmp.md

.junie/guidelines.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# MockWebServer Extensions - Development Guidelines
2+
3+
This document provides essential information for developers working on the MockWebServer Extensions project.
4+
5+
## Build/Configuration Instructions
6+
7+
### Prerequisites
8+
- JDK 11 or higher
9+
- Android SDK with API level 34 (compileSdk)
10+
- Gradle 8.x
11+
12+
### Project Setup
13+
1. Clone the repository
14+
2. Open the project in Android Studio or IntelliJ IDEA
15+
3. Sync the project with Gradle files
16+
17+
### Building the Project
18+
- To build the entire project: `./gradlew build`
19+
- To build a specific module: `./gradlew :moduleName:build`
20+
- Example: `./gradlew :mockwebserver-extensions:build`
21+
22+
### Publishing
23+
The library is configured for Maven publishing. To publish locally:
24+
```
25+
./gradlew publishToMavenLocal
26+
```
27+
28+
## Testing Information
29+
30+
### Running Tests
31+
- Run all tests: `./gradlew test`
32+
- Run tests for a specific module: `./gradlew :moduleName:test`
33+
- Example: `./gradlew :mockwebserver-extensions:test`
34+
35+
### Writing Tests
36+
The project uses JUnit 4 for testing, along with Strikt for assertions and Mockk for mocking.
37+
38+
#### Basic Test Structure
39+
```kotlin
40+
class YourTest {
41+
@get:Rule
42+
val mockWebServerRule: MockWebServerRule = MockWebServerRule()
43+
44+
@Test
45+
fun testSomething() {
46+
// Register a mock response
47+
mockWebServerRule.register { request ->
48+
// You can inspect the request here
49+
MockResponse().setBody("Your response")
50+
}
51+
52+
// Execute your code that makes HTTP requests
53+
val result = yourCodeThatMakesHttpRequests()
54+
55+
// Assert the results
56+
expectThat(result).isEqualTo(expectedValue)
57+
}
58+
}
59+
```
60+
61+
#### Key Testing Components
62+
1. **MockWebServerRule**: JUnit rule that sets up and manages a MockWebServer instance
63+
- Automatically installs and uninstalls the TestInterceptor
64+
- Provides methods to register mock responses
65+
- Reports errors that occurred during tests
66+
67+
2. **TestInterceptor**: Intercepts HTTP requests and redirects them to the MockWebServer
68+
- Automatically installed by MockWebServerRule
69+
- Can be customized with your own interceptor
70+
71+
3. **Assertions**: Custom assertions for HTTP responses
72+
- `code`: Assert response status code
73+
- `bodyString`: Assert response body as string
74+
- `headers`: Assert response headers
75+
- And many more in the mockwebserver-assertions module
76+
77+
### Example Test
78+
Here's a simple test that demonstrates how to use the MockWebServerRule:
79+
80+
```kotlin
81+
@Test
82+
fun testSimpleRequest() {
83+
// Register a mock response for any request
84+
mockWebServerRule.register { _ ->
85+
MockResponse().setBody("Hello, MockWebServer!")
86+
}
87+
88+
// Execute a request
89+
val client = OkHttpClient.Builder()
90+
.addInterceptor(TestInterceptor)
91+
.build()
92+
val request = okhttp3.Request.Builder()
93+
.url("https://example.com/test")
94+
.build()
95+
val response = client.newCall(request).execute()
96+
97+
// Verify the response
98+
expectThat(response).and {
99+
code.isEqualTo(200)
100+
bodyString.isEqualTo("Hello, MockWebServer!")
101+
}
102+
}
103+
```
104+
105+
## Additional Development Information
106+
107+
### Project Structure
108+
The project is organized into several modules:
109+
- **app**: Sample Android application
110+
- **mockwebserver-extensions**: Core library with MockWebServerRule and related components
111+
- **mockwebserver-interceptor**: Contains the TestInterceptor for redirecting HTTP requests
112+
- **mockwebserver-assertions**: Custom assertions for HTTP responses
113+
- **mockwebserver-allow-mocking**: Android configuration for allowing HTTP traffic to MockWebServer
114+
- **mockwebserver-request**: Request model and utilities
115+
116+
### Dependency Management
117+
The project uses Gradle version catalogs (libs.versions.toml) for dependency management.
118+
119+
### Code Style
120+
- The project follows Kotlin coding conventions
121+
- Use extension functions for adding functionality to existing classes
122+
- Write comprehensive tests for all new features
123+
124+
### Common Patterns
125+
1. **Response Generation**: Use the `ResponseGenerator` functional interface to create mock responses
126+
2. **Request Assertions**: Use the assertion extensions from mockwebserver-assertions to verify request properties
127+
3. **Network Simulation**: Use `simulateNetworkDown()` and `simulateNetworkUp()` methods to test network failure scenarios
128+
129+
## For AI: Generating a Pull Request
130+
131+
To generate a pull request description:
132+
133+
1. Read the content of the pull request template file located at `.github/PULL_REQUEST_TEMPLATE.md`.
134+
2. Get the code changes by running the command `git diff origin/HEAD...HEAD`.
135+
3. Analyze the changes and fill out the template with a relevant title, description, and checklist selections.
136+
4. Save the final output to a temporary file named `pr-description.tmp.md`.
137+
5. Ensure at the first line of `pr-description.tmp.md` there is a title of the pull request.

GEMINI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.junie/guidelines.md

app/.aiignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ plugins {
22
alias(libs.plugins.android.application)
33
alias(libs.plugins.kotlin.android)
44
alias(libs.plugins.kotlin.serialization)
5+
alias(libs.plugins.compose.compiler)
56
}
67

78
android {
89
namespace = "com.appunite.mockwebserver"
910
compileSdk = libs.versions.compileSdk.get().toInt()
1011

12+
lint {
13+
// Those two checks cause build failure, so we disable them
14+
disable += "MutableCollectionMutableState"
15+
disable += "AutoboxingStateCreation"
16+
}
17+
1118
defaultConfig {
1219
applicationId = "com.appunite.mockwebserverextensions"
1320
minSdk = libs.versions.minSdk.get().toInt()
@@ -31,18 +38,17 @@ android {
3138
}
3239
}
3340
compileOptions {
34-
sourceCompatibility = JavaVersion.VERSION_11
35-
targetCompatibility = JavaVersion.VERSION_11
41+
sourceCompatibility = JavaVersion.VERSION_17
42+
targetCompatibility = JavaVersion.VERSION_17
3643
}
37-
kotlinOptions {
38-
jvmTarget = libs.versions.javaVersion.get()
44+
kotlin {
45+
compilerOptions {
46+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget(libs.versions.javaVersion.get()))
47+
}
3948
}
4049
buildFeatures {
4150
compose = true
4251
}
43-
composeOptions {
44-
kotlinCompilerExtensionVersion = libs.versions.kotlinxSerialization.get()
45-
}
4652
packaging {
4753
resources {
4854
excludes += "/META-INF/{AL2.0,LGPL2.1}"
@@ -53,7 +59,6 @@ android {
5359
}
5460

5561
dependencies {
56-
5762
androidTestImplementation(project(":mockwebserver-extensions"))
5863
androidTestImplementation(project(":mockwebserver-assertions"))
5964
androidTestImplementation(project(":mockwebserver-request"))

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ plugins {
1111
allprojects {
1212
// Configure Kotlin compiler options
1313
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
14-
kotlinOptions {
15-
jvmTarget = libs.versions.javaVersion.get()
14+
compilerOptions {
15+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.fromTarget(libs.versions.javaVersion.get()))
1616
}
1717
}
1818
}

gradle/libs.versions.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[versions]
22
# Plugins
33
androidGradlePlugin = "8.11.0"
4-
kotlinPlugin = "1.9.0"
4+
kotlinPlugin = "2.2.0"
55

66
# Libraries
77
okhttp = "4.12.0"
88
striktMockk = "0.34.1"
99
junit = "4.13.2"
10-
androidxJunit = "1.1.5"
10+
androidxJunit = "1.2.1"
1111
androidxCore = "1.12.0"
1212
androidxLifecycle = "2.7.0"
1313
androidxActivity = "1.8.2"
@@ -23,7 +23,7 @@ projectVersion = "0.3.0"
2323
compileSdk = "34"
2424
minSdk = "23"
2525
targetSdk = "34"
26-
javaVersion = "11"
26+
javaVersion = "17"
2727

2828
[libraries]
2929
# OkHttp
@@ -66,3 +66,4 @@ android-library = { id = "com.android.library", version.ref = "androidGradlePlug
6666
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinPlugin" }
6767
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinPlugin" }
6868
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinPlugin" }
69+
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlinPlugin" }

0 commit comments

Comments
 (0)