name: java-expert-tests
skill: java-expert
version: 1.0.0
cases:
  - id: field-injection-vs-constructor
    description: Should reject @Autowired field injection and recommend constructor injection
    prompt: "Should I use @Autowired on my fields or constructor injection in my Spring Boot service?"
    expected:
      contains_any:
        - constructor injection
        - final
        - "@Autowired field"
        - testability
        - explicit
        - immutable
      not_contains:
        - field injection is fine
      min_length: 80
    tags: [core, di]

  - id: optional-get-without-check
    description: Should reject Optional.get() without isPresent check and recommend orElseThrow
    prompt: I have an Optional<User> returned from my repository. I'm calling .get() on it directly. Is that a problem?
    expected:
      contains_any:
        - orElseThrow
        - NoSuchElementException
        - isPresent
        - orElse
        - map
        - unsafe
      not_contains:
        - fine
      min_length: 60
    tags: [core, null-safety]

  - id: modern-java-records
    description: Should recommend records for immutable data types in Java 21+
    prompt: I'm creating a Java class to represent a user's address with street, city, and zip. I'm writing the constructor, getters, equals, hashCode, and toString manually. Is there a better way in modern Java?
    expected:
      contains_any:
        - record
        - Java 16
        - Java 17
        - Java 21
        - immutable
        - value
        - equals
        - hashCode
      min_length: 80
    tags: [core, modern-java]

  - id: catch-exception-broadly
    description: Should reject catching Exception or Throwable without rethrowing
    prompt: My code keeps throwing various exceptions, so I wrapped the whole method body in catch(Exception e) and log the message. Is there a better approach?
    expected:
      contains_any:
        - specific exception
        - rethrow
        - re-throw
        - swallow
        - catch broad
        - specific class
      min_length: 80
    tags: [core, errors]

  - id: virtual-threads
    description: Should recommend virtual threads (Project Loom) for I/O-bound concurrency
    prompt: I have a Spring Boot application that makes many outbound HTTP calls. I'm using a thread pool with 100 threads. Should I increase the thread count?
    expected:
      contains_any:
        - virtual thread
        - Project Loom
        - Executors.newVirtualThreadPerTaskExecutor
        - Thread.ofVirtual
        - Java 21
        - lightweight
      min_length: 80
    tags: [core, concurrency]

  - id: sealed-classes-pattern-matching
    description: Should recommend sealed classes and pattern matching switch for discriminated unions
    prompt: I have a result type that can be either a success with data or a failure with an error message. I'm using a class with a boolean success flag and nullable fields. Is there a better way?
    expected:
      contains_any:
        - sealed
        - pattern matching
        - switch
        - Success
        - Failure
        - record
        - permits
      min_length: 80
    tags: [core, modern-java]

  - id: coding-easy-result-type
    description: "Coding challenge (easy): Implement a Result type using sealed classes"
    prompt: "Write a Java sealed interface Result<T> with Success and Failure record implementations. Include map, flatMap, and orElse methods. Use pattern matching with switch expressions where appropriate. Target Java 21+."
    expected:
      contains_any:
        - sealed
        - interface Result
        - record Success
        - record Failure
        - map
        - switch
      contains:
        - class
      not_contains:
        - "I can't write"
      min_length: 100
    tags:
      - coding-easy

  - id: coding-medium-circuit-breaker
    description: "Coding challenge (medium): Implement a circuit breaker pattern"
    prompt: "Write a Java circuit breaker class with three states: CLOSED (normal), OPEN (failing fast), and HALF_OPEN (testing recovery). It should track failure count, trip to OPEN after a configurable threshold, automatically transition to HALF_OPEN after a timeout, and reset to CLOSED on success in HALF_OPEN. Make it thread-safe and generic over the operation type."
    expected:
      contains_any:
        - CLOSED
        - OPEN
        - HALF_OPEN
        - threshold
        - AtomicInteger
        - synchronized
        - volatile
      contains:
        - class
      min_length: 200
    tags:
      - coding-medium

  - id: coding-hard-scheduler
    description: "Coding challenge (hard): Implement a priority task scheduler with virtual threads"
    prompt: "Write a Java task scheduler that uses virtual threads (Java 21+). It should support: submitting tasks with priority levels, a configurable max concurrency limit, task dependencies (task B waits for task A to complete), cancellation with proper cleanup, and returning a CompletableFuture per task. Handle circular dependency detection."
    expected:
      contains_any:
        - virtual
        - Thread.ofVirtual
        - CompletableFuture
        - priority
        - PriorityQueue
        - Semaphore
        - dependency
        - circular
      contains:
        - class
      min_length: 300
    tags:
      - coding-hard
