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

Commit336d85c

Browse files
author
Bruce Eckel
committed
Trying to get everything to build with JUnit5
1 parent2ca00a4 commit336d85c

22 files changed

+238
-198
lines changed

‎build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ subprojects {
191191
main {
192192
java {
193193
srcDir projectDir
194-
exclude"*Test.java"
194+
//exclude "*Test.java"
195195
exclude"*Tests.java"
196196
exclude"*JUnit.java"
197197
exclude"StringInverter*.java"
198-
exclude"Queue.java"
198+
//exclude "Queue.java"
199199
}
200200
resources {
201201
srcDir projectDir
@@ -207,11 +207,11 @@ subprojects {
207207
srcDir projectDir
208208
}
209209
}
210-
test {
210+
/* test {
211211
java {
212212
srcDir projectDir
213213
}
214-
}
214+
}*/
215215
}
216216

217217
/*test {

‎generics/Amphibian.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// generics/Amphibian.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+
publicclassAmphibian {}

‎generics/ApplyTest.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@
66
importjava.util.function.*;
77
importonjava.*;
88

9-
classShape {
10-
privatestaticlongcounter =0;
11-
privatefinallongid =counter++;
12-
@Override
13-
publicStringtoString() {
14-
returngetClass().getSimpleName() +" " +id;
15-
}
16-
publicvoidrotate() {
17-
System.out.println(this +" rotate");
18-
}
19-
publicvoidresize(intnewSize) {
20-
System.out.println(this +" resize " +newSize);
21-
}
22-
}
23-
24-
classSquareextendsShape {}
25-
26-
classFilledList<T>extendsArrayList<T> {
27-
publicFilledList(Supplier<T>gen,intsize) {
28-
Suppliers.fill(this,gen,size);
29-
}
30-
}
31-
329
publicclassApplyTest {
3310
publicstaticvoidmain(String[]args)throwsException {
3411
List<Shape>shapes =

‎generics/FilledList.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// generics/FilledList.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+
importjava.util.*;
6+
importjava.util.function.*;
7+
importonjava.*;
8+
9+
classFilledList<T>extendsArrayList<T> {
10+
publicFilledList(Supplier<T>gen,intsize) {
11+
Suppliers.fill(this,gen,size);
12+
}
13+
publicFilledList(Tt,intsize) {
14+
for(inti =0;i <size;i++)
15+
this.add(t);
16+
}
17+
publicstaticvoidmain(String[]args) {
18+
List<String>list =newFilledList<>("Hello",4);
19+
System.out.println(list);
20+
// Supplier version:
21+
List<Integer>ilist =newFilledList<>(() ->47,4);
22+
System.out.println(ilist);
23+
}
24+
}
25+
/* Output:
26+
[Hello, Hello, Hello, Hello]
27+
[47, 47, 47, 47]
28+
*/

‎generics/FilledListMaker.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎generics/MultipleInterfaceVariants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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
// {CompileTimeError} (Will not compile)
6+
packagegenerics;
67

78
interfacePayable<T> {}
89

‎generics/Shape.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// generics/Shape.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+
6+
publicclassShape {
7+
privatestaticlongcounter =0;
8+
privatefinallongid =counter++;
9+
@Override
10+
publicStringtoString() {
11+
returngetClass().getSimpleName() +" " +id;
12+
}
13+
publicvoidrotate() {
14+
System.out.println(this +" rotate");
15+
}
16+
publicvoidresize(intnewSize) {
17+
System.out.println(this +" resize " +newSize);
18+
}
19+
}

‎generics/SimpleQueue.java

Lines changed: 1 addition & 1 deletion
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-
// A different kind ofcollection that isIterable
5+
// A different kind of Iterable collection
66
importjava.util.*;
77

88
publicclassSimpleQueue<T>implementsIterable<T> {

‎generics/Square.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// generics/Square.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+
publicclassSquareextendsShape {}

‎generics/TupleTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
55
importonjava.*;
66

7-
classAmphibian {}
8-
classVehicle {}
9-
107
publicclassTupleTest {
118
staticTuple2<String,Integer>f() {
129
// Autoboxing converts the int to Integer:

‎generics/UseList.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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
// {CompileTimeError} (Will not compile)
6+
importjava.util.*;
67

78
publicclassUseList<W,T> {
89
voidf(List<T>v) {}

‎generics/Vehicle.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// generics/Vehicle.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+
publicclassVehicle {}

‎references/DeepCopy.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

‎references/DeepCopyTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// references/DeepCopyTest.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+
packagereferences;
6+
importorg.junit.jupiter.api.*;
7+
importstaticorg.junit.jupiter.api.Assertions.*;
8+
9+
publicclassDeepCopyTest {
10+
@Test
11+
publicvoidtestClone() {
12+
OceanReadingreading =
13+
newOceanReading(33.9,100.5);
14+
// Now clone it:
15+
OceanReadingclone =reading.clone();
16+
TemperatureReadingtr =
17+
clone.getTemperatureReading();
18+
tr.setTemperature(tr.getTemperature() +1);
19+
clone.setTemperatureReading(tr);
20+
DepthReadingdr =clone.getDepthReading();
21+
dr.setDepth(dr.getDepth() +1);
22+
clone.setDepthReading(dr);
23+
assertEquals(reading.toString(),
24+
"temperature: 33.9, depth: 100.5");
25+
assertEquals(clone.toString(),
26+
"temperature: 34.9, depth: 101.5");
27+
}
28+
}

‎references/DepthReading.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// references/DepthReading.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+
// Cloning a composed object
6+
packagereferences;
7+
8+
publicclassDepthReadingimplementsCloneable {
9+
privatedoubledepth;
10+
publicDepthReading(doubledepth) {
11+
this.depth =depth;
12+
}
13+
@Override
14+
publicDepthReadingclone() {
15+
try {
16+
return (DepthReading)super.clone();
17+
}catch(CloneNotSupportedExceptione) {
18+
thrownewRuntimeException(e);
19+
}
20+
}
21+
publicdoublegetDepth() {returndepth; }
22+
publicvoidsetDepth(doubledepth) {
23+
this.depth =depth;
24+
}
25+
@Override
26+
publicStringtoString() {
27+
returnString.valueOf(depth);
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp