Skip to content

Commit 719362a

Browse files
eviltestereviltester
authored andcommitted
initial release of the java for testers source code extracted from the book macro comments
1 parent b871dfb commit 719362a

File tree

91 files changed

+6326
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+6326
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010

1111
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1212
hs_err_pid*
13+
.idea
14+
target
15+
/source/javaForTesters.iml

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
javaForTesters
2-
==============
1+
java For Testers Source Code
2+
============================
33

4-
Java source code to support the book "Java For Testers"
4+
Copyright 2013 Alan Richardson, Compendium Developments
5+
6+
About
7+
-----
8+
Java source code to support the book "Java For Testers" by Alan Richardson.
9+
10+
This contains all the examples and exercise answers for the book.
11+
12+
The main website for the book is http://javafortesters.com/
13+
14+
You can purchase the book on leanpub: https://leanpub.com/javaForTesters
15+
16+
http://www.eviltester.com
17+
http://www.seleniumsimplified.com
18+
http://www.javafortesters.com
19+
http://www.compendiumdev.co.uk
20+
Twitter: @eviltester
21+
22+
### Note:
23+
This code is an extract from the actual source used to create the book. The actual source has embedded macros to allow the book to be automatically generated. While the extraction process has been tested, it may still contain errors. If you find differences from the book, or discover errors in this code, please let the author know. All tests have been run prior to the source release.
24+
25+
License
26+
-------
27+
You can use this source for personal use to help you learn Java and to work through the book "Java For Testers".
28+
29+
Please do not use this code as part of any training that you provide to other people, it is for personal use only. If you wish to use this code for public training or commercially, please contact the author to discuss commercial licensing terms.
30+
31+
If you use this code in your own projects, you do so at your own risk, no warranty is provided or implied by release of this source.

source/pom.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
7+
<modelVersion>4.0.0</modelVersion>
8+
9+
<groupId>javaForTesters</groupId>
10+
<artifactId>javaForTesters</artifactId>
11+
<version>1.0-SNAPSHOT</version>
12+
<packaging>jar</packaging>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>4.11</version>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<configuration>
34+
<source>1.7</source>
35+
<target>1.7</target>
36+
</configuration>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
</project>

source/reportingpom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
7+
<modelVersion>4.0.0</modelVersion>
8+
9+
<groupId>javaForTesters</groupId>
10+
<artifactId>javaForTesters</artifactId>
11+
<version>1.0-SNAPSHOT</version>
12+
<packaging>jar</packaging>
13+
14+
<!--
15+
http://maven.apache.org/surefire/maven-surefire-plugin/usage.html
16+
http://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html
17+
18+
mvn clean test -Dmaven.source=reportingpom.xml
19+
mvn surefire-report:report -Dmaven.source=reportingpom.xml
20+
-->
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
</properties>
25+
26+
27+
<dependencies>
28+
29+
<dependency>
30+
<groupId>junit</groupId>
31+
<artifactId>junit</artifactId>
32+
<version>4.11</version>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.apache.maven.surefire</groupId>
37+
<artifactId>surefire</artifactId>
38+
<version>2.15</version>
39+
<type>pom</type>
40+
</dependency>
41+
42+
</dependencies>
43+
44+
<reporting>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-surefire-report-plugin</artifactId>
49+
<version>2.15</version>
50+
<configuration>
51+
<showSuccess>true</showSuccess>
52+
</configuration>
53+
</plugin>
54+
</plugins>
55+
</reporting>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-compiler-plugin</artifactId>
62+
<configuration>
63+
<source>1.7</source>
64+
<target>1.7</target>
65+
</configuration>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
</project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.javafortesters.classes;
2+
3+
public class AClassWithAMethod {
4+
5+
public void aMethodOnAClass(){
6+
System.out.println("Hello World");
7+
}
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.javafortesters.classes;
2+
3+
public class AnEmptyClass {
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.javafortesters.domainentities;
2+
3+
public class AdminUser extends User {
4+
5+
public AdminUser(){
6+
this("adminuser", "password");
7+
}
8+
9+
public AdminUser(String username, String password){
10+
super(username, password);
11+
}
12+
13+
@Override
14+
public String getPermission(){
15+
return "Elevated";
16+
}
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.javafortesters.domainentities;
2+
3+
public class User {
4+
5+
6+
private String username;
7+
private String password;
8+
9+
public User(){
10+
this("username", "password");
11+
}
12+
13+
14+
public User(String username, String password) {
15+
this.username = username;
16+
this.password = password;
17+
}
18+
19+
public String getUsername() {
20+
return username;
21+
}
22+
23+
public String getPassword() {
24+
return password;
25+
}
26+
27+
public void setPassword(String password) {
28+
this.password = password;
29+
}
30+
31+
public String getPermission() {
32+
return "Normal";
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.javafortesters.domainentities;
2+
3+
import java.util.Comparator;
4+
5+
/**
6+
* compare users based on username and password
7+
*
8+
* order them by username.length + password.length
9+
*
10+
* where the length comparison == 0, delegate to the String
11+
* compareTo for username
12+
*
13+
* return 0 if the same
14+
* return negative if o1 is less than o2
15+
* return positive if o1 is greater than o2
16+
*/
17+
public class UserComparator implements Comparator {
18+
19+
public int compare(Object oUser1, Object oUser2) {
20+
21+
User user1 = (User)oUser1;
22+
User user2 = (User)oUser2;
23+
24+
int user1Comparator = user1.getPassword().length() +
25+
user1.getUsername().length();
26+
27+
int user2Comparator = user2.getPassword().length() +
28+
user2.getUsername().length();
29+
30+
int val = user1Comparator - user2Comparator;
31+
32+
if(val==0){
33+
val = user1.getUsername().compareTo(user2.getUsername());
34+
}
35+
36+
return val;
37+
}
38+
}
39+
40+
/*
41+
// add the following line just before return val; to see the comparator in action
42+
System.out.println("Compare " + user1.getUsername() +
43+
" with " + user2.getUsername() + " = " + val);
44+
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.javafortesters.domainentities;
2+
3+
import java.util.Comparator;
4+
5+
/**
6+
* compare users based on username and password
7+
*
8+
* order them by username.length + password.length
9+
* disallow duplicate usernames
10+
*
11+
* where the length comparison == 0, delegate to the String
12+
* compareTo for username
13+
*
14+
* return 0 if the same
15+
* return negative if o1 is less than o2
16+
* return positive if o1 is greater than o2
17+
*/
18+
public class UserComparatorDisallowDupes implements Comparator {
19+
20+
public int compare(Object oUser1, Object oUser2) {
21+
User user1 = (User)oUser1;
22+
User user2 = (User)oUser2;
23+
24+
if(user1.getUsername().compareTo(user2.getUsername())==0){
25+
return 0;
26+
}
27+
28+
int user1Comparator = user1.getPassword().length() +
29+
user1.getUsername().length();
30+
31+
int user2Comparator = user2.getPassword().length() +
32+
user2.getUsername().length();
33+
34+
int val = user1Comparator - user2Comparator;
35+
36+
if(val==0){
37+
val = user1.getUsername().compareTo(user2.getUsername());
38+
}
39+
40+
return val;
41+
}
42+
}

0 commit comments

Comments
 (0)