Skip to content
Ameen Abozaid
Planned lessonJNR-056-L06

Keys, configuration, and testing with a fake model

  • Lesson 6 of 7
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

keep secrets safe and tests deterministic.

Planned topics

  • API keys come from environment variables, never from application.yml committed to Git.
  • Reference the key as ${AI_API_KEY} in configuration.
  • Define an interface (ProductDescriptionAssistant); the Spring AI class implements it.
  • In tests use a fake implementation that returns a fixed record. No network, no cost, same result every run.
  • Test the invalid-output path with a fake that returns bad data.
Draft outline details

Demonstration

java
interface ProductDescriptionAssistant { Description describe(ProductInfo info); }
class FakeAssistant implements ProductDescriptionAssistant {
    public Description describe(ProductInfo i) { return new Description("Test", "Fixed text"); }
}

Check your understanding

Why a fake in tests?

Show answer

Fast, free, offline, and deterministic.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.