Commits

Micha Kops  committed 030379e Draft

TestWatcher examples added, jUnit version changed.

  • Participants
  • Parent commits 37cef9e

Comments (0)

Files changed (7)

 .project
 .settings
 .classpath
-.target
+target
 infinitest.filters
   <groupId>com.hascode.tutorial</groupId>
   <artifactId>junit-4.11-examples</artifactId>
   <version>0.0.1</version>
+  <url>http://www.hascode.com</url>
+  
+  <properties>
+  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  
   <dependencies>
   	<dependency>
   		<groupId>junit</groupId>
   		<artifactId>junit</artifactId>
-  		<version>4.11-beta-1</version>
+  		<version>4.11</version>
   	</dependency>
   </dependencies>
+  
+  <build>
+    <plugins>
+        <plugin>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <configuration>
+                <source>1.6</source>
+                <target>1.6</target>
+            </configuration>
+        </plugin>
+    </plugins>
+</build>
 </project>

File src/main/java/com/hascode/tutorial/Calculator.java

+package com.hascode.tutorial;
+
+public class Calculator {
+	public int square(final int input) {
+		return input * input;
+	}
+}

File src/main/java/com/hascode/tutorial/User.java

-package com.hascode.tutorial;
-
-public class User {
-	private Long id;
-	private String name;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(final Long id) {
-		this.id = id;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(final String name) {
-		this.name = name;
-	}
-
-	public User() {
-	}
-
-	public User(final Long id, final String name) {
-		this.id = id;
-		this.name = name;
-	}
-
-	@Override
-	public int hashCode() {
-		final int prime = 31;
-		int result = 1;
-		result = prime * result + ((id == null) ? 0 : id.hashCode());
-		return result;
-	}
-
-	@Override
-	public boolean equals(final Object obj) {
-		if (this == obj)
-			return true;
-		if (obj == null)
-			return false;
-		if (getClass() != obj.getClass())
-			return false;
-		User other = (User) obj;
-		if (id == null) {
-			if (other.id != null)
-				return false;
-		} else if (!id.equals(other.id))
-			return false;
-		return true;
-	}
-
-	@Override
-	public String toString() {
-		return "User [id=" + id + ", name=" + name + "]";
-	}
-}

File src/main/java/com/hascode/tutorial/UserDao.java

-package com.hascode.tutorial;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class UserDao {
-	final Map<Long, User> userStore = new HashMap<Long, User>();
-	{
-		userStore.put(1l, new User(1l, "Fred"));
-		userStore.put(3l, new User(3l, "Suzie"));
-		userStore.put(5l, new User(5l, "Tim"));
-		userStore.put(666l, new User(666l, "Luzi"));
-		userStore.put(1024l, new User(1024l, "Bob"));
-	}
-
-	public User findById(final Long id) {
-		return userStore.get(id);
-	}
-}

File src/test/java/com/hascode/tutorial/ParameterizedTest.java

 
 @RunWith(Parameterized.class)
 public class ParameterizedTest {
-	@Parameters(name = "Run {index}: findUserById({0})={1}")
+	@Parameters(name = "Run #{index}: {0}^2={1}")
 	public static Iterable<Object[]> data() {
-		return Arrays.asList(new Object[][] { { 1l, new User(1l, "Fred") },
-				{ 3l, new User(3l, "Suzie") }, { 5l, new User(5l, "Tim") },
-				{ 666l, new User(666l, "Luzi") },
-				{ 1024l, new User(1025l, "Bob") } });
+		return Arrays.asList(new Object[][] { { 1, 1 }, { 2, 4 }, { 3, 9 },
+				{ 4, 16 }, { 5, 25 } });
 	}
 
-	private final Long idParam;
-	private final User userParam;
+	private final int input;
+	private final int resultExpected;
 
-	public ParameterizedTest(final Long idParam, final User userParam) {
-		this.idParam = idParam;
-		this.userParam = userParam;
+	public ParameterizedTest(final int input, final int result) {
+		this.input = input;
+		this.resultExpected = result;
 	}
 
 	@Test
 	public void testUserMapping() {
-		UserDao userDao = new UserDao();
-		User user = userDao.findById(idParam);
-		System.err.print(idParam + " :\t");
-		System.err.println(userParam.toString());
-		assertEquals(idParam, user.getId());
-		assertEquals(userParam.getName(), user.getName());
+		Calculator calc = new Calculator();
+		assertEquals(resultExpected, calc.square(input));
 	}
 }

File src/test/java/com/hascode/tutorial/WatcherExampleTest.java

 
 	@Test
 	public void testIgnored() {
-		assumeFalse(true);
+		assumeFalse(true); // assumption fails
 	}
-
 }