Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit33a529c

Browse files
committed
Chapter name and order change
1 parent941213a commit33a529c

30 files changed

+195
-188
lines changed

‎build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ subprojects {
277277
task run(dependsOn: createdTasks)
278278
}
279279

280-
project(':verifying') {
280+
project(':validating') {
281281
jmh {
282-
include='verifying.jmh.*'
282+
include='validating.jmh.*'
283283
}
284284
}
285285

‎network/SimpleClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
publicclassSimpleClient {
1212
publicstaticvoid
1313
main(String[]args)throwsIOException {
14-
// Passing null to getByName() produces the
15-
// special "Local Loopback" IP address, for
16-
// testing on one machine w/o a network:
14+
// Produce the "Local Loopback" IP address
15+
// for testing on one machine w/o a network:
1716
InetAddressaddr =
1817
InetAddress.getLoopbackAddress();
1918
System.out.println("addr = " +addr);
@@ -35,7 +34,7 @@ public class SimpleClient {
3534
newOutputStreamWriter(
3635
socket.getOutputStream())),true);
3736
for(inti =0;i <10;i ++) {
38-
out.println("howdy " +i);
37+
out.println("hello " +i);
3938
Stringstr =in.readLine();
4039
System.out.println(str);
4140
}

‎network/SimpleServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
//Just echoes whatever the client sends
5+
//Echoes what the client sends
66
// {ValidateByHand}
77
importjava.io.*;
88
importjava.net.*;
@@ -30,7 +30,7 @@ public class SimpleServer {
3030
newPrintWriter(
3131
newBufferedWriter(
3232
newOutputStreamWriter(
33-
socket.getOutputStream())),true);
33+
socket.getOutputStream())),true);
3434
while (true) {
3535
Stringstr =in.readLine();
3636
if(str.equals("END"))break;

‎verifying/Assert1.javarenamed to‎validating/Assert1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/Assert1.java
1+
//validating/Assert1.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/Assert2.javarenamed to‎validating/Assert2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/Assert2.java
1+
//validating/Assert2.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/BadMicroBenchmark.javarenamed to‎validating/BadMicroBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/BadMicroBenchmark.java
1+
//validating/BadMicroBenchmark.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/BadMicroBenchmark2.javarenamed to‎validating/BadMicroBenchmark2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/BadMicroBenchmark2.java
1+
//validating/BadMicroBenchmark2.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/BadMicroBenchmark3.javarenamed to‎validating/BadMicroBenchmark3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/BadMicroBenchmark3.java
1+
//validating/BadMicroBenchmark3.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/CountedList.javarenamed to‎validating/CountedList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//verifying/CountedList.java
1+
//validating/CountedList.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
// A List that keeps track of how many
66
// of itself are created.
7-
packageverifying;
7+
packagevalidating;
88
importjava.util.*;
99

1010
publicclassCountedListextendsArrayList<String> {

‎verifying/CountedListTest.javarenamed to‎validating/CountedListTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//verifying/CountedListTest.java
1+
//validating/CountedListTest.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
// Simple use of JUnit to test CountedList.
6-
packageverifying;
6+
packagevalidating;
77
importjava.util.*;
88
importorg.junit.jupiter.api.*;
99
importstaticorg.junit.jupiter.api.Assertions.*;
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// validating/DynamicStringInverterTests.java
2+
// (c)2016 MindView LLC: see Copyright.txt
3+
// We make no guarantees that this code is fit for any purpose.
4+
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5+
packagevalidating;
6+
importjava.util.*;
7+
importjava.util.function.*;
8+
importjava.util.stream.*;
9+
importorg.junit.jupiter.api.*;
10+
importstaticorg.junit.jupiter.api.Assertions.*;
11+
importstaticorg.junit.jupiter.api.DynamicTest.*;
12+
13+
classDynamicStringInverterTests {
14+
// Combine operations to prevent code duplication:
15+
Stream<DynamicTest>testVersions(Stringid,
16+
Function<StringInverter,String>test) {
17+
List<StringInverter>versions =Arrays.asList(
18+
newInverter1(),newInverter2(),
19+
newInverter3(),newInverter4());
20+
returnDynamicTest.stream(
21+
versions.iterator(),
22+
inverter ->inverter.getClass().getSimpleName(),
23+
inverter -> {
24+
System.out.println(
25+
inverter.getClass().getSimpleName() +": " +id
26+
);
27+
try {
28+
if(test.apply(inverter) !="fail")
29+
System.out.println("Success");
30+
}catch(Exception |Errore) {
31+
System.out.println("Exception: " +e.getMessage());
32+
}
33+
}
34+
);
35+
}
36+
StringisEqual(Stringlval,Stringrval) {
37+
if(lval.equals(rval))
38+
return"success";
39+
System.out.println("FAIL: " +lval +" != " +rval);
40+
return"fail";
41+
}
42+
@BeforeAll
43+
staticvoidstartMsg() {
44+
System.out.println(
45+
">>> Starting DynamicStringInverterTests <<<");
46+
}
47+
@AfterAll
48+
staticvoidendMsg() {
49+
System.out.println(
50+
">>> Finished DynamicStringInverterTests <<<");
51+
}
52+
@TestFactory
53+
Stream<DynamicTest>basicInversion1() {
54+
Stringin ="Exit, Pursued by a Bear.";
55+
Stringout ="eXIT, pURSUED BY A bEAR.";
56+
returntestVersions(
57+
"Basic inversion (should succeed)",
58+
inverter ->isEqual(inverter.invert(in),out)
59+
);
60+
}
61+
@TestFactory
62+
Stream<DynamicTest>basicInversion2() {
63+
returntestVersions(
64+
"Basic inversion (should fail)",
65+
inverter ->isEqual(inverter.invert("X"),"X"));
66+
}
67+
@TestFactory
68+
Stream<DynamicTest>disallowedCharacters() {
69+
Stringdisallowed =";-_()*&^%$#@!~`0123456789";
70+
returntestVersions(
71+
"Disallowed characters",
72+
inverter -> {
73+
Stringresult =disallowed.chars()
74+
.mapToObj(c -> {
75+
Stringcc =Character.toString((char)c);
76+
try {
77+
inverter.invert(cc);
78+
return"";
79+
}catch(RuntimeExceptione) {
80+
returncc;
81+
}
82+
}).collect(Collectors.joining(""));
83+
if(result.length() ==0)
84+
return"success";
85+
System.out.println("Bad characters: " +result);
86+
return"fail";
87+
}
88+
);
89+
}
90+
@TestFactory
91+
Stream<DynamicTest>allowedCharacters() {
92+
Stringlowcase ="abcdefghijklmnopqrstuvwxyz ,.";
93+
Stringupcase ="ABCDEFGHIJKLMNOPQRSTUVWXYZ ,.";
94+
returntestVersions(
95+
"Allowed characters (should succeed)",
96+
inverter -> {
97+
assertEquals(inverter.invert(lowcase),upcase);
98+
assertEquals(inverter.invert(upcase),lowcase);
99+
return"success";
100+
}
101+
);
102+
}
103+
@TestFactory
104+
Stream<DynamicTest>lengthNoGreaterThan30() {
105+
Stringstr ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
106+
assertTrue(str.length() >30);
107+
returntestVersions(
108+
"Length must be less than 31 (throws exception)",
109+
inverter ->inverter.invert(str)
110+
);
111+
}
112+
@TestFactory
113+
Stream<DynamicTest>lengthLessThan31() {
114+
Stringstr ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
115+
assertTrue(str.length() <31);
116+
returntestVersions(
117+
"Length must be less than 31 (should succeed)",
118+
inverter ->inverter.invert(str)
119+
);
120+
}
121+
}

‎verifying/FirstJUnit5Tests.javarenamed to‎validating/FirstJUnit5Tests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//verifying/FirstJUnit5Tests.java
1+
//validating/FirstJUnit5Tests.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66
importorg.junit.jupiter.api.*;
77
importstaticorg.junit.jupiter.api.Assertions.*;
88

‎verifying/GuavaPreconditions.javarenamed to‎validating/GuavaPreconditions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/GuavaPreconditions.java
1+
//validating/GuavaPreconditions.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//verifying/StringInverter1.java
1+
//validating/Inverter1.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66

7-
publicclassStringInverter1implementsStringInverter {
8-
publicStringinvert(Stringstr) {return""; }
7+
publicclassInverter1implementsStringInverter {
8+
publicStringinvert(Stringstr) {returnstr; }
99
}

‎verifying/StringInverter2.javarenamed to‎validating/Inverter2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//verifying/StringInverter2.java
1+
//validating/Inverter2.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66
importstaticjava.lang.Character.*;
77

8-
publicclassStringInverter2implementsStringInverter {
8+
publicclassInverter2implementsStringInverter {
99
publicStringinvert(Stringstr) {
1010
Stringresult ="";
1111
for(inti =0;i <str.length();i++) {

‎verifying/StringInverter3.javarenamed to‎validating/Inverter3.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//verifying/StringInverter3.java
1+
//validating/Inverter3.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66
importstaticjava.lang.Character.*;
77

8-
publicclassStringInverter3implementsStringInverter {
8+
publicclassInverter3implementsStringInverter {
99
publicStringinvert(Stringstr) {
1010
if(str.length() >30)
1111
thrownewRuntimeException("argument too long!");

‎verifying/StringInverter4.javarenamed to‎validating/Inverter4.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//verifying/StringInverter4.java
1+
//validating/Inverter4.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66
importstaticjava.lang.Character.*;
77

8-
publicclassStringInverter4implementsStringInverter {
8+
publicclassInverter4implementsStringInverter {
99
staticfinalStringallowed =
1010
"abcdefghijklmnopqrstuvwxyz ,." +
1111
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

‎verifying/LoaderAssertions.javarenamed to‎validating/LoaderAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/LoaderAssertions.java
1+
//validating/LoaderAssertions.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/Queue.javarenamed to‎validating/Queue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//verifying/Queue.java
1+
//validating/Queue.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
// Demonstration of Design by Contract (DbC)
6-
packageverifying;
6+
packagevalidating;
77
importjava.util.*;
88

99
publicclassQueue {

‎verifying/QueueException.javarenamed to‎validating/QueueException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//verifying/QueueException.java
1+
//validating/QueueException.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66

77
publicclassQueueExceptionextendsRuntimeException {
88
publicQueueException(Stringwhy) {super(why); }

‎verifying/QueueTest.javarenamed to‎validating/QueueTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//verifying/QueueTest.java
1+
//validating/QueueTest.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
6-
importverifying.Queue;
5+
packagevalidating;
6+
//importvalidating.Queue;
77
importorg.junit.jupiter.api.*;
88
importstaticorg.junit.jupiter.api.Assertions.*;
99

‎verifying/SLF4JLevels.javarenamed to‎validating/SLF4JLevels.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/SLF4JLevels.java
1+
//validating/SLF4JLevels.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/SLF4JLogging.javarenamed to‎validating/SLF4JLogging.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/SLF4JLogging.java
1+
//validating/SLF4JLogging.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/SimpleDebugging.javarenamed to‎validating/SimpleDebugging.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//verifying/SimpleDebugging.java
1+
//validating/SimpleDebugging.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.

‎verifying/StringInverter.javarenamed to‎validating/StringInverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//verifying/StringInverter.java
1+
//validating/StringInverter.java
22
// (c)2016 MindView LLC: see Copyright.txt
33
// We make no guarantees that this code is fit for any purpose.
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
5-
packageverifying;
5+
packagevalidating;
66

77
interfaceStringInverter {
88
publicStringinvert(Stringstr);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp