forked from eviltester/javaForTestersCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial release of the java for testers source code extracted from th…
…e book macro comments
- Loading branch information
eviltester
authored and
eviltester
committed
May 13, 2014
1 parent
b871dfb
commit 719362a
Showing
91 changed files
with
6,326 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
javaForTesters | ||
============== | ||
java For Testers Source Code | ||
============================ | ||
|
||
Java source code to support the book "Java For Testers" | ||
Copyright 2013 Alan Richardson, Compendium Developments | ||
|
||
About | ||
----- | ||
Java source code to support the book "Java For Testers" by Alan Richardson. | ||
|
||
This contains all the examples and exercise answers for the book. | ||
|
||
The main website for the book is http:https://javafortesters.com/ | ||
|
||
You can purchase the book on leanpub: https://leanpub.com/javaForTesters | ||
|
||
http:https://www.eviltester.com | ||
http:https://www.seleniumsimplified.com | ||
http:https://www.javafortesters.com | ||
http:https://www.compendiumdev.co.uk | ||
Twitter: @eviltester | ||
|
||
### Note: | ||
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. | ||
|
||
License | ||
------- | ||
You can use this source for personal use to help you learn Java and to work through the book "Java For Testers". | ||
|
||
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. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http:https://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 | ||
http:https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>javaForTesters</groupId> | ||
<artifactId>javaForTesters</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http:https://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 | ||
http:https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>javaForTesters</groupId> | ||
<artifactId>javaForTesters</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<!-- | ||
http:https://maven.apache.org/surefire/maven-surefire-plugin/usage.html | ||
http:https://maven.apache.org/surefire/maven-surefire-report-plugin/report-mojo.html | ||
mvn clean test -Dmaven.source=reportingpom.xml | ||
mvn surefire-report:report -Dmaven.source=reportingpom.xml | ||
--> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven.surefire</groupId> | ||
<artifactId>surefire</artifactId> | ||
<version>2.15</version> | ||
<type>pom</type> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<reporting> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-report-plugin</artifactId> | ||
<version>2.15</version> | ||
<configuration> | ||
<showSuccess>true</showSuccess> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</reporting> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
8 changes: 8 additions & 0 deletions
8
source/src/main/java/com/javafortesters/classes/AClassWithAMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.javafortesters.classes; | ||
|
||
public class AClassWithAMethod { | ||
|
||
public void aMethodOnAClass(){ | ||
System.out.println("Hello World"); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
source/src/main/java/com/javafortesters/classes/AnEmptyClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.javafortesters.classes; | ||
|
||
public class AnEmptyClass { | ||
} |
17 changes: 17 additions & 0 deletions
17
source/src/main/java/com/javafortesters/domainentities/AdminUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.javafortesters.domainentities; | ||
|
||
public class AdminUser extends User { | ||
|
||
public AdminUser(){ | ||
this("adminuser", "password"); | ||
} | ||
|
||
public AdminUser(String username, String password){ | ||
super(username, password); | ||
} | ||
|
||
@Override | ||
public String getPermission(){ | ||
return "Elevated"; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
source/src/main/java/com/javafortesters/domainentities/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.javafortesters.domainentities; | ||
|
||
public class User { | ||
|
||
|
||
private String username; | ||
private String password; | ||
|
||
public User(){ | ||
this("username", "password"); | ||
} | ||
|
||
|
||
public User(String username, String password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public String getPermission() { | ||
return "Normal"; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
source/src/main/java/com/javafortesters/domainentities/UserComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.javafortesters.domainentities; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* compare users based on username and password | ||
* | ||
* order them by username.length + password.length | ||
* | ||
* where the length comparison == 0, delegate to the String | ||
* compareTo for username | ||
* | ||
* return 0 if the same | ||
* return negative if o1 is less than o2 | ||
* return positive if o1 is greater than o2 | ||
*/ | ||
public class UserComparator implements Comparator { | ||
|
||
public int compare(Object oUser1, Object oUser2) { | ||
|
||
User user1 = (User)oUser1; | ||
User user2 = (User)oUser2; | ||
|
||
int user1Comparator = user1.getPassword().length() + | ||
user1.getUsername().length(); | ||
|
||
int user2Comparator = user2.getPassword().length() + | ||
user2.getUsername().length(); | ||
|
||
int val = user1Comparator - user2Comparator; | ||
|
||
if(val==0){ | ||
val = user1.getUsername().compareTo(user2.getUsername()); | ||
} | ||
|
||
return val; | ||
} | ||
} | ||
|
||
/* | ||
// add the following line just before return val; to see the comparator in action | ||
System.out.println("Compare " + user1.getUsername() + | ||
" with " + user2.getUsername() + " = " + val); | ||
*/ |
42 changes: 42 additions & 0 deletions
42
source/src/main/java/com/javafortesters/domainentities/UserComparatorDisallowDupes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.javafortesters.domainentities; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* compare users based on username and password | ||
* | ||
* order them by username.length + password.length | ||
* disallow duplicate usernames | ||
* | ||
* where the length comparison == 0, delegate to the String | ||
* compareTo for username | ||
* | ||
* return 0 if the same | ||
* return negative if o1 is less than o2 | ||
* return positive if o1 is greater than o2 | ||
*/ | ||
public class UserComparatorDisallowDupes implements Comparator { | ||
|
||
public int compare(Object oUser1, Object oUser2) { | ||
User user1 = (User)oUser1; | ||
User user2 = (User)oUser2; | ||
|
||
if(user1.getUsername().compareTo(user2.getUsername())==0){ | ||
return 0; | ||
} | ||
|
||
int user1Comparator = user1.getPassword().length() + | ||
user1.getUsername().length(); | ||
|
||
int user2Comparator = user2.getPassword().length() + | ||
user2.getUsername().length(); | ||
|
||
int val = user1Comparator - user2Comparator; | ||
|
||
if(val==0){ | ||
val = user1.getUsername().compareTo(user2.getUsername()); | ||
} | ||
|
||
return val; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
source/src/main/java/com/javafortesters/domainentities/interim/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
package com.javafortesters.domainentities; | ||
public class User { | ||
} | ||
*/ | ||
|
||
package com.javafortesters.domainentities.interim; | ||
|
||
public class User { | ||
|
||
private String username; | ||
private String password; | ||
|
||
public User(){ | ||
username = "username"; | ||
password = "password"; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
} |
Oops, something went wrong.