Skip to content

Commit

Permalink
docs: add lost tdd examples
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 8, 2020
1 parent 711f32b commit 55d4fdc
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 0 deletions.
20 changes: 20 additions & 0 deletions code/ch10/tdd/AssertionRouletteTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tbs;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class AssertionRouletteTest {
@Test
public void testCloneNonBareRepoFromLocalTestServer() throws Exception {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);

int subResult = calculate.sub(9, 2);
int subSuccess = 7;
assertEquals(subSuccess, subResult);
}
}
19 changes: 19 additions & 0 deletions code/ch10/tdd/ConditionalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tbs;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ConditionalTest {
@Test
public void byGod() {
Calculate calculate = new Calculate();
// just examples
if (calculate.add(7, 9) == 16) {
if (calculate.sub(12, 9) == 3) {
int subSuccess = 7;
assertEquals(subSuccess, calculate.sub(9, 2));
}
}
}
}
21 changes: 21 additions & 0 deletions code/ch10/tdd/ConstructorInitializationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tbs;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ConstructorInitializationTest {
@Before
public void init() throws Exception {

}

@Test
public void name() {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;
assertEquals(success, result);
}
}
25 changes: 25 additions & 0 deletions code/ch10/tdd/DuplicateAssertTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tbs;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class DuplicateAssertTest {
@Test
public void testXmlSanitizer() {
boolean valid = XmlSanitizer.isValid("Fritzbox");
assertEquals("Fritzbox is valid", true, valid);

valid = XmlSanitizer.isValid("Fritz Box");
assertEquals("Spaces are valid", true, valid);

valid = XmlSanitizer.isValid("Frützbüx");
assertEquals("Frützbüx is invalid", false, valid);

valid = XmlSanitizer.isValid("Fritz!box");
assertEquals("Exclamation mark is valid", true, valid);

valid = XmlSanitizer.isValid("Fritz!box");
assertEquals("Exclamation mark is valid", true, valid);
}
}
13 changes: 13 additions & 0 deletions code/ch10/tdd/EmptyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tbs;

import org.junit.Test;

public class EmptyTest {

@Test
public void testCredGetFullSampleV1() throws Throwable {
// ScrapedCredentials credentials = innerCredTest(FULL_SAMPLE_v1);
// assertEquals("p4ssw0rd", credentials.pass);
// assertEquals("[email protected]",credentials.user);
}
}
10 changes: 10 additions & 0 deletions code/ch10/tdd/IgnoreTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tbs;

import org.junit.Ignore;

public class IgnoreTest {
@Ignore("Oops, Not Time fix it")
public void peerPriority() throws Exception {

}
}
15 changes: 15 additions & 0 deletions code/ch10/tdd/MagicNumberTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tbs;

import org.junit.Test;

import java.util.Calendar;

import static org.junit.Assert.assertEquals;

public class MagicNumberTest {
@Test
public void testGetLocalTimeAsCalendar() {
int result = 7 + 8;
assertEquals(15, result);
}
}
21 changes: 21 additions & 0 deletions code/ch10/tdd/MysteryGuestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tbs;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MysteryGuestTest {
@Test
public void testPersistence() throws Exception {
try (FileOutputStream out = new FileOutputStream("people.bin");) {
int result = 5;
out.write(result);
} catch (FileNotFoundException e) {
// blabla
} catch (IOException e) {
// blabla
}
}
}
16 changes: 16 additions & 0 deletions code/ch10/tdd/RedundantAssertionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tbs;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class RedundantAssertionTest {
@Test
public void testTrue() {
Calculate calculate = new Calculate();
int result = calculate.add(7, 8);
int success = 15;

assertEquals(true, true);
}
}
12 changes: 12 additions & 0 deletions code/ch10/tdd/RedundantPrintTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tbs;

import org.junit.Test;

public class RedundantPrintTest {
@Test
public void testTransform10mNEUAndBack() {
String result = "a, b, c";
System.out.println("result = " + result);
assertEquals(true, true);
}
}
11 changes: 11 additions & 0 deletions code/ch10/tdd/SleepyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tbs;

import org.junit.Test;

public class SleepyTest {
@Test
public void testEdictExternSearch() throws Exception {
Thread.sleep(500);
assertEquals(true, true);
}
}
5 changes: 5 additions & 0 deletions code/ch10/tdd/TestersOnly.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
*
* public for test call only
*
*/
13 changes: 13 additions & 0 deletions code/ch10/tdd/UnknownTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tbs;

import org.junit.Test;

public class UnknownTest {
@Test
public void hitGetPOICategoriesApi() throws Exception {
String a = "blabla";
String b = "blablac";
String c = a + b;
Show(a, b);
}
}

0 comments on commit 55d4fdc

Please sign in to comment.