Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriedenhagen committed Oct 31, 2010
0 parents commit 63320b5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target/
.classpath
.settings/
.project

52 changes: 52 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>jmockittest</groupId>
<artifactId>jmockittest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jmockittest</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mockit</groupId>
<artifactId>jmockit</artifactId>
<version>0.999.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
16 changes: 16 additions & 0 deletions src/main/java/jmockittest/jmockittest/ClassWithFinalMethods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2010 Mirko Friedenhagen
*/

package jmockittest.jmockittest;

/**
* @author mirko
*
*/
public class ClassWithFinalMethods {

public final String getString() {
return "Hallo";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright 2010 Mirko Friedenhagen
*/

package jmockittest.jmockittest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import mockit.Expectations;
import mockit.Mocked;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;

/**
* @author mirko
*
*/
public class ClassWithFinalMethodsTest {

@Mocked
ClassWithFinalMethods mock;

/**
* Test method for {@link jmockittest.jmockittest.ClassWithFinalMethods#getString()}.
*/
@Test
public void testGetString() {
new Expectations() {
{
mock.getString();
result = "Hullo";
}
};
assertEquals("Hullo", mock.getString());
}

@Test
public void getGmxHomePage() throws URISyntaxException, ClientProtocolException, IOException {
final HttpClient client = new DefaultHttpClient();
final String homepage = "https://www.gmx.net/";
new Expectations() {
{
mock.getString();
result = homepage;
}
};
final HttpGet get = new HttpGet(mock.getString());
final URI actualURI = get.getURI();
assertEquals(new URI(homepage), actualURI);
final String html = client.execute(get, new BasicResponseHandler());
assertThat(
html,
containsString("<title>GMX - E-Mail, FreeMail, De-Mail, Themen- &amp; Shopping-Portal - kostenlos</title>"));
}

}

0 comments on commit 63320b5

Please sign in to comment.