Skip to content

Commit 4bfc15f

Browse files
eviltestereviltester
authored andcommitted
amended after proof of print book
changed the File examples more than any other
1 parent 5e9ceb6 commit 4bfc15f

13 files changed

Lines changed: 206 additions & 63 deletions

File tree

source/reportingpom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
http://maven.apache.org/surefire/maven-surefire-plugin/usage.html
1616
http://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html
1717
18-
mvn clean test -Dmaven.source=reportingpom.xml
18+
mvn clean surefire-report:report -Dmaven.source=reportingpom.xml
1919
-->
2020

2121
<properties>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.javafortesters.chap001basicsofjava.examples.classes;
2+
3+
import org.junit.Test;
4+
5+
public class ASysOutJunitTest {
6+
7+
@Test
8+
public void canOutputHelloWorldToConsole(){
9+
AClassWithAMethod myClass = new AClassWithAMethod();
10+
myClass.aMethodOnAClass();
11+
}
12+
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
package com.javafortesters.chap004testswithotherclasses.examples;
22

33
import org.junit.Test;
4-
54
import static org.junit.Assert.assertEquals;
65

76
public class IntegerExamplesTest {
87

98
@Test
109
public void integerExploration(){
11-
1210
Integer four = new Integer(4);
1311
assertEquals("intValue returns int 4",
1412
4, four.intValue());
15-
1613
Integer five = new Integer("5");
1714
assertEquals("intValue returns int 5",
1815
5, five.intValue());
19-
2016
Integer six = 6;
2117
assertEquals("autoboxing assignment for 6",
2218
6, six.intValue());
2319
}
24-
25-
26-
}
20+
}

source/src/test/java/com/javafortesters/chap005testwithourownclasses/domainobject/examples/TestAppEnvironmentTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ public class TestAppEnvironmentTest {
88

99
@Test
1010
public void canGetUrlStatically(){
11+
1112
assertEquals("Returns Hard Coded URL",
1213
"http://192.123.0.3:67",
13-
TestAppEnv.getUrl());
14+
TestAppEnv.getUrl()
15+
);
1416
}
1517

1618
@Test

source/src/test/java/com/javafortesters/chap007basicsofjavarevisited/examples/StatementsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public void statements(){
1212
assertEquals(4, 2+2);
1313

1414
assertEquals("2+2 always = 4",
15-
4,
16-
2+2);
15+
4,
16+
2+2);
1717

1818
}
1919
}

source/src/test/java/com/javafortesters/chap014junit/exercises/JunitExercisesTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ public void junitHasAssertions(){
4646
public void assertThatWithHamcrestMatchers(){
4747

4848
assertThat(3 + 3, is(6));
49+
50+
/* failing assert used to generate message in book
51+
assertThat(3 + 3, is(7));
52+
*/
53+
4954
assertThat("3 + 3 = 6", 3 + 3, is(6));
5055

56+
/* failing assert used to generate message in book
57+
assertThat("3 + 3 = 6", 3 + 3, is(7));
58+
*/
59+
5160
assertThat("false is false", false, equalTo(false));
5261
assertThat(false, is(false));
5362

source/src/test/java/com/javafortesters/chap015stringsrevisited/examples/StringComparisonsTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void canCheckContainsOnString(){
3333
assertThat(hello.contains("He"), is(true));
3434
assertThat(hello.contains("Hello"), is(true));
3535

36-
assertThat(hello.contains("he"), is(false));
36+
assertThat(hello.contains("LL"), is(false));
3737

3838
assertThat(hello.contains("z"), is(false));
3939
assertThat(hello.contains("world"), is(false));
@@ -107,6 +107,22 @@ public void checkRegionMatches(){
107107
hello.regionMatches(true, 6, "fez", 0, 2),
108108
is(true));
109109

110+
// case insensitive search
111+
assertThat(
112+
hello.regionMatches(true, 0, "he", 0, 2),
113+
is(true));
114+
115+
// case sensitive search
116+
assertThat(
117+
hello.regionMatches(false, 0, "hE", 0, 2),
118+
is(false));
119+
assertThat(
120+
hello.regionMatches(0, "hE", 0, 2),
121+
is(false));
122+
assertThat(
123+
hello.regionMatches(0, "He", 0, 2),
124+
is(true));
125+
110126
assertFalse(
111127
hello.regionMatches(true, 3, "lady", 0, 2));
112128
assertFalse(

source/src/test/java/com/javafortesters/chap017_datestimes/examples/SimpleDateFormatTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void unusualDateFormatPatterns() throws ParseException {
113113
SimpleDateFormat sdf = new SimpleDateFormat("y M d HH:mm:ss.SSS");
114114
Date date = sdf.parse("2013 12 15 23:39:54.123");
115115

116+
116117
String[][] formatElement = {
117118
{"w", "Week in the year"},
118119
{"www", "Week in the year"},

source/src/test/java/com/javafortesters/chap017_datestimes/exercises/DateTimeExercisesTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@ public void useOtherCalendarConstants(){
7575
@Test
7676
public void experimentWithCalendarConstants(){
7777
Calendar cal = Calendar.getInstance();
78-
cal.set(2013, Calendar.DECEMBER, 15, 23,39, 54);
78+
cal.set(2013, Calendar.DECEMBER, 15, 23, 39, 54);
79+
80+
81+
assertThat(cal.get(Calendar.DAY_OF_WEEK), is(1));
82+
assertThat(cal.get(Calendar.DAY_OF_WEEK), is(Calendar.SUNDAY));
83+
assertThat(cal.get(Calendar.WEEK_OF_YEAR), is(50));
84+
assertThat(cal.get(Calendar.DAY_OF_YEAR), is(349));
85+
7986
// week of month depends on first day of week
8087
// some places use SUNDAY as first day
8188
// set to MONDAY for our calculation
82-
// and control Minimdal Days in First Week
89+
// and control Minimal Days in First Week
8390
cal.setFirstDayOfWeek(Calendar.MONDAY);
8491
cal.setMinimalDaysInFirstWeek(6);
85-
86-
assertThat(cal.get(Calendar.DAY_OF_WEEK), is(1));
87-
assertThat(cal.get(Calendar.DAY_OF_WEEK), is(Calendar.SUNDAY));
8892
assertThat(cal.get(Calendar.WEEK_OF_MONTH), is(2));
89-
assertThat(cal.get(Calendar.WEEK_OF_YEAR), is(50));
90-
assertThat(cal.get(Calendar.DAY_OF_YEAR), is(349));
9193
}
9294

9395
@Test

source/src/test/java/com/javafortesters/chap018properties/examples/PropertiesTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public void simpleSaveLoadPropertiesFile() throws IOException {
8484

8585
String tempDirectory = System.getProperty("java.io.tmpdir");
8686
String tempResourceFilePath =
87-
tempDirectory +
88-
"tempFileForPropertiesStoreTest.properties";
87+
new File(tempDirectory,
88+
"tempFileForPropertiesStoreTest.properties")
89+
.getAbsolutePath();
8990

9091
Properties saved = new Properties();
9192
saved.setProperty("prop1", "Hello");

0 commit comments

Comments
 (0)