SlideShare a Scribd company logo
1 of 14
Download to read offline
PRE TDD BOOT CAMP	   	     JAVA




TDD Boot Camp
Introduction




Overview




      1 / 14
PRE TDD BOOT CAMP	                  	               JAVA


Exercise 0: Interface design




      public abstract void convert(String text);
      public abstract String getFormatedText();


      public abstract String convert(String text);




package tddbootcamp.sapporo.wikiengine;

public interface WikiEngine {
  /**
   * Wiki                    html          .
     * @param text
     * @return         html
     * /
    String toHtml(String text);
}




      2 / 14
PRE TDD BOOT CAMP	                   	                  JAVA


Exercise 1: First Test (20 minutes)




1.




     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImplTest {
     }


2.



       @Test
       public void toHtml_HelloWorld() {
         WikiEngineImpl target = new WikiEngineImpl();
         String input = "Hello World";
         String expected = "Hello World";
         String actual = target.toHtml(input);
         assertThat(actual, is(expected));
       }




3.




      3 / 14
PRE TDD BOOT CAMP	                  	         JAVA




     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImpl {
       public String toHtml(String input) {
         return null;
       }
     }




4.



       public String toHtml(String input) {
         return "Hello World";
       }




      4 / 14
PRE TDD BOOT CAMP	                  	                   JAVA


Exercise 2: Second Test (15 minutes)




1.




       @Test
       public void toHtml_TDD_Bootcamp() {
         WikiEngineImpl target = new WikiEngineImpl();
         String input = "TDD Bootcamp";
         String expected = “TDD Bootcamp”;
         String actual = target.toHtml(input);
         assertThat(actual, is(expected));
       }




2.




       public String toHtml(String input) {
         return input;
       }




3.




      5 / 14
PRE TDD BOOT CAMP	                 	           JAVA




   public class WikiEngineImplTest {
     WikiEngineImpl target;
     @Before
     public void setUp() {
       target = new WikiEngineImpl();
     }
     @Test
     public void toHtml_HelloWorld() {
       String input = "Hello World";
       String expected = "Hello World";
       String actual = target.toHtml(input);
       assertThat(actual, is(expected));
     }
     @Test
     public void toHtml_TDD_Bootcamp() {
       String input = "TDD Bootcamp";
       String expected = "TDD Bootcamp";
       String actual = target.toHtml(input);
       assertThat(actual, is(expected));
     }
   }




     6 / 14
PRE TDD BOOT CAMP	                  	                            JAVA


Exercise 3: Interface Test (15 minutes)




1.




       @Test
       public void implements_WikiEngine() {
         assertThat(target, is(instanceOf(                 )));
       }




2.




     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImpl implements WikiEngine {
       @Override
       public String toHtml(String input) {
         return input;
       }
     }




      7 / 14
PRE TDD BOOT CAMP	                  	                       JAVA


Exercise 4: Null args test (15 minutes)




1.




       @Test(expected = IllegalArgumentException.class)
       public void toHtml_null() {
         target.toHtml(input);
       }




2.

     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImpl implements WikiEngine {
       @Override
       public String toHtml(String input) {
         if (input == null)
                 throw new IllegalArgumentException("input == null");
         return input;
       }
     }




      8 / 14
PRE TDD BOOT CAMP	                  	                       JAVA


Exercise 5: Heading (15 minutes)




1.

       @Test
       public void toHtml_Heading() {
         String input = "= Heading =";
         String expected = "<h1>Heading</h1>";
         String actual = target.toHtml(input);
         assertThat(actual, is(expected));
       }




2.



     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImpl implements WikiEngine {
       @Override
       public String toHtml(String input) {
         if (input == null)
                 throw new IllegalArgumentException("input == null");
         if (input.startsWith("= ") && input.endsWith(" =")) {
                 return "<h1>"
                    + input.substring(2, input.length() - 2) + "</h1>";
         }
         return input;
     }




      9 / 14
PRE TDD BOOT CAMP	                  	                       JAVA


Exercise 6: Subheading (15 minutes)




1.

       @Test
       public void toHtml_Heading2() {
         String input = "== Heading2 ==";
         String expected = "<h2>Heading2</h2>";
         String actual = target.toHtml(input);
         assertThat(actual, is(expected));
       }




2.



     package tddbootcamp.sapporo.wikiengine;
     public class WikiEngineImpl implements WikiEngine {
       @Override
       public String toHtml(String input) {
         if (input == null)
                 throw new IllegalArgumentException(“input == null”);
         if (input.startsWith("= ") && input.endsWith(" =")) {
           return "<h1>" + input.substring(2, input.length() - 2)
                         + "</h1>";
         } else if (input.startsWith("== ") && input.endsWith(" ==")) {
           return "<h2>" + input.substring(3, input.length() - 3)
                         + "</h2>";
         }
         return input;
       }
     }




      10 / 14
PRE TDD BOOT CAMP	                         	                            JAVA


Exercise 7: Refactering (20 minutes)




1.



            if (input.startsWith("= ") && input.endsWith(" =")) {
              return "<h1>" + input.substring(2, input.length() - 2)
                            + "</h1>";
            } else if (input.startsWith("== ") && input.endsWith(" ==")) {
              return "<h2>" + input.substring(3, input.length() - 3)
                            + "</h2>";
            }




2.

     public class WikiEngineImpl implements WikiEngine {
       static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$");
       @Override
       public String toHtml(String input) {
         if (input == null) throw new IllegalArgumentException("input == null");
         Matcher m = HEADER_PATTERN.matcher(input);
         if (m.find()) {
           String start = m.group(1);
           String end = m.group(2);
           if (start.length() == end.length()) {
             int level = start.length();
             String body = input.substring(level + 1, input.length() - level - 1);
             return "<h" + level + ">" + body + "</h" + level + ">";
           }
         }
         return input;
       }
     }




      11 / 14
PRE TDD BOOT CAMP	                       	             JAVA

3.


           @Test
           public void toHtml_Level3() {
               String input = "=== Level3 ===";
               String expected = "<h3>Level3</h3>";
               String actual = target.toHtml(input);
               assertThat(actual, is(expected));
           }




           @Test
           public void toHtml_Level4() {
               String input = "==== Level4 ====";
               String expected = "<h4>Level4</h4>";
               String actual = target.toHtml(input);
               assertThat(actual, is(expected));
           }




           @Test
           public void toHtml_Level5() {
               String input = "===== Level5 =====";
               String expected = "<h5>Level5</h5>";
               String actual = target.toHtml(input);
               assertThat(actual, is(expected));
           }




           @Test
           public void toHtml_Level6() {
               String input = "====== Level6 ======";
               String expected = "<h6>Level6</h6>";
               String actual = target.toHtml(input);
               assertThat(actual, is(expected));
           }




      12 / 14
PRE TDD BOOT CAMP	                          	                           JAVA


Exercise 8: Levl7 (10 minutes)




1.

          @Test
          public void toHtml_Level7_unsupport() {
              String input = "======= Level7 =======";
              String expected = "======= Level7 =======";
              String actual = target.toHtml(input);
              assertThat(actual, is(expected));
          }




2.


     public class WikiEngineImpl implements WikiEngine {
       static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$");
       @Override
       public String toHtml(String input) {
         if (input == null) throw new IllegalArgumentException("input == null");
         Matcher m = HEADER_PATTERN.matcher(input);
         if (m.find()) {
           String start = m.group(1);
           String end = m.group(2);
           if (start.length() < 7 && start.length() == end.length()) {
             int level = start.length();
             String body = input.substring(level + 1, input.length() - level - 1);
             return "<h" + level + ">" + body + "</h" + level + ">";
           }
         }
         return input;
       }
     }




      13 / 14
PRE TDD BOOT CAMP	                         	                            JAVA

3.


     public class WikiEngineImpl implements WikiEngine {
       static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$");
       static final int HEADER_MAX_LEVEL = 6;
       @Override
       public String toHtml(String input) {
         if (input == null) throw new IllegalArgumentException("input == null");
         Matcher m = HEADER_PATTERN.matcher(input);
         if (m.find()) {
           String start = m.group(1);
           String end = m.group(2);
           int level = start.length();
           if (level <= HEADER_MAX_LEVEL && level == end.length()) {
             String body = input.substring(level + 1, input.length() - level - 1);
             return "<h" + level + ">" + body + "</h" + level + ">";
           }
         }
         return input;
       }
     }




More Exercise:




Author:
  Shuji Watanabe (          Java                  shuji.w6e@gmail.com




      14 / 14

More Related Content

What's hot

What's hot (20)

Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Software transactional memory. pure functional approach
Software transactional memory. pure functional approachSoftware transactional memory. pure functional approach
Software transactional memory. pure functional approach
 
JVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's TricksJVM Mechanics: Understanding the JIT's Tricks
JVM Mechanics: Understanding the JIT's Tricks
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
 
Антон Бикинеев, Reflection in C++Next
Антон Бикинеев,  Reflection in C++NextАнтон Бикинеев,  Reflection in C++Next
Антон Бикинеев, Reflection in C++Next
 
Computer Programming- Lecture 4
Computer Programming- Lecture 4Computer Programming- Lecture 4
Computer Programming- Lecture 4
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
Thread
ThreadThread
Thread
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
C++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogrammingC++ How I learned to stop worrying and love metaprogramming
C++ How I learned to stop worrying and love metaprogramming
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code Better
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 

Viewers also liked (6)

Xp祭り関西2013
Xp祭り関西2013Xp祭り関西2013
Xp祭り関西2013
 
EC-CUBE + PHPUnit で 実践テスト駆動開発
EC-CUBE + PHPUnit で 実践テスト駆動開発EC-CUBE + PHPUnit で 実践テスト駆動開発
EC-CUBE + PHPUnit で 実践テスト駆動開発
 
私とTDDと研究と(TDDBC横浜LT)
私とTDDと研究と(TDDBC横浜LT)私とTDDと研究と(TDDBC横浜LT)
私とTDDと研究と(TDDBC横浜LT)
 
テストリストの見つけ方
テストリストの見つけ方テストリストの見つけ方
テストリストの見つけ方
 
JAWS-UG 青森 第0回勉強会 発表資料
JAWS-UG 青森 第0回勉強会 発表資料JAWS-UG 青森 第0回勉強会 発表資料
JAWS-UG 青森 第0回勉強会 発表資料
 
今日帰ってすぐに始められるChrome App #nds45
今日帰ってすぐに始められるChrome App #nds45今日帰ってすぐに始められるChrome App #nds45
今日帰ってすぐに始められるChrome App #nds45
 

Similar to TDD Hands-on

Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
arjuncorner565
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
Technopark
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing Tips
Shingo Furuyama
 

Similar to TDD Hands-on (20)

Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Awt
AwtAwt
Awt
 
applet.docx
applet.docxapplet.docx
applet.docx
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
What’s new in C# 6
What’s new in C# 6What’s new in C# 6
What’s new in C# 6
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Nice to meet Kotlin
Nice to meet KotlinNice to meet Kotlin
Nice to meet Kotlin
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
Apache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API BasicsApache Flink Training: DataSet API Basics
Apache Flink Training: DataSet API Basics
 
20070329 Java Programing Tips
20070329 Java Programing Tips20070329 Java Programing Tips
20070329 Java Programing Tips
 

More from Shuji Watanabe

Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Shuji Watanabe
 
クラスメソッド会社説明会in札幌 — メンバー紹介 #cmdevio
クラスメソッド会社説明会in札幌 — メンバー紹介   #cmdevioクラスメソッド会社説明会in札幌 — メンバー紹介   #cmdevio
クラスメソッド会社説明会in札幌 — メンバー紹介 #cmdevio
Shuji Watanabe
 

More from Shuji Watanabe (20)

Serverless - Developers.IO 2019
Serverless - Developers.IO 2019Serverless - Developers.IO 2019
Serverless - Developers.IO 2019
 
Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017Ansible ハンズオン on AWS - DevelopersIO 2017
Ansible ハンズオン on AWS - DevelopersIO 2017
 
SSMでマネージドEC2 #reinvent #cmdevio
SSMでマネージドEC2 #reinvent #cmdevioSSMでマネージドEC2 #reinvent #cmdevio
SSMでマネージドEC2 #reinvent #cmdevio
 
プロビジョニングの今 ーフルマネージド・サービスを目指してー #cmdevio2016 #E
プロビジョニングの今 ーフルマネージド・サービスを目指してー  #cmdevio2016 #Eプロビジョニングの今 ーフルマネージド・サービスを目指してー  #cmdevio2016 #E
プロビジョニングの今 ーフルマネージド・サービスを目指してー #cmdevio2016 #E
 
ELBの概要と勘所
ELBの概要と勘所ELBの概要と勘所
ELBの概要と勘所
 
AWSによるWebサイト構築と運用 - concrete5 編 -
AWSによるWebサイト構築と運用 - concrete5 編 -AWSによるWebサイト構築と運用 - concrete5 編 -
AWSによるWebサイト構築と運用 - concrete5 編 -
 
Cloud FormationによるBlue-Green Deployment - Dev io mtup11 003
Cloud FormationによるBlue-Green Deployment - Dev io mtup11 003Cloud FormationによるBlue-Green Deployment - Dev io mtup11 003
Cloud FormationによるBlue-Green Deployment - Dev io mtup11 003
 
CloudSearchによる全文検索 - CM:道 2014/08/01
CloudSearchによる全文検索 - CM:道 2014/08/01 CloudSearchによる全文検索 - CM:道 2014/08/01
CloudSearchによる全文検索 - CM:道 2014/08/01
 
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
Javaアプリケーション開発におけるユニットテストとTDDの実践 Java Day Tokyo 2014
 
TDD BootCamp in JJUG CCC - レガシーコード対策編 -
TDD BootCamp in JJUG CCC - レガシーコード対策編 -TDD BootCamp in JJUG CCC - レガシーコード対策編 -
TDD BootCamp in JJUG CCC - レガシーコード対策編 -
 
s3+cloud frontによる静的コンテンツ配信 - Sphinx編 #cmdevio
s3+cloud frontによる静的コンテンツ配信 - Sphinx編  #cmdevios3+cloud frontによる静的コンテンツ配信 - Sphinx編  #cmdevio
s3+cloud frontによる静的コンテンツ配信 - Sphinx編 #cmdevio
 
クラスメソッド会社説明会in札幌 — メンバー紹介 #cmdevio
クラスメソッド会社説明会in札幌 — メンバー紹介   #cmdevioクラスメソッド会社説明会in札幌 — メンバー紹介   #cmdevio
クラスメソッド会社説明会in札幌 — メンバー紹介 #cmdevio
 
テスト駆動開発へようこそ
テスト駆動開発へようこそテスト駆動開発へようこそ
テスト駆動開発へようこそ
 
テスト駆動開発のはじめ方
テスト駆動開発のはじめ方テスト駆動開発のはじめ方
テスト駆動開発のはじめ方
 
ユースケースからテスト駆動開発へ
ユースケースからテスト駆動開発へユースケースからテスト駆動開発へ
ユースケースからテスト駆動開発へ
 
テスト駆動開発入門
テスト駆動開発入門テスト駆動開発入門
テスト駆動開発入門
 
テストコードのリファクタリング
テストコードのリファクタリングテストコードのリファクタリング
テストコードのリファクタリング
 
テスト駆動開発の導入ーペアプログラミングの学習効果ー
テスト駆動開発の導入ーペアプログラミングの学習効果ーテスト駆動開発の導入ーペアプログラミングの学習効果ー
テスト駆動開発の導入ーペアプログラミングの学習効果ー
 
JUnit実践入門 xUnitTestPatternsで学ぶユニットテスト
JUnit実践入門 xUnitTestPatternsで学ぶユニットテストJUnit実践入門 xUnitTestPatternsで学ぶユニットテスト
JUnit実践入門 xUnitTestPatternsで学ぶユニットテスト
 
アジャイルテスティング
アジャイルテスティングアジャイルテスティング
アジャイルテスティング
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

TDD Hands-on

  • 1. PRE TDD BOOT CAMP JAVA TDD Boot Camp Introduction Overview 1 / 14
  • 2. PRE TDD BOOT CAMP JAVA Exercise 0: Interface design public abstract void convert(String text); public abstract String getFormatedText(); public abstract String convert(String text); package tddbootcamp.sapporo.wikiengine; public interface WikiEngine { /** * Wiki html . * @param text * @return html * / String toHtml(String text); } 2 / 14
  • 3. PRE TDD BOOT CAMP JAVA Exercise 1: First Test (20 minutes) 1. package tddbootcamp.sapporo.wikiengine; public class WikiEngineImplTest { } 2. @Test public void toHtml_HelloWorld() { WikiEngineImpl target = new WikiEngineImpl(); String input = "Hello World"; String expected = "Hello World"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 3. 3 / 14
  • 4. PRE TDD BOOT CAMP JAVA package tddbootcamp.sapporo.wikiengine; public class WikiEngineImpl { public String toHtml(String input) { return null; } } 4. public String toHtml(String input) { return "Hello World"; } 4 / 14
  • 5. PRE TDD BOOT CAMP JAVA Exercise 2: Second Test (15 minutes) 1. @Test public void toHtml_TDD_Bootcamp() { WikiEngineImpl target = new WikiEngineImpl(); String input = "TDD Bootcamp"; String expected = “TDD Bootcamp”; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 2. public String toHtml(String input) { return input; } 3. 5 / 14
  • 6. PRE TDD BOOT CAMP JAVA public class WikiEngineImplTest { WikiEngineImpl target; @Before public void setUp() { target = new WikiEngineImpl(); } @Test public void toHtml_HelloWorld() { String input = "Hello World"; String expected = "Hello World"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } @Test public void toHtml_TDD_Bootcamp() { String input = "TDD Bootcamp"; String expected = "TDD Bootcamp"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } } 6 / 14
  • 7. PRE TDD BOOT CAMP JAVA Exercise 3: Interface Test (15 minutes) 1. @Test public void implements_WikiEngine() { assertThat(target, is(instanceOf( ))); } 2. package tddbootcamp.sapporo.wikiengine; public class WikiEngineImpl implements WikiEngine { @Override public String toHtml(String input) { return input; } } 7 / 14
  • 8. PRE TDD BOOT CAMP JAVA Exercise 4: Null args test (15 minutes) 1. @Test(expected = IllegalArgumentException.class) public void toHtml_null() { target.toHtml(input); } 2. package tddbootcamp.sapporo.wikiengine; public class WikiEngineImpl implements WikiEngine { @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException("input == null"); return input; } } 8 / 14
  • 9. PRE TDD BOOT CAMP JAVA Exercise 5: Heading (15 minutes) 1. @Test public void toHtml_Heading() { String input = "= Heading ="; String expected = "<h1>Heading</h1>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 2. package tddbootcamp.sapporo.wikiengine; public class WikiEngineImpl implements WikiEngine { @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException("input == null"); if (input.startsWith("= ") && input.endsWith(" =")) { return "<h1>" + input.substring(2, input.length() - 2) + "</h1>"; } return input; } 9 / 14
  • 10. PRE TDD BOOT CAMP JAVA Exercise 6: Subheading (15 minutes) 1. @Test public void toHtml_Heading2() { String input = "== Heading2 =="; String expected = "<h2>Heading2</h2>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 2. package tddbootcamp.sapporo.wikiengine; public class WikiEngineImpl implements WikiEngine { @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException(“input == null”); if (input.startsWith("= ") && input.endsWith(" =")) { return "<h1>" + input.substring(2, input.length() - 2) + "</h1>"; } else if (input.startsWith("== ") && input.endsWith(" ==")) { return "<h2>" + input.substring(3, input.length() - 3) + "</h2>"; } return input; } } 10 / 14
  • 11. PRE TDD BOOT CAMP JAVA Exercise 7: Refactering (20 minutes) 1. if (input.startsWith("= ") && input.endsWith(" =")) { return "<h1>" + input.substring(2, input.length() - 2) + "</h1>"; } else if (input.startsWith("== ") && input.endsWith(" ==")) { return "<h2>" + input.substring(3, input.length() - 3) + "</h2>"; } 2. public class WikiEngineImpl implements WikiEngine { static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$"); @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException("input == null"); Matcher m = HEADER_PATTERN.matcher(input); if (m.find()) { String start = m.group(1); String end = m.group(2); if (start.length() == end.length()) { int level = start.length(); String body = input.substring(level + 1, input.length() - level - 1); return "<h" + level + ">" + body + "</h" + level + ">"; } } return input; } } 11 / 14
  • 12. PRE TDD BOOT CAMP JAVA 3. @Test public void toHtml_Level3() { String input = "=== Level3 ==="; String expected = "<h3>Level3</h3>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } @Test public void toHtml_Level4() { String input = "==== Level4 ===="; String expected = "<h4>Level4</h4>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } @Test public void toHtml_Level5() { String input = "===== Level5 ====="; String expected = "<h5>Level5</h5>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } @Test public void toHtml_Level6() { String input = "====== Level6 ======"; String expected = "<h6>Level6</h6>"; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 12 / 14
  • 13. PRE TDD BOOT CAMP JAVA Exercise 8: Levl7 (10 minutes) 1. @Test public void toHtml_Level7_unsupport() { String input = "======= Level7 ======="; String expected = "======= Level7 ======="; String actual = target.toHtml(input); assertThat(actual, is(expected)); } 2. public class WikiEngineImpl implements WikiEngine { static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$"); @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException("input == null"); Matcher m = HEADER_PATTERN.matcher(input); if (m.find()) { String start = m.group(1); String end = m.group(2); if (start.length() < 7 && start.length() == end.length()) { int level = start.length(); String body = input.substring(level + 1, input.length() - level - 1); return "<h" + level + ">" + body + "</h" + level + ">"; } } return input; } } 13 / 14
  • 14. PRE TDD BOOT CAMP JAVA 3. public class WikiEngineImpl implements WikiEngine { static final Pattern HEADER_PATTERN = Pattern.compile("^(=+) .* (=+)$"); static final int HEADER_MAX_LEVEL = 6; @Override public String toHtml(String input) { if (input == null) throw new IllegalArgumentException("input == null"); Matcher m = HEADER_PATTERN.matcher(input); if (m.find()) { String start = m.group(1); String end = m.group(2); int level = start.length(); if (level <= HEADER_MAX_LEVEL && level == end.length()) { String body = input.substring(level + 1, input.length() - level - 1); return "<h" + level + ">" + body + "</h" + level + ">"; } } return input; } } More Exercise: Author: Shuji Watanabe ( Java shuji.w6e@gmail.com 14 / 14