Skip to content

Commit

Permalink
initial release of the java for testers source code extracted from th…
Browse files Browse the repository at this point in the history
…e book macro comments
  • Loading branch information
eviltester authored and eviltester committed May 13, 2014
1 parent b871dfb commit 719362a
Show file tree
Hide file tree
Showing 91 changed files with 6,326 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# virtual machine crash logs, see http:https://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea
target
/source/javaForTesters.iml
33 changes: 30 additions & 3 deletions README.md
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.
40 changes: 40 additions & 0 deletions source/pom.xml
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>
69 changes: 69 additions & 0 deletions source/reportingpom.xml
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>
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.javafortesters.classes;

public class AnEmptyClass {
}
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 source/src/main/java/com/javafortesters/domainentities/User.java
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";
}
}
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);
*/
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;
}
}
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;
}
}
Loading

0 comments on commit 719362a

Please sign in to comment.