-
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.
- Loading branch information
0 parents
commit 63320b5
Showing
4 changed files
with
140 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
target/ | ||
.classpath | ||
.settings/ | ||
.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,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
16
src/main/java/jmockittest/jmockittest/ClassWithFinalMethods.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,16 @@ | ||
/** | ||
* Copyright 2010 Mirko Friedenhagen | ||
*/ | ||
|
||
package jmockittest.jmockittest; | ||
|
||
/** | ||
* @author mirko | ||
* | ||
*/ | ||
public class ClassWithFinalMethods { | ||
|
||
public final String getString() { | ||
return "Hallo"; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/jmockittest/jmockittest/ClassWithFinalMethodsTest.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,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- & Shopping-Portal - kostenlos</title>")); | ||
} | ||
|
||
} |