---
title: Morning Routine
description: Learn how to work with test doubles, and to understand the concept of mock it if you own it
---

[Katas ](https://www.codurance.com/katas)

# [Morning Routine](https://www.codurance.com/katas/morning-routine-kata)

 Written by [Emmanuel Valverde](https://www.codurance.com/katas/author/emmanuel-valverde) | Mar 5, 2024 12:05:53 PM

As a forgetful person, I need to remember my morning routine. Because of this, I have created a program that, depending on the time of day, will tell me what I should be doing:

`From 06:00 to 06:59 - Do exercise`  
`From 07:00 to 07:59 - Read and study`  
`From 08:00 to 08:59 - Have breakfast`

# Introduction

This kata could be done with two approaches:

- From scratch
- Refactoring the provided implementation

# Approach from scratch

# Story: Morning Routine Reminder

## User Story:

## `As a forgetful person,` `I want a program that reminds me of my morning routine,` `So that I can stay on track with my activities.` Scenario 1: Display "Do exercise" between 06:00 and 06:59

## `Given the current time is between 06:00 and 06:59` `When I request the routine activity` `Then the system should display "Do exercise"` Scenario 2: Display "Read and study" between 07:00 and 07:59

## `Given the current time is between 07:00 and 07:59` `When I request the routine activity` `Then the system should display "Read and study"` Scenario 3: Display "Have breakfast" between 08:00 and 08:59

## `Given the current time is between 08:00 and 08:59` `When I request the routine activity` `Then the system should display "Have breakfast"` Scenario 4: Display "No activity" outside the defined time range

`Given the current time is before 05:59 or after 09:00`  
`When I request the routine activity`  
`Then the system should display "No activity"`

## Iteration 2 - More precise time

Now I'd like to be able to add things to do, that take less than an Hour as well as update the list of things to do for example:

`From 06:00 to 06:59 - Do exercise`  
`From 07:00 to 07:29 - Read`  
`From 07:30 to 07:59 - Study`  
`From 08:00 to 08:59 - Have breakfast`  
`From 06:00 to 06:44 - Do exercise`  
`From 06:45 to 06:59 - Take a shower`  
`From 07:00 to 07:29 - Read`  
`From 07:30 to 07:59 - Study`  
`From 08:00 to 09:00 - Have breakfast`

## Possible interface to use

## `interface MorningRoutine {` `    String whatShouldIDoNow();` `}` `interface MorningRoutine {` `    void whatShouldIDoNow();` `}`

# Approach refactoring

## Smelly implementation for iteration 1 in Java

interface MorningRoutine {  
    void whatShouldIDoNow();  
}

`public class MyMorningRouting implements MorningRoutine {`  
`    public void whatShouldIDoNow() {`  
`        LocalDateTime now = LocalDateTime.now();`  
`        int currentHour = now.getHour();`  
`        if (currentHour == 6) {`  
`            System.out.println("Do exercise");`  
`        } else if (currentHour == 7) {`  
`            System.out.println("Read and study");`  
`        } else if (currentHour == 8) {`  
`            System.out.println("Have breakfast");`  
`        } else {`  
`            System.out.println("No activity");`  
`        }`  
`    }`  
`}`

# To think further...

- Would your software work in a different time zone?
- Is it easy to add new activity to the existing schedule with your current design?
- Does your implementation allow you to add longer or shorter activities?

 

[View full post](https://www.codurance.com/katas/morning-routine-kata)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Emmanuel Valverde"
  },
  "dateModified" : "2024-03-05T12:05:53.167Z",
  "datePublished" : "2024-03-05T12:05:53Z",
  "headline" : "Morning Routine",
  "image" : {
    "@type" : "ImageObject",
    "height" : 630,
    "url" : "https://3042464.fs1.hubspotusercontent-na1.net/hubfs/3042464/Katalyst/Thumbnails/Katalyst_Thumbnail%20%E2%80%93%20Stack.jpg",
    "width" : 1200
  },
  "mainEntityOfPage" : "https://www.codurance.com/katas/morning-routine-kata",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Katas"
  }
}
```