├── README.asciidoc ├── build.gradle ├── chp_03_fahrenheit └── src │ ├── main │ └── java │ │ └── com │ │ └── practicalunittesting │ │ └── FahrenheitCelciusConverter.java │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── FahrenheitCelciusConverterTest.java ├── chp_03_string_reversal └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ └── StringUtils.java ├── chp_05_race_results └── src │ ├── main │ └── java │ │ └── com │ │ └── practicalunittesting │ │ ├── Client.java │ │ ├── Message.java │ │ └── RaceResultsService.java │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── RaceResultsServiceTest.java ├── chp_05_user_service └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ ├── SecurityService.java │ ├── User.java │ ├── UserDAO.java │ └── UserServiceImpl.java ├── chp_06_custom_matcher └── src │ ├── main │ └── java │ │ └── com │ │ └── practicalunittesting │ │ └── OperatingSystem.java │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── OperatingSystemTest.java ├── chp_06_id_generator └── src │ ├── main │ └── java │ │ └── com │ │ └── practicalunittesting │ │ ├── AtomicIdGenerator.java │ │ └── IdGenerator.java │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── parallel │ └── JVMUniqueIdGeneratorParallelTest.java ├── chp_06_test_collections └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ ├── User.java │ └── UserList.java ├── chp_06_time_testing └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ ├── HelpDesk.java │ ├── Issue.java │ └── ItIsWeekendException.java ├── chp_07_legacy_code └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ ├── Email.java │ ├── EmailServer.java │ └── MailClient.java ├── chp_08_csv_reporter_log └── data.csv ├── chp_08_custom_test_listener └── src │ └── test │ └── java │ └── com │ └── practicalunittesting │ ├── FirstTest.java │ ├── SecondTest.java │ └── utils │ └── TestListenerUtils.java ├── chp_09_test_data_builder └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ └── Transaction.java ├── chp_09_test_fixture └── src │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── TestFixtureTest.java ├── chp_10_sports_car └── src │ └── main │ └── java │ └── com │ └── practicalunittesting │ ├── Car.java │ ├── CarImpl.java │ ├── CarSearch.java │ ├── Engine.java │ └── Manufacturer.java ├── chp_11_clean_this_mess └── src │ ├── main │ └── java │ │ └── com │ │ └── practicalunittesting │ │ ├── Fridge.java │ │ └── NoSuchItemException.java │ └── test │ └── java │ └── com │ └── practicalunittesting │ └── FoodTesting.java ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /README.asciidoc: -------------------------------------------------------------------------------- 1 | == Basic Info 2 | This project contains all the source code of exercises for "Practical Unit Testing with TestNG and Mockito". 3 | 4 | See the book's website: http://practicalunittesting.com 5 | 6 | == Import project to your IDE 7 | 8 | === Eclipse 9 | First you need to generate Eclipse project files. If you have Gradle installed then type 10 | 11 | ---- 12 | gradle eclipse 13 | ---- 14 | 15 | In other cases (this will take some time - first Gradle will be downloaded): 16 | 17 | ---- 18 | ./gradlew eclipse 19 | ---- 20 | 21 | After this you can import this project to Eclipse as any other project (File / Import / General / Existing Project into Workspace). As far as I know (not being an Eclipse guru!) you need to import each project individually. 22 | 23 | === IntelliJ IDEA 24 | You can import files by choosing: 25 | 26 | * File / New Project / Import project from external module 27 | * select Gradle 28 | * and then select +build.gradle+ file 29 | 30 | == Content 31 | For your convenience all exercises are kept in separate dirs with names like "chp_X_exercise_name" where X is the chapter number: 32 | 33 | * Chapter 3 "Unit Tests with no Collaborators" 34 | * Chapter 4 "Test Driven Development" 35 | * Chapter 5 "Mocks, Stubs, Test Spies" 36 | * Chapter 6 "Things You Should Know" 37 | * Chapter 7 "Points of Controversy" 38 | * Chapter 8 "Getting Feedback" 39 | * Chapter 9 "Organization of Tests" 40 | * Chapter 10 "Maintainable Tests" 41 | * Chapter 11 "Test Quality" -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'idea' 2 | apply plugin: 'eclipse' 3 | 4 | subprojects { 5 | apply plugin: 'java'; 6 | apply plugin: 'eclipse' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | testCompile 'org.testng:testng:6.3.1' 14 | testCompile 'org.mockito:mockito-all:1.9.0' 15 | testCompile 'org.easytesting:fest-assert:1.4' 16 | testCompile 'org.hamcrest:hamcrest-all:1.1' 17 | } 18 | 19 | test { 20 | useTestNG() 21 | } 22 | } 23 | 24 | task wrapper(type: Wrapper) { 25 | gradleVersion = '1.0-milestone-8' 26 | } 27 | 28 | project(':chp_08_custom_test_listener') { 29 | dependencies { 30 | compile 'org.testng:testng:6.3.1' 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /chp_03_fahrenheit/src/main/java/com/practicalunittesting/FahrenheitCelciusConverter.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class FahrenheitCelciusConverter { 10 | 11 | public static int toCelcius(int fahrenheit) { 12 | return (fahrenheit - 32) * 5/9; 13 | } 14 | 15 | public static int toFahrenheit(int celcius) { 16 | return celcius * 9/5 + 32; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /chp_03_fahrenheit/src/test/java/com/practicalunittesting/FahrenheitCelciusConverterTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static org.testng.Assert.assertEquals; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | @Test 14 | public class FahrenheitCelciusConverterTest { 15 | 16 | public void shouldConvertCelciusToFahrenheit() { 17 | assertEquals(FahrenheitCelciusConverter.toFahrenheit(0), 32); 18 | assertEquals(FahrenheitCelciusConverter.toFahrenheit(37), 98); 19 | assertEquals(FahrenheitCelciusConverter.toFahrenheit(100), 212); 20 | } 21 | 22 | public void shouldConvertFahrenheitToCelcius() { 23 | assertEquals(FahrenheitCelciusConverter.toCelcius(32), 0); 24 | assertEquals(FahrenheitCelciusConverter.toCelcius(100), 37); 25 | assertEquals(FahrenheitCelciusConverter.toCelcius(212), 100); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /chp_03_string_reversal/src/main/java/com/practicalunittesting/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 8 | * Visit http://practicalunittesting.com for more information. 9 | * 10 | * @author Tomek Kaczanowski 11 | */ 12 | public class StringUtils { 13 | 14 | public static String reverse(String s) { 15 | List tempArray = new ArrayList(s.length()); 16 | for (int i = 0; i < s.length(); i++) { 17 | tempArray.add(s.substring(i, i+1)); 18 | } 19 | StringBuilder reversedString = new StringBuilder(s.length()); 20 | for (int i = tempArray.size() -1; i >= 0; i--) { 21 | reversedString.append(tempArray.get(i)); 22 | } 23 | return reversedString.toString(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chp_05_race_results/src/main/java/com/practicalunittesting/Client.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface Client { 10 | void receive(Message message); 11 | } 12 | -------------------------------------------------------------------------------- /chp_05_race_results/src/main/java/com/practicalunittesting/Message.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface Message { 10 | } 11 | -------------------------------------------------------------------------------- /chp_05_race_results/src/main/java/com/practicalunittesting/RaceResultsService.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | 6 | /** 7 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 8 | * Visit http://practicalunittesting.com for more information. 9 | * 10 | * @author Tomek Kaczanowski 11 | */ 12 | public class RaceResultsService { 13 | 14 | private Collection clients = new HashSet(); 15 | 16 | public void addSubscriber(Client client) { 17 | clients.add(client); 18 | } 19 | 20 | public void send(Message message) { 21 | for (Client client : clients) { 22 | client.receive(message); 23 | } 24 | } 25 | 26 | public void removeSubscriber(Client client) { 27 | clients.remove(client); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chp_05_race_results/src/test/java/com/practicalunittesting/RaceResultsServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.BeforeMethod; 4 | import org.testng.annotations.Test; 5 | 6 | import static org.mockito.Mockito.*; 7 | 8 | /** 9 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 10 | * Visit http://practicalunittesting.com for more information. 11 | * 12 | * @author Tomek Kaczanowski 13 | */ 14 | @Test 15 | public class RaceResultsServiceTest { 16 | 17 | private RaceResultsService raceResults; 18 | private Client clientA, clientB; 19 | private Message message; 20 | 21 | @BeforeMethod 22 | public void setUp() { 23 | raceResults = new RaceResultsService(); 24 | clientA = mock(Client.class); 25 | clientB = mock(Client.class); 26 | message = mock(Message.class); 27 | } 28 | 29 | public void notSubscribedClientShouldNotReceiveMessage() { 30 | raceResults.send(message); 31 | verify(clientA, never()).receive(message); 32 | // verify(clientA).receive(message); 33 | verify(clientB, never()).receive(message); 34 | } 35 | 36 | public void subscribedClientShouldReceiveMessage() { 37 | raceResults.send(message); 38 | verify(clientA, never()).receive(message); 39 | verify(clientB, never()).receive(message); 40 | 41 | raceResults.addSubscriber(clientA); 42 | raceResults.send(message); 43 | verify(clientA).receive(message); 44 | } 45 | 46 | public void allSubscribedClientsShouldReceiveMessages() { 47 | raceResults.addSubscriber(clientA); 48 | raceResults.addSubscriber(clientB); 49 | raceResults.send(message); 50 | verify(clientA).receive(message); 51 | verify(clientB).receive(message); 52 | } 53 | 54 | public void shouldSendOnlyOneMassageToMultiSubscriber() { 55 | raceResults.addSubscriber(clientA); 56 | raceResults.addSubscriber(clientA); 57 | raceResults.send(message); 58 | //verify(clientA, times(1)).receive(message); // same as below - times(1) is the default 59 | verify(clientA).receive(message); 60 | } 61 | 62 | public void unsubscribedClientShouldNotReceiveMessages() { 63 | raceResults.addSubscriber(clientA); 64 | raceResults.removeSubscriber(clientA); 65 | raceResults.send(message); 66 | verify(clientA, never()).receive(message); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /chp_05_user_service/src/main/java/com/practicalunittesting/SecurityService.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface SecurityService { 10 | String md5(String password); 11 | } 12 | -------------------------------------------------------------------------------- /chp_05_user_service/src/main/java/com/practicalunittesting/User.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface User { 10 | String getPassword(); 11 | 12 | void setPassword(String passwordMd5); 13 | } 14 | -------------------------------------------------------------------------------- /chp_05_user_service/src/main/java/com/practicalunittesting/UserDAO.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface UserDAO { 10 | void updateUser(User user); 11 | } 12 | -------------------------------------------------------------------------------- /chp_05_user_service/src/main/java/com/practicalunittesting/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class UserServiceImpl { 10 | 11 | private UserDAO userDAO; 12 | private SecurityService securityService; 13 | 14 | public void assignPassword(User user) throws Exception { 15 | String passwordMd5 = securityService.md5(user.getPassword()); 16 | user.setPassword(passwordMd5); 17 | userDAO.updateUser(user); 18 | } 19 | 20 | public UserServiceImpl(UserDAO dao, SecurityService security) { 21 | this.userDAO = dao; 22 | this.securityService = security; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chp_06_custom_matcher/src/main/java/com/practicalunittesting/OperatingSystem.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class OperatingSystem { 10 | 11 | private int nbOfBits; 12 | 13 | private String name; 14 | 15 | private String version; 16 | 17 | private int releaseYear; 18 | 19 | public int getNbOfBits() { 20 | return nbOfBits; 21 | } 22 | 23 | public void setNbOfBits(int nbOfBits) { 24 | this.nbOfBits = nbOfBits; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getVersion() { 36 | return version; 37 | } 38 | 39 | public void setVersion(String version) { 40 | this.version = version; 41 | } 42 | 43 | public int getReleaseYear() { 44 | return releaseYear; 45 | } 46 | 47 | public void setReleaseYear(int releaseYear) { 48 | this.releaseYear = releaseYear; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /chp_06_custom_matcher/src/test/java/com/practicalunittesting/OperatingSystemTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | /** 6 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 7 | * Visit http://practicalunittesting.com for more information. 8 | * 9 | * @author Tomek Kaczanowski 10 | */ 11 | @Test 12 | public class OperatingSystemTest { 13 | 14 | private OperatingSystem os; 15 | 16 | public void testUsingMatcher() { 17 | os = new OperatingSystem(); 18 | os.setNbOfBits(64); 19 | os.setReleaseYear(2007); 20 | 21 | //TODO this is what we would like to have 22 | //assertThat(os).is64bit().wasReleasedIn(2003); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chp_06_id_generator/src/main/java/com/practicalunittesting/AtomicIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class AtomicIdGenerator implements IdGenerator { 10 | 11 | private static Long nextId = System.currentTimeMillis(); 12 | 13 | public Long nextId() { 14 | return nextId++; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /chp_06_id_generator/src/main/java/com/practicalunittesting/IdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface IdGenerator { 10 | 11 | /** 12 | * @return unique id 13 | */ 14 | Long nextId(); 15 | } -------------------------------------------------------------------------------- /chp_06_id_generator/src/test/java/com/practicalunittesting/parallel/JVMUniqueIdGeneratorParallelTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting.parallel; 2 | 3 | import com.practicalunittesting.AtomicIdGenerator; 4 | import com.practicalunittesting.IdGenerator; 5 | import org.testng.annotations.Test; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | import static org.testng.Assert.assertTrue; 11 | 12 | /** 13 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 14 | * Visit http://practicalunittesting.com for more information. 15 | * 16 | * @author Tomek Kaczanowski 17 | */ 18 | @Test 19 | public class JVMUniqueIdGeneratorParallelTest { 20 | 21 | private IdGenerator idGen = new AtomicIdGenerator(); 22 | 23 | private Set ids = new HashSet(100); 24 | 25 | @Test(threadPoolSize = 7, invocationCount = 100) 26 | public void idsShouldBeUnique() { 27 | assertTrue(ids.add(idGen.nextId())); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chp_06_test_collections/src/main/java/com/practicalunittesting/User.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class User { 10 | } 11 | -------------------------------------------------------------------------------- /chp_06_test_collections/src/main/java/com/practicalunittesting/UserList.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 8 | * Visit http://practicalunittesting.com for more information. 9 | * 10 | * @author Tomek Kaczanowski 11 | */ 12 | public class UserList { 13 | 14 | private List users = new ArrayList(); 15 | 16 | public List getUsers() { 17 | return users; 18 | } 19 | 20 | public void addUser(User user) { 21 | users.add(user); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chp_06_time_testing/src/main/java/com/practicalunittesting/HelpDesk.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.util.Calendar; 4 | 5 | /** 6 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 7 | * Visit http://practicalunittesting.com for more information. 8 | * 9 | * @author Tomek Kaczanowski 10 | */ 11 | public class HelpDesk { 12 | 13 | public final static int EOB_HOUR = 17; 14 | 15 | public boolean willHandleIssue(Issue issue) { 16 | Calendar cal = Calendar.getInstance(); 17 | int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); 18 | if (Calendar.SUNDAY == dayOfWeek || Calendar.SATURDAY == dayOfWeek) { 19 | return false; 20 | } 21 | if (Calendar.FRIDAY == dayOfWeek) { 22 | int hour = cal.get(Calendar.HOUR_OF_DAY); 23 | if (hour > EOB_HOUR) { 24 | return false; 25 | } 26 | } 27 | return true; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chp_06_time_testing/src/main/java/com/practicalunittesting/Issue.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface Issue { 10 | } 11 | -------------------------------------------------------------------------------- /chp_06_time_testing/src/main/java/com/practicalunittesting/ItIsWeekendException.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class ItIsWeekendException extends Throwable { 10 | public ItIsWeekendException(String s) { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /chp_07_legacy_code/src/main/java/com/practicalunittesting/Email.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class Email { 10 | public Email(String address, String title, String body) { 11 | //To change body of created methods use File | Settings | File Templates. 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chp_07_legacy_code/src/main/java/com/practicalunittesting/EmailServer.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class EmailServer { 10 | 11 | public static void sendEmail(Email email) { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chp_07_legacy_code/src/main/java/com/practicalunittesting/MailClient.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class MailClient { 10 | 11 | public void sendEmail(String address, String title, String body) { 12 | Email email = new Email(address, title, body); 13 | EmailServer.sendEmail(email); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /chp_08_csv_reporter_log/data.csv: -------------------------------------------------------------------------------- 1 | name,surname,age 2 | John,Doe,32 3 | Jane,Doe,32 4 | Joe,Bloggs,43 5 | John,Smith,16 6 | Joe,Public,80 7 | Joe,Shmoe,58 8 | -------------------------------------------------------------------------------- /chp_08_custom_test_listener/src/test/java/com/practicalunittesting/FirstTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static com.practicalunittesting.utils.TestListenerUtils.waitAndFailOrPass; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | @Test 14 | public class FirstTest { 15 | 16 | 17 | public void firstTestMethod() throws InterruptedException { 18 | waitAndFailOrPass(); 19 | } 20 | 21 | public void secondTestMethod() throws InterruptedException { 22 | waitAndFailOrPass(); 23 | } 24 | 25 | public void thirdTestMethod() throws InterruptedException { 26 | waitAndFailOrPass(); 27 | } 28 | 29 | public void fourthTestMethod() throws InterruptedException { 30 | waitAndFailOrPass(); 31 | } 32 | 33 | public void fifthTestMethod() throws InterruptedException { 34 | waitAndFailOrPass(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chp_08_custom_test_listener/src/test/java/com/practicalunittesting/SecondTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static com.practicalunittesting.utils.TestListenerUtils.waitAndFailOrPass; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | @Test 14 | public class SecondTest { 15 | 16 | 17 | public void methodA() throws InterruptedException { 18 | waitAndFailOrPass(); 19 | } 20 | 21 | public void methodB() throws InterruptedException { 22 | waitAndFailOrPass(); 23 | } 24 | 25 | public void methodC() throws InterruptedException { 26 | waitAndFailOrPass(); 27 | } 28 | 29 | public void methodD() throws InterruptedException { 30 | waitAndFailOrPass(); 31 | } 32 | 33 | public void methodE() throws InterruptedException { 34 | waitAndFailOrPass(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chp_08_custom_test_listener/src/test/java/com/practicalunittesting/utils/TestListenerUtils.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting.utils; 2 | 3 | import org.testng.ITestResult; 4 | 5 | import static org.testng.Assert.fail; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | public class TestListenerUtils { 14 | 15 | public static void waitAndFailOrPass() throws InterruptedException { 16 | Thread.sleep((long) (Math.random() * 5000)); 17 | if (Math.random() > 0.8) { 18 | fail(); 19 | } 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /chp_09_test_data_builder/src/main/java/com/practicalunittesting/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class Transaction { 10 | 11 | private long id; 12 | 13 | private String state; 14 | 15 | private boolean retryAllowed; 16 | 17 | private String message; 18 | 19 | private String billingId; 20 | 21 | public long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getState() { 30 | return state; 31 | } 32 | 33 | public void setState(String state) { 34 | this.state = state; 35 | } 36 | 37 | public String getMessage() { 38 | return message; 39 | } 40 | 41 | public void setMessage(String message) { 42 | this.message = message; 43 | } 44 | 45 | public String getBillingId() { 46 | return billingId; 47 | } 48 | 49 | public void setBillingId(String billingId) { 50 | this.billingId = billingId; 51 | } 52 | 53 | public boolean isRetryAllowed() { 54 | return retryAllowed; 55 | } 56 | 57 | public void setRetryAllowed(boolean retryAllowed) { 58 | this.retryAllowed = retryAllowed; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /chp_09_test_fixture/src/test/java/com/practicalunittesting/TestFixtureTest.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static org.testng.Assert.*; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | @Test 14 | public class TestFixtureTest { 15 | 16 | public void testMethodA() { 17 | System.out.println("method A"); 18 | } 19 | 20 | public void testMethodB() { 21 | System.out.println("method B"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chp_10_sports_car/src/main/java/com/practicalunittesting/Car.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 7 | * Visit http://practicalunittesting.com for more information. 8 | * 9 | * @author Tomek Kaczanowski 10 | */ 11 | public interface Car { 12 | 13 | Engine getEngine(); 14 | 15 | Color getColor(); 16 | 17 | Manufacturer getManufacturer(); 18 | } 19 | -------------------------------------------------------------------------------- /chp_10_sports_car/src/main/java/com/practicalunittesting/CarImpl.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 7 | * Visit http://practicalunittesting.com for more information. 8 | * 9 | * @author Tomek Kaczanowski 10 | */ 11 | public class CarImpl implements Car { 12 | 13 | private Engine engine; 14 | private Color color; 15 | private Manufacturer manufacturer; 16 | 17 | public Engine getEngine() { 18 | return engine; 19 | } 20 | 21 | public Color getColor() { 22 | return color; 23 | } 24 | 25 | public Manufacturer getManufacturer() { 26 | return manufacturer; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /chp_10_sports_car/src/main/java/com/practicalunittesting/CarSearch.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.awt.*; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 9 | * Visit http://practicalunittesting.com for more information. 10 | * 11 | * @author Tomek Kaczanowski 12 | */ 13 | public class CarSearch { 14 | 15 | private List cars = new ArrayList(); 16 | 17 | public void addCar(Car car) { 18 | cars.add(car); 19 | } 20 | 21 | public List findSportCars() { 22 | List sportCars = new ArrayList(); 23 | for (Car car : cars) { 24 | if (car.getEngine().getNbOfCylinders() > 6 25 | && Color.RED == car.getColor() 26 | && "Ferrari".equals(car.getManufacturer().getName())) { 27 | sportCars.add(car); 28 | } 29 | } 30 | return sportCars; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chp_10_sports_car/src/main/java/com/practicalunittesting/Engine.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface Engine { 10 | 11 | int getNbOfCylinders(); 12 | } 13 | -------------------------------------------------------------------------------- /chp_10_sports_car/src/main/java/com/practicalunittesting/Manufacturer.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public interface Manufacturer { 10 | String getName(); 11 | } 12 | -------------------------------------------------------------------------------- /chp_11_clean_this_mess/src/main/java/com/practicalunittesting/Fridge.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | 6 | /** 7 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 8 | * Visit http://practicalunittesting.com for more information. 9 | * 10 | * @author Tomek Kaczanowski 11 | */ 12 | public class Fridge { 13 | 14 | private Collection food = new HashSet(); 15 | 16 | public boolean put(String item) { 17 | return food.add(item); 18 | } 19 | 20 | public boolean contains(String item) { 21 | return food.contains(item); 22 | } 23 | 24 | public void take(String item) throws NoSuchItemException { 25 | boolean result = food.remove(item); 26 | if (!result) { 27 | throw new NoSuchItemException(item + " not found in the fridge"); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chp_11_clean_this_mess/src/main/java/com/practicalunittesting/NoSuchItemException.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | /** 4 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 5 | * Visit http://practicalunittesting.com for more information. 6 | * 7 | * @author Tomek Kaczanowski 8 | */ 9 | public class NoSuchItemException extends RuntimeException { 10 | public NoSuchItemException(String errorMsg) { 11 | super(errorMsg); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /chp_11_clean_this_mess/src/test/java/com/practicalunittesting/FoodTesting.java: -------------------------------------------------------------------------------- 1 | package com.practicalunittesting; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import static org.testng.Assert.*; 9 | 10 | /** 11 | * Practical Unit Testing with TestNG and Mockito - source code for exercises. 12 | * Visit http://practicalunittesting.com for more information. 13 | * 14 | * @author Tomek Kaczanowski 15 | */ 16 | @Test 17 | public class FoodTesting { 18 | 19 | public void testFridge() { 20 | Fridge fridge = new Fridge(); 21 | 22 | fridge.put("cheese"); 23 | assertEquals(fridge.contains("cheese"), true); 24 | assertEquals(fridge.put("cheese"), false); 25 | assertEquals(fridge.contains("cheese"), true); 26 | 27 | assertEquals(fridge.contains("ham"), false); 28 | 29 | fridge.put("ham"); 30 | assertEquals(fridge.contains("cheese"), true); 31 | assertEquals(fridge.contains("ham"), true); 32 | 33 | try { 34 | fridge.take("sausage"); 35 | fail("There was no sausage in the fridge!"); 36 | } 37 | catch(NoSuchItemException e) { 38 | // ok 39 | } 40 | 41 | } 42 | public void testPutTake() { 43 | Fridge fridge = new Fridge(); 44 | List food = new ArrayList(); 45 | food.add("yogurt"); 46 | food.add("milk"); 47 | food.add("eggs"); 48 | for (String item : food) { 49 | fridge.put(item); 50 | assertEquals(fridge.contains(item), true); 51 | fridge.take(item); 52 | assertEquals(fridge.contains(item), false); 53 | } 54 | 55 | for (String item : food) { 56 | try { 57 | fridge.take(item); 58 | fail("there was no " + item + " in the fridge"); 59 | } 60 | catch(NoSuchItemException e) { 61 | assertEquals(e.getMessage().contains(item), true); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomekkaczanowski/practicalunittesting-exercises/b0eb9d219a457c2f7466fbb83940b0a6f8e519e6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Mar 08 20:12:40 CET 2012 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-8-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query businessSystem maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add APP_NAME to the JAVA_OPTS as -Xdock:name 109 | if $darwin; then 110 | JAVA_OPTS="$JAVA_OPTS -Xdock:name=$APP_NAME" 111 | # we may also want to set -Xdock:image 112 | fi 113 | 114 | # For Cygwin, switch paths to Windows format before running java 115 | if $cygwin ; then 116 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 117 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 118 | 119 | # We build the pattern for arguments to be converted via cygpath 120 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 121 | SEP="" 122 | for dir in $ROOTDIRSRAW ; do 123 | ROOTDIRS="$ROOTDIRS$SEP$dir" 124 | SEP="|" 125 | done 126 | OURCYGPATTERN="(^($ROOTDIRS))" 127 | # Add a user-defined pattern to the cygpath arguments 128 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 129 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 130 | fi 131 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 132 | i=0 133 | for arg in "$@" ; do 134 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 135 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 136 | 137 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 138 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 139 | else 140 | eval `echo args$i`="\"$arg\"" 141 | fi 142 | i=$((i+1)) 143 | done 144 | case $i in 145 | (0) set -- ;; 146 | (1) set -- "$args0" ;; 147 | (2) set -- "$args0" "$args1" ;; 148 | (3) set -- "$args0" "$args1" "$args2" ;; 149 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 150 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 151 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 152 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 153 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 154 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 155 | esac 156 | fi 157 | 158 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 159 | function splitJvmOpts() { 160 | JVM_OPTS=("$@") 161 | } 162 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 163 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 164 | 165 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 166 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'chp_03_fahrenheit', 'chp_03_string_reversal', 2 | 'chp_05_user_service', 'chp_05_race_results', 3 | 'chp_06_test_collections', 'chp_06_time_testing', 'chp_06_custom_matcher', 'chp_06_id_generator', 4 | 'chp_07_legacy_code', 5 | 'chp_08_csv_reporter_log', 6 | 'chp_08_custom_test_listener', 7 | 'chp_09_test_fixture', 'chp_09_test_data_builder', 8 | 'chp_10_sports_car', 9 | 'chp_11_clean_this_mess' 10 | --------------------------------------------------------------------------------