@ranimontagna/agent-toolkit 0.1.6 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -10
- package/package.json +1 -1
- package/skills/backend/database/postgres-patterns/LICENSE.ANTIGRAVITY +21 -0
- package/skills/backend/database/postgres-patterns/LICENSE.ECC +21 -0
- package/skills/backend/database/postgres-patterns/NOTICE.md +11 -0
- package/skills/backend/database/postgres-patterns/SKILL.md +180 -0
- package/skills/backend/go/golang-patterns/LICENSE +21 -0
- package/skills/backend/go/golang-patterns/NOTICE.md +10 -0
- package/skills/backend/go/golang-patterns/SKILL.md +674 -0
- package/skills/backend/go/golang-testing/LICENSE +21 -0
- package/skills/backend/go/golang-testing/NOTICE.md +10 -0
- package/skills/backend/go/golang-testing/SKILL.md +329 -0
- package/skills/backend/java/java-coding-standards/LICENSE +21 -0
- package/skills/backend/java/java-coding-standards/NOTICE.md +10 -0
- package/skills/backend/java/java-coding-standards/SKILL.md +383 -0
- package/skills/backend/java/java-junit/LICENSE +21 -0
- package/skills/backend/java/java-junit/NOTICE.md +10 -0
- package/skills/backend/java/java-junit/SKILL.md +64 -0
- package/skills/backend/kotlin/kotlin-patterns/LICENSE +21 -0
- package/skills/backend/kotlin/kotlin-patterns/NOTICE.md +7 -0
- package/skills/backend/kotlin/kotlin-patterns/SKILL.md +711 -0
- package/skills/backend/kotlin/kotlin-testing/LICENSE +21 -0
- package/skills/backend/kotlin/kotlin-testing/NOTICE.md +7 -0
- package/skills/backend/kotlin/kotlin-testing/SKILL.md +824 -0
- package/skills/backend/python/python-patterns/LICENSE +21 -0
- package/skills/backend/python/python-patterns/NOTICE.md +7 -0
- package/skills/backend/python/python-patterns/SKILL.md +424 -0
- package/skills/backend/python/python-testing/LICENSE +21 -0
- package/skills/backend/python/python-testing/NOTICE.md +7 -0
- package/skills/backend/python/python-testing/SKILL.md +494 -0
- package/skills/devops/docker-patterns/LICENSE.ANTIGRAVITY +21 -0
- package/skills/devops/docker-patterns/LICENSE.ECC +21 -0
- package/skills/devops/docker-patterns/NOTICE.md +11 -0
- package/skills/devops/docker-patterns/SKILL.md +397 -0
- package/skills/frontend/accessibility/LICENSE +21 -0
- package/skills/frontend/accessibility/NOTICE.md +10 -0
- package/skills/frontend/accessibility/SKILL.md +145 -0
- package/skills/frontend/design/ui-ux-pro-max/LICENSE +21 -0
- package/skills/frontend/design/ui-ux-pro-max/NOTICE.md +12 -0
- package/skills/frontend/design/ui-ux-pro-max/SKILL.md +672 -0
- package/skills/frontend/design/ui-ux-pro-max/data/_sync_all.py +414 -0
- package/skills/frontend/design/ui-ux-pro-max/data/app-interface.csv +31 -0
- package/skills/frontend/design/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/frontend/design/ui-ux-pro-max/data/colors.csv +162 -0
- package/skills/frontend/design/ui-ux-pro-max/data/design.csv +1776 -0
- package/skills/frontend/design/ui-ux-pro-max/data/draft.csv +1779 -0
- package/skills/frontend/design/ui-ux-pro-max/data/google-fonts.csv +1924 -0
- package/skills/frontend/design/ui-ux-pro-max/data/icons.csv +106 -0
- package/skills/frontend/design/ui-ux-pro-max/data/landing.csv +35 -0
- package/skills/frontend/design/ui-ux-pro-max/data/products.csv +162 -0
- package/skills/frontend/design/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/angular.csv +51 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
- package/skills/frontend/design/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/frontend/design/ui-ux-pro-max/data/styles.csv +85 -0
- package/skills/frontend/design/ui-ux-pro-max/data/typography.csv +74 -0
- package/skills/frontend/design/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
- package/skills/frontend/design/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/frontend/design/ui-ux-pro-max/scripts/core.py +262 -0
- package/skills/frontend/design/ui-ux-pro-max/scripts/design_system.py +1148 -0
- package/skills/frontend/design/ui-ux-pro-max/scripts/search.py +114 -0
- package/skills/frontend/react/react-patterns/SKILL.md +4 -4
- package/skills/frontend/react/react-patterns/rules/react/LICENSE +21 -0
- package/skills/frontend/react/react-patterns/rules/react/NOTICE.md +11 -0
- package/skills/frontend/react/react-patterns/rules/react/coding-style.md +109 -0
- package/skills/frontend/react/react-patterns/rules/react/hooks.md +187 -0
- package/skills/frontend/react/react-patterns/rules/react/patterns.md +194 -0
- package/skills/frontend/react/react-patterns/rules/react/security.md +180 -0
- package/skills/frontend/react/react-patterns/rules/react/testing.md +208 -0
- package/skills/frontend/react/react-performance/SKILL.md +2 -2
- package/skills/frontend/react/react-performance/rules/react/LICENSE +21 -0
- package/skills/frontend/react/react-performance/rules/react/NOTICE.md +11 -0
- package/skills/frontend/react/react-performance/rules/react/coding-style.md +109 -0
- package/skills/frontend/react/react-performance/rules/react/hooks.md +187 -0
- package/skills/frontend/react/react-performance/rules/react/patterns.md +194 -0
- package/skills/frontend/react/react-performance/rules/react/security.md +180 -0
- package/skills/frontend/react/react-performance/rules/react/testing.md +208 -0
- package/skills/frontend/react/react-testing/SKILL.md +4 -4
- package/skills/frontend/react/react-testing/rules/react/LICENSE +21 -0
- package/skills/frontend/react/react-testing/rules/react/NOTICE.md +11 -0
- package/skills/frontend/react/react-testing/rules/react/coding-style.md +109 -0
- package/skills/frontend/react/react-testing/rules/react/hooks.md +187 -0
- package/skills/frontend/react/react-testing/rules/react/patterns.md +194 -0
- package/skills/frontend/react/react-testing/rules/react/security.md +180 -0
- package/skills/frontend/react/react-testing/rules/react/testing.md +208 -0
- package/skills/general/code-reviewer/AGENTS.md +292 -0
- package/skills/general/code-reviewer/LICENSE +201 -0
- package/skills/general/code-reviewer/NOTICE.md +10 -0
- package/skills/general/code-reviewer/SKILL.md +132 -0
- package/skills/general/code-reviewer/rules/correctness-error-handling.md +279 -0
- package/skills/general/code-reviewer/rules/maintainability-naming.md +149 -0
- package/skills/general/code-reviewer/rules/maintainability-type-hints.md +93 -0
- package/skills/general/code-reviewer/rules/performance-n-plus-one.md +250 -0
- package/skills/general/code-reviewer/rules/security-sql-injection.md +142 -0
- package/skills/general/code-reviewer/rules/security-xss-prevention.md +225 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: java-coding-standards
|
|
3
|
+
description: "Use when writing or reviewing Java 17+ code in Spring Boot or Quarkus services, including naming, immutability, Optional usage, streams, exceptions, generics, CDI, reactive patterns, and project layout."
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Java Coding Standards
|
|
8
|
+
|
|
9
|
+
Standards for readable, maintainable Java (17+) code in Spring Boot and Quarkus services.
|
|
10
|
+
|
|
11
|
+
## When to Use
|
|
12
|
+
|
|
13
|
+
- Writing or reviewing Java code in Spring Boot or Quarkus projects
|
|
14
|
+
- Enforcing naming, immutability, or exception handling conventions
|
|
15
|
+
- Working with records, sealed classes, or pattern matching (Java 17+)
|
|
16
|
+
- Reviewing use of Optional, streams, or generics
|
|
17
|
+
- Structuring packages and project layout
|
|
18
|
+
- **[QUARKUS]**: Working with CDI scopes, Panache entities, or reactive pipelines
|
|
19
|
+
|
|
20
|
+
## How It Works
|
|
21
|
+
|
|
22
|
+
### Framework Detection
|
|
23
|
+
|
|
24
|
+
Before applying standards, determine the framework from the build file:
|
|
25
|
+
|
|
26
|
+
- Build file contains `quarkus` → apply **[QUARKUS]** conventions
|
|
27
|
+
- Build file contains `spring-boot` → apply **[SPRING]** conventions
|
|
28
|
+
- Neither detected → apply shared conventions only
|
|
29
|
+
|
|
30
|
+
## Core Principles
|
|
31
|
+
|
|
32
|
+
- Prefer clarity over cleverness
|
|
33
|
+
- Immutable by default; minimize shared mutable state
|
|
34
|
+
- Fail fast with meaningful exceptions
|
|
35
|
+
- Consistent naming and package structure
|
|
36
|
+
- **[QUARKUS]**: Favor build-time over runtime processing; avoid runtime reflection where possible
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
The sections below show concrete Spring Boot, Quarkus, and shared Java examples
|
|
41
|
+
for naming, immutability, dependency injection, reactive code, exceptions,
|
|
42
|
+
project layout, logging, configuration, and tests.
|
|
43
|
+
|
|
44
|
+
## Naming
|
|
45
|
+
|
|
46
|
+
```java
|
|
47
|
+
// PASS: Classes/Records: PascalCase
|
|
48
|
+
public class MarketService {}
|
|
49
|
+
public record Money(BigDecimal amount, Currency currency) {}
|
|
50
|
+
|
|
51
|
+
// PASS: Methods/fields: camelCase
|
|
52
|
+
private final MarketRepository marketRepository;
|
|
53
|
+
public Market findBySlug(String slug) {}
|
|
54
|
+
|
|
55
|
+
// PASS: Constants: UPPER_SNAKE_CASE
|
|
56
|
+
private static final int MAX_PAGE_SIZE = 100;
|
|
57
|
+
|
|
58
|
+
// PASS: [QUARKUS] JAX-RS resources named as *Resource, not *Controller
|
|
59
|
+
public class MarketResource {}
|
|
60
|
+
|
|
61
|
+
// PASS: [SPRING] REST controllers named as *Controller
|
|
62
|
+
public class MarketController {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Immutability
|
|
66
|
+
|
|
67
|
+
```java
|
|
68
|
+
// PASS: Favor records and final fields
|
|
69
|
+
public record MarketDto(Long id, String name, MarketStatus status) {}
|
|
70
|
+
|
|
71
|
+
public class Market {
|
|
72
|
+
private final Long id;
|
|
73
|
+
private final String name;
|
|
74
|
+
// getters only, no setters
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// PASS: [QUARKUS] Panache active-record entities use public fields (Quarkus convention)
|
|
78
|
+
@Entity
|
|
79
|
+
public class Market extends PanacheEntity {
|
|
80
|
+
public String name;
|
|
81
|
+
public MarketStatus status;
|
|
82
|
+
// Panache generates accessors at build time; public fields are idiomatic here
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// PASS: [QUARKUS] Panache MongoDB entities
|
|
86
|
+
@MongoEntity(collection = "markets")
|
|
87
|
+
public class Market extends PanacheMongoEntity {
|
|
88
|
+
public String name;
|
|
89
|
+
public MarketStatus status;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Optional Usage
|
|
94
|
+
|
|
95
|
+
```java
|
|
96
|
+
// PASS: Return Optional from find* methods
|
|
97
|
+
// [SPRING]
|
|
98
|
+
Optional<Market> market = marketRepository.findBySlug(slug);
|
|
99
|
+
|
|
100
|
+
// [QUARKUS] Panache
|
|
101
|
+
Optional<Market> market = Market.find("slug", slug).firstResultOptional();
|
|
102
|
+
|
|
103
|
+
// PASS: Map/flatMap instead of get()
|
|
104
|
+
return market
|
|
105
|
+
.map(MarketResponse::from)
|
|
106
|
+
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Streams Best Practices
|
|
110
|
+
|
|
111
|
+
```java
|
|
112
|
+
// PASS: Use streams for transformations, keep pipelines short
|
|
113
|
+
List<String> names = markets.stream()
|
|
114
|
+
.map(Market::name)
|
|
115
|
+
.filter(Objects::nonNull)
|
|
116
|
+
.toList();
|
|
117
|
+
|
|
118
|
+
// FAIL: Avoid complex nested streams; prefer loops for clarity
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Dependency Injection
|
|
122
|
+
|
|
123
|
+
```java
|
|
124
|
+
// PASS: [SPRING] Constructor injection (preferred over @Autowired on fields)
|
|
125
|
+
@Service
|
|
126
|
+
public class MarketService {
|
|
127
|
+
private final MarketRepository marketRepository;
|
|
128
|
+
|
|
129
|
+
public MarketService(MarketRepository marketRepository) {
|
|
130
|
+
this.marketRepository = marketRepository;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// PASS: [QUARKUS] Constructor injection
|
|
135
|
+
@ApplicationScoped
|
|
136
|
+
public class MarketService {
|
|
137
|
+
private final MarketRepository marketRepository;
|
|
138
|
+
|
|
139
|
+
@Inject
|
|
140
|
+
public MarketService(MarketRepository marketRepository) {
|
|
141
|
+
this.marketRepository = marketRepository;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// PASS: [QUARKUS] Package-private field injection (acceptable in Quarkus — avoids proxy issues)
|
|
146
|
+
@ApplicationScoped
|
|
147
|
+
public class MarketService {
|
|
148
|
+
@Inject
|
|
149
|
+
MarketRepository marketRepository;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// FAIL: [SPRING] Field injection with @Autowired
|
|
153
|
+
@Autowired
|
|
154
|
+
private MarketRepository marketRepository; // use constructor injection
|
|
155
|
+
|
|
156
|
+
// FAIL: [QUARKUS] @Singleton when interception or lazy init is needed
|
|
157
|
+
@Singleton // non-proxyable — use @ApplicationScoped instead
|
|
158
|
+
public class MarketService {}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Reactive Patterns [QUARKUS]
|
|
162
|
+
|
|
163
|
+
```java
|
|
164
|
+
// PASS: Return Uni/Multi from reactive endpoints
|
|
165
|
+
@GET
|
|
166
|
+
@Path("/{slug}")
|
|
167
|
+
public Uni<Market> findBySlug(@PathParam("slug") String slug) {
|
|
168
|
+
return Market.find("slug", slug)
|
|
169
|
+
.<Market>firstResult()
|
|
170
|
+
.onItem().ifNull().failWith(() -> new MarketNotFoundException(slug));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// PASS: Non-blocking pipeline composition
|
|
174
|
+
public Uni<OrderConfirmation> placeOrder(OrderRequest req) {
|
|
175
|
+
return validateOrder(req)
|
|
176
|
+
.chain(valid -> persistOrder(valid))
|
|
177
|
+
.chain(order -> notifyFulfillment(order));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// FAIL: Blocking call inside a Uni/Multi pipeline
|
|
181
|
+
public Uni<Market> find(String slug) {
|
|
182
|
+
Market m = Market.find("slug", slug).firstResult(); // BLOCKING — breaks event loop
|
|
183
|
+
return Uni.createFrom().item(m);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// FAIL: Subscribing more than once to a shared Uni
|
|
187
|
+
Uni<Market> shared = fetchMarket(slug);
|
|
188
|
+
shared.subscribe().with(m -> log(m));
|
|
189
|
+
shared.subscribe().with(m -> cache(m)); // double subscribe — use Uni.memoize()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Exceptions
|
|
193
|
+
|
|
194
|
+
- Use unchecked exceptions for domain errors; wrap technical exceptions with context
|
|
195
|
+
- Create domain-specific exceptions (e.g., `MarketNotFoundException`)
|
|
196
|
+
- Avoid broad `catch (Exception ex)` unless rethrowing/logging centrally
|
|
197
|
+
|
|
198
|
+
```java
|
|
199
|
+
throw new MarketNotFoundException(slug);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Centralised Exception Handling
|
|
203
|
+
|
|
204
|
+
```java
|
|
205
|
+
// [SPRING]
|
|
206
|
+
@RestControllerAdvice
|
|
207
|
+
public class GlobalExceptionHandler {
|
|
208
|
+
@ExceptionHandler(MarketNotFoundException.class)
|
|
209
|
+
public ResponseEntity<ErrorResponse> handle(MarketNotFoundException ex) {
|
|
210
|
+
return ResponseEntity.status(404).body(ErrorResponse.from(ex));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// [QUARKUS] Option A: ExceptionMapper
|
|
215
|
+
@Provider
|
|
216
|
+
public class MarketNotFoundMapper implements ExceptionMapper<MarketNotFoundException> {
|
|
217
|
+
@Override
|
|
218
|
+
public Response toResponse(MarketNotFoundException ex) {
|
|
219
|
+
return Response.status(404).entity(ErrorResponse.from(ex)).build();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// [QUARKUS] Option B: @ServerExceptionMapper (RESTEasy Reactive)
|
|
224
|
+
@ServerExceptionMapper
|
|
225
|
+
public RestResponse<ErrorResponse> handle(MarketNotFoundException ex) {
|
|
226
|
+
return RestResponse.status(Status.NOT_FOUND, ErrorResponse.from(ex));
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Generics and Type Safety
|
|
231
|
+
|
|
232
|
+
- Avoid raw types; declare generic parameters
|
|
233
|
+
- Prefer bounded generics for reusable utilities
|
|
234
|
+
|
|
235
|
+
```java
|
|
236
|
+
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Project Structure
|
|
240
|
+
|
|
241
|
+
### [SPRING] Maven/Gradle
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
src/main/java/com/example/app/
|
|
245
|
+
config/
|
|
246
|
+
controller/
|
|
247
|
+
service/
|
|
248
|
+
repository/
|
|
249
|
+
domain/
|
|
250
|
+
dto/
|
|
251
|
+
util/
|
|
252
|
+
src/main/resources/
|
|
253
|
+
application.yml
|
|
254
|
+
src/test/java/... (mirrors main)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### [QUARKUS] Maven/Gradle
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
src/main/java/com/example/app/
|
|
261
|
+
config/ # @ConfigMapping, @ConfigProperty beans, Producers
|
|
262
|
+
resource/ # JAX-RS resources (not "controller")
|
|
263
|
+
service/
|
|
264
|
+
repository/ # PanacheRepository implementations (if not using active record)
|
|
265
|
+
domain/ # JPA/Panache entities, MongoDB entities
|
|
266
|
+
dto/
|
|
267
|
+
util/
|
|
268
|
+
mapper/ # MapStruct mappers (if used)
|
|
269
|
+
src/main/resources/
|
|
270
|
+
application.properties # Quarkus convention (YAML supported with quarkus-config-yaml)
|
|
271
|
+
import.sql # Hibernate auto-import for dev/test
|
|
272
|
+
src/test/java/... (mirrors main)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Formatting and Style
|
|
276
|
+
|
|
277
|
+
- Use 2 or 4 spaces consistently (project standard)
|
|
278
|
+
- One public top-level type per file
|
|
279
|
+
- Keep methods short and focused; extract helpers
|
|
280
|
+
- Order members: constants, fields, constructors, public methods, protected, private
|
|
281
|
+
|
|
282
|
+
## Code Smells to Avoid
|
|
283
|
+
|
|
284
|
+
- Long parameter lists → use DTO/builders
|
|
285
|
+
- Deep nesting → early returns
|
|
286
|
+
- Magic numbers → named constants
|
|
287
|
+
- Static mutable state → prefer dependency injection
|
|
288
|
+
- Silent catch blocks → log and act or rethrow
|
|
289
|
+
- **[QUARKUS]**: `@Singleton` where `@ApplicationScoped` is intended — breaks proxying and interception
|
|
290
|
+
- **[QUARKUS]**: Mixing `quarkus-resteasy-reactive` and `quarkus-resteasy` (classic) — pick one stack
|
|
291
|
+
- **[QUARKUS]**: Panache active-record + repository pattern in the same bounded context — pick one
|
|
292
|
+
|
|
293
|
+
## Logging
|
|
294
|
+
|
|
295
|
+
```java
|
|
296
|
+
// [SPRING] SLF4J
|
|
297
|
+
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
|
|
298
|
+
log.info("fetch_market slug={}", slug);
|
|
299
|
+
log.error("failed_fetch_market slug={}", slug, ex);
|
|
300
|
+
|
|
301
|
+
// [QUARKUS] JBoss Logging (default, zero-cost at build time)
|
|
302
|
+
private static final Logger log = Logger.getLogger(MarketService.class);
|
|
303
|
+
log.infof("fetch_market slug=%s", slug);
|
|
304
|
+
log.errorf(ex, "failed_fetch_market slug=%s", slug);
|
|
305
|
+
|
|
306
|
+
// [QUARKUS] Alternative: simplified logging with @Inject
|
|
307
|
+
@Inject
|
|
308
|
+
Logger log; // CDI-injected, scoped to declaring class
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Null Handling
|
|
312
|
+
|
|
313
|
+
- Accept `@Nullable` only when unavoidable; otherwise use `@NonNull`
|
|
314
|
+
- Use Bean Validation (`@NotNull`, `@NotBlank`) on inputs
|
|
315
|
+
- **[QUARKUS]**: Apply `@Valid` on `@BeanParam`, `@RestForm`, and request body parameters
|
|
316
|
+
|
|
317
|
+
## Configuration
|
|
318
|
+
|
|
319
|
+
```java
|
|
320
|
+
// [SPRING] @ConfigurationProperties
|
|
321
|
+
@ConfigurationProperties(prefix = "market")
|
|
322
|
+
public record MarketProperties(int maxPageSize, Duration cacheTtl) {}
|
|
323
|
+
|
|
324
|
+
// [QUARKUS] @ConfigMapping (type-safe, build-time validated)
|
|
325
|
+
@ConfigMapping(prefix = "market")
|
|
326
|
+
public interface MarketConfig {
|
|
327
|
+
int maxPageSize();
|
|
328
|
+
Duration cacheTtl();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// [QUARKUS] Simple values with @ConfigProperty
|
|
332
|
+
@ConfigProperty(name = "market.max-page-size", defaultValue = "100")
|
|
333
|
+
int maxPageSize;
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Testing Expectations
|
|
337
|
+
|
|
338
|
+
### Shared
|
|
339
|
+
- JUnit 5 + AssertJ for fluent assertions
|
|
340
|
+
- Mockito for mocking; avoid partial mocks where possible
|
|
341
|
+
- Favor deterministic tests; no hidden sleeps
|
|
342
|
+
|
|
343
|
+
### [SPRING]
|
|
344
|
+
- `@WebMvcTest` for controller slices, `@DataJpaTest` for repository slices
|
|
345
|
+
- `@SpringBootTest` reserved for full integration tests
|
|
346
|
+
- `@MockBean` for replacing beans in Spring context
|
|
347
|
+
|
|
348
|
+
### [QUARKUS]
|
|
349
|
+
- Plain JUnit 5 + Mockito for unit tests (no `@QuarkusTest`)
|
|
350
|
+
- `@QuarkusTest` reserved for CDI integration tests
|
|
351
|
+
- `@InjectMock` for replacing CDI beans in integration tests
|
|
352
|
+
- Dev Services for database/Kafka/Redis — avoid manual Testcontainers setup when Dev Services suffice
|
|
353
|
+
- `@QuarkusTestResource` for custom external service lifecycle
|
|
354
|
+
|
|
355
|
+
```java
|
|
356
|
+
// [SPRING] Controller test
|
|
357
|
+
@WebMvcTest(MarketController.class)
|
|
358
|
+
class MarketControllerTest {
|
|
359
|
+
@Autowired MockMvc mockMvc;
|
|
360
|
+
@MockBean MarketService marketService;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// [QUARKUS] Integration test
|
|
364
|
+
@QuarkusTest
|
|
365
|
+
class MarketResourceTest {
|
|
366
|
+
@InjectMock
|
|
367
|
+
MarketService marketService;
|
|
368
|
+
|
|
369
|
+
@Test
|
|
370
|
+
void should_return_404_when_market_not_found() {
|
|
371
|
+
given().when().get("/markets/unknown").then().statusCode(404);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// [QUARKUS] Unit test (no CDI, no @QuarkusTest)
|
|
376
|
+
@ExtendWith(MockitoExtension.class)
|
|
377
|
+
class MarketServiceTest {
|
|
378
|
+
@Mock MarketRepository marketRepository;
|
|
379
|
+
@InjectMocks MarketService marketService;
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
**Remember**: Keep code intentional, typed, and observable. Optimize for maintainability over micro-optimizations unless proven necessary.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright GitHub, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Third-party notice
|
|
2
|
+
|
|
3
|
+
This skill was copied from GitHub's awesome-copilot repository.
|
|
4
|
+
|
|
5
|
+
- Source: https://github.com/github/awesome-copilot/tree/main/skills/java-junit
|
|
6
|
+
- Source commit: 776d84143238cb91f7242665f188887b9e8d2aa9
|
|
7
|
+
- License: MIT
|
|
8
|
+
- Copyright: Copyright GitHub, Inc.
|
|
9
|
+
|
|
10
|
+
The upstream MIT license is included in `LICENSE`.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: java-junit
|
|
3
|
+
description: Use when writing or improving JUnit 5 unit tests, including parameterized and data-driven tests.
|
|
4
|
+
origin: awesome-copilot
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# JUnit 5+ Best Practices
|
|
8
|
+
|
|
9
|
+
Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches.
|
|
10
|
+
|
|
11
|
+
## Project Setup
|
|
12
|
+
|
|
13
|
+
- Use a standard Maven or Gradle project structure.
|
|
14
|
+
- Place test source code in `src/test/java`.
|
|
15
|
+
- Include dependencies for `junit-jupiter-api`, `junit-jupiter-engine`, and `junit-jupiter-params` for parameterized tests.
|
|
16
|
+
- Use build tool commands to run tests: `mvn test` or `gradle test`.
|
|
17
|
+
|
|
18
|
+
## Test Structure
|
|
19
|
+
|
|
20
|
+
- Test classes should have a `Test` suffix, e.g., `CalculatorTest` for a `Calculator` class.
|
|
21
|
+
- Use `@Test` for test methods.
|
|
22
|
+
- Follow the Arrange-Act-Assert (AAA) pattern.
|
|
23
|
+
- Name tests using a descriptive convention, like `methodName_should_expectedBehavior_when_scenario`.
|
|
24
|
+
- Use `@BeforeEach` and `@AfterEach` for per-test setup and teardown.
|
|
25
|
+
- Use `@BeforeAll` and `@AfterAll` for per-class setup and teardown (must be static methods).
|
|
26
|
+
- Use `@DisplayName` to provide a human-readable name for test classes and methods.
|
|
27
|
+
|
|
28
|
+
## Standard Tests
|
|
29
|
+
|
|
30
|
+
- Keep tests focused on a single behavior.
|
|
31
|
+
- Avoid testing multiple conditions in one test method.
|
|
32
|
+
- Make tests independent and idempotent (can run in any order).
|
|
33
|
+
- Avoid test interdependencies.
|
|
34
|
+
|
|
35
|
+
## Data-Driven (Parameterized) Tests
|
|
36
|
+
|
|
37
|
+
- Use `@ParameterizedTest` to mark a method as a parameterized test.
|
|
38
|
+
- Use `@ValueSource` for simple literal values (strings, ints, etc.).
|
|
39
|
+
- Use `@MethodSource` to refer to a factory method that provides test arguments as a `Stream`, `Collection`, etc.
|
|
40
|
+
- Use `@CsvSource` for inline comma-separated values.
|
|
41
|
+
- Use `@CsvFileSource` to use a CSV file from the classpath.
|
|
42
|
+
- Use `@EnumSource` to use enum constants.
|
|
43
|
+
|
|
44
|
+
## Assertions
|
|
45
|
+
|
|
46
|
+
- Use the static methods from `org.junit.jupiter.api.Assertions` (e.g., `assertEquals`, `assertTrue`, `assertNotNull`).
|
|
47
|
+
- For more fluent and readable assertions, consider using a library like AssertJ (`assertThat(...).is...`).
|
|
48
|
+
- Use `assertThrows` or `assertDoesNotThrow` to test for exceptions.
|
|
49
|
+
- Group related assertions with `assertAll` to ensure all assertions are checked before the test fails.
|
|
50
|
+
- Use descriptive messages in assertions to provide clarity on failure.
|
|
51
|
+
|
|
52
|
+
## Mocking and Isolation
|
|
53
|
+
|
|
54
|
+
- Use a mocking framework like Mockito to create mock objects for dependencies.
|
|
55
|
+
- Use `@Mock` and `@InjectMocks` annotations from Mockito to simplify mock creation and injection.
|
|
56
|
+
- Use interfaces to facilitate mocking.
|
|
57
|
+
|
|
58
|
+
## Test Organization
|
|
59
|
+
|
|
60
|
+
- Group tests by feature or component using packages.
|
|
61
|
+
- Use `@Tag` to categorize tests (e.g., `@Tag("fast")`, `@Tag("integration")`).
|
|
62
|
+
- Use `@TestMethodOrder(MethodOrderer.OrderAnnotation.class)` and `@Order` to control test execution order when strictly necessary.
|
|
63
|
+
- Use `@Disabled` to temporarily skip a test method or class, providing a reason.
|
|
64
|
+
- Use `@Nested` to group tests in a nested inner class for better organization and structure.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Affaan Mustafa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|