Skip to content

Web Adapter

Pull from Latest

Make sure you pull the latest code from the repository (you can also re-clone the project, if you prefer). The Spring framework was added to the project, so you will need to make sure you can get its dependencies from the internet. You may need to explicitly force IntelliJ IDEA to reload/reimport the Maven pom.xml file. See the docs for more information: https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#maven_reimport

Goal

In this lab, we'll finish the web adapter to handle the player's "Stand" command.

Predictive TDD

Review the predictive TDD cycle from here, which starts on slide 5.

A. Write an Adapter Test

All Tests Pass

Make sure that all tests are passing before starting on this lab.

In the WebConfigurationTest class, write a minimal test to check that a POST request sent to the "/stand" endpoint redirects (doesn't matter where, we check that later). It should fail.

Write the minimal code in the controller class to make the test pass. Note that you're just implementing "framework" code, i.e., the @PostMapping annotation and returning the appropriate "redirect" string.

Run Tests

Ensure that all tests pass before continuing.

B. Handle the Stand Command

Write two tests in the BlackjackControllerTest class:

  1. A test that checks that redirect goes to /done and the Game "player is done" state is true.

  2. Another test that does a "deeper" test for when the player stands by using StubDeck where the player loses to the dealer:

    Deck dealerBeatsPlayerAfterDrawingAdditionalCardDeck =
        new StubDeck(Rank.TEN,   Rank.QUEEN,
                     Rank.NINE,  Rank.FIVE,
                                 Rank.SIX);   
    

For each test, write the minimal code in the controller class to make the test pass. Note that you'll be implementing calls to the Game domain class here.

Run Tests

Ensure that all tests pass before continuing.

C. Try It Out!

Start the application via the BlackjackGameApplication class and point your browser to http://localhost:8080/ and play the game.

D. Refactor

Review the code in the BlackjackController. Think about any opportunities for refactoring. Look for duplication or similarities in the various controller methods.

E. Transformation of GameOutcome (optional)

If you have time, improve the transformation of the GameOutcome enum to a String by creating a DTO for the outcome.


You are done!