diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e5303e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/ +.classpath +.settings/ +.project + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..56bbb63 --- /dev/null +++ b/pom.xml @@ -0,0 +1,52 @@ + + 4.0.0 + + jmockittest + jmockittest + 0.0.1-SNAPSHOT + jar + + jmockittest + http://maven.apache.org + + + UTF-8 + + + + + org.apache.httpcomponents + httpclient + 4.0.3 + test + + + mockit + jmockit + 0.999.3 + test + + + junit + junit + 4.8.2 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + + diff --git a/src/main/java/jmockittest/jmockittest/ClassWithFinalMethods.java b/src/main/java/jmockittest/jmockittest/ClassWithFinalMethods.java new file mode 100644 index 0000000..1ca616e --- /dev/null +++ b/src/main/java/jmockittest/jmockittest/ClassWithFinalMethods.java @@ -0,0 +1,16 @@ +/** + * Copyright 2010 Mirko Friedenhagen + */ + +package jmockittest.jmockittest; + +/** + * @author mirko + * + */ +public class ClassWithFinalMethods { + + public final String getString() { + return "Hallo"; + } +} diff --git a/src/test/java/jmockittest/jmockittest/ClassWithFinalMethodsTest.java b/src/test/java/jmockittest/jmockittest/ClassWithFinalMethodsTest.java new file mode 100644 index 0000000..a558951 --- /dev/null +++ b/src/test/java/jmockittest/jmockittest/ClassWithFinalMethodsTest.java @@ -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("GMX - E-Mail, FreeMail, De-Mail, Themen- & Shopping-Portal - kostenlos")); + } + +}