├── .gitignore ├── README.md ├── license.txt ├── pom.xml ├── src ├── main │ └── java │ │ └── com │ │ └── in28minutes │ │ └── tdd │ │ └── StringHelper.java └── test │ └── java │ └── com │ └── in28minutes │ └── tdd │ └── StringHelperTest.java └── start.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | *.cmd 21 | *.classpath 22 | *.settings 23 | *.project 24 | *.mvn 25 | mvnw 26 | target 27 | *.DS_Store 28 | 29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 30 | hs_err_pid* 31 | bin 32 | .settings 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TDDin28Minutes 2 | Learn TDD from in28Minutes. Test Driven Development for Beginners 3 | 4 | ## Video Tutorial 5 | https://www.youtube.com/watch?v=QXo8bCv1BiQ 6 | 7 | ## Section 1 What is TDD 8 | What is TDD? 9 | 10 | ## Section 2 Basics of TDD 11 | 12 | ### Three Steps in TDD 13 | - RED 14 | - GREEN 15 | - REFACTOR 16 | 17 | ### Three Laws of TDD 18 | - New Code only on Red bar 19 | - Simplest code to make test fail 20 | - Simplest code to make test succeed 21 | 22 | ## Section 3  Playing with TDD 23 | - Example 1 24 | - Example 2 25 | 26 | ## Section 4  Continuing with TDD 27 | - A Quick Revision 28 | - Have Patience 29 | - Get a Mentor 30 | - Practice 31 | - Have Fun 32 | 33 | ## About in28Minutes 34 | 35 | At in28Minutes, we ask ourselves one question everyday 36 | > How do we create more amazing course experiences? 37 | > We use 80-20 Rule. We discuss 20% things used 80% of time in depth. 38 | 39 | We are creating amazing learning experiences for learning Spring Boot with AWS, Azure, GCP, Docker, Kubernetes and Full Stack. 300,000 Learners rely on our expertise. [Find out more.... ](https://github.com/in28minutes/learn#best-selling-courses) 40 | 41 | ![in28MinutesLearningRoadmap-July2019.png](https://github.com/in28minutes/in28Minutes-Course-Roadmap/raw/master/in28MinutesLearningRoadmap-July2019.png) 42 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 In28Minutes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | com.in28minutes.maven 7 | tdd-example 8 | 1.0-SNAPSHOT 9 | 10 | jar 11 | 12 | tdd-example-1 13 | http://www.in28minutes.com 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.12 20 | test 21 | 22 | 23 | 24 | 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-compiler-plugin 29 | 3.2 30 | 31 | true 32 | 1.8 33 | 1.8 34 | true 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/com/in28minutes/tdd/StringHelper.java: -------------------------------------------------------------------------------- 1 | package com.in28minutes.tdd; 2 | 3 | public class StringHelper { 4 | 5 | // ABCD,BCD 6 | public String truncateAInFirst2Positions(String input) { 7 | if (input.length() < 2) 8 | return input.replace("A", ""); 9 | String first2Chars = input.substring(0, 2); 10 | String restOfTheString = input.substring(2); 11 | return first2Chars.replaceAll("A", "").concat(restOfTheString); 12 | } 13 | 14 | public boolean areFirstAndLastTwoCharsTheSame(String input) { 15 | 16 | if (input.length() < 2) 17 | return false; 18 | 19 | String first2Chars = input.substring(0,2); 20 | String last2Chars = input.substring(input.length()-2); 21 | 22 | return first2Chars.equals(last2Chars); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/in28minutes/tdd/StringHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.in28minutes.tdd; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | public class StringHelperTest { 8 | 9 | StringHelper stringHelper = new StringHelper(); 10 | 11 | // ""=>false, 12 | 13 | @Test 14 | public void testAreFirstAndLastTwoCharsTheSame_EmptyCondition() { 15 | assertFalse(stringHelper.areFirstAndLastTwoCharsTheSame("")); 16 | } 17 | 18 | @Test 19 | public void testAreFirstAndLastTwoCharsTheSame_StringWith1Char() { 20 | assertFalse(stringHelper.areFirstAndLastTwoCharsTheSame("A")); 21 | } 22 | 23 | @Test 24 | public void testAreFirstAndLastTwoCharsTheSame_TwoChars() { 25 | assertTrue(stringHelper.areFirstAndLastTwoCharsTheSame("AB")); 26 | } 27 | 28 | // "A"=>false,"AB"=>true,"ABC"=>false,"AAA"=>true,"ABCAB"=>true, 29 | // "ABCDEBA"=>false 30 | @Test 31 | public void testAreFirstAndLastTwoCharsTheSame_ThreeChars() { 32 | assertEquals(false, stringHelper.areFirstAndLastTwoCharsTheSame("ABC")); 33 | assertEquals(true, stringHelper.areFirstAndLastTwoCharsTheSame("AAA")); 34 | assertEquals(true, stringHelper.areFirstAndLastTwoCharsTheSame("ABCAB")); 35 | assertEquals(false, 36 | stringHelper.areFirstAndLastTwoCharsTheSame("ABCDEBA")); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /start.txt: -------------------------------------------------------------------------------- 1 | Truncate A in first 2 positions of a String 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | "ABCD" => "BCD", "AACD"=> "CD", 4 | "BACD"=>"BCD", "AAAA" => "AA", "MNAA"=>"MNAA" 5 | 6 | Check if first two and last two characters in the string are the same. 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | Hint : substring method. 9 | 10 | ""=>false, 11 | "A"=>false,"AB"=>true,"ABC"=>false,"AAA"=>true,"ABCAB"=>true, 12 | "ABCDEBA"=>false 13 | --------------------------------------------------------------------------------