Skip to content

Commit 2a309bd

Browse files
author
Luis Miranda
committed
issue #52: removed PowerMock agents as they are not needed and break badly in JDK8
1 parent 8876430 commit 2a309bd

14 files changed

Lines changed: 7 additions & 108 deletions

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,4 @@ Select a Tomcat Server in order to deploy the server.
3636

3737
### Unit Tests
3838

39-
Known issues while testing:
40-
41-
* [ECLEmma coverage plugin incompatible with PowerMock](http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue)
42-
43-
* When using @PrepareForTest and PowerMockito the breakpoints not does [not stop when debugging](http://stackoverflow.com/questions/35140575/powermockito-junit-and-eclemma-debugging-dosent-work). The solution is define Rules.
44-
45-
* Java7+ enforces bytecode verification and with Powermock you can experience a [java.lang.VerifyError](http://www.notonlyanecmplace.com/java-7-enforces-bytecode-verification/).
46-
At Java8 bytecode verification is mandatory and there is no option to disable it :(
39+
The unit tests use PowerMock but do not run with the PowerMock javaagents enabled. This means you will not be able to mock out static methods, but other PowerMock features will work.

core/pom.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@
3030
<version>1.6.2</version>
3131
<scope>test</scope>
3232
</dependency>
33-
<dependency>
34-
<groupId>org.powermock</groupId>
35-
<artifactId>powermock-module-javaagent</artifactId>
36-
<version>1.6.0</version>
37-
<scope>test</scope>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.powermock</groupId>
41-
<artifactId>powermock-module-junit4-rule-agent</artifactId>
42-
<version>1.6.4</version>
43-
<scope>test</scope>
44-
</dependency>
4533

4634
<!-- for log -->
4735
<dependency>
@@ -111,7 +99,7 @@
11199
<artifactId>maven-surefire-plugin</artifactId>
112100
<version>2.12</version>
113101
<configuration>
114-
<argLine>-XX:-UseSplitVerifier ${jacoco.agent.argLine}</argLine>
102+
<argLine>${jacoco.agent.argLine}</argLine>
115103
</configuration>
116104
</plugin>
117105
</plugins>

core/src/test/java/com/onelogin/saml2/test/AuthTest.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,17 @@
3232
import javax.servlet.http.HttpSession;
3333

3434
import org.junit.Test;
35-
import org.junit.runner.RunWith;
36-
import org.powermock.core.classloader.annotations.PrepareForTest;
3735

3836
import com.onelogin.saml2.Auth;
39-
import com.onelogin.saml2.authn.SamlResponse;
4037
import com.onelogin.saml2.exception.SettingsException;
4138
import com.onelogin.saml2.exception.XMLEntityException;
4239
import com.onelogin.saml2.settings.Saml2Settings;
4340
import com.onelogin.saml2.settings.SettingsBuilder;
4441
import com.onelogin.saml2.util.Constants;
4542
import com.onelogin.saml2.util.Util;
4643

47-
/*
48-
* Known issues while testing
49-
*
50-
* ECLEmma coverage plugin incompatible with PowerMock
51-
* http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue
52-
*
53-
* import org.junit.runner.RunWith;
54-
* import org.powermock.modules.junit4.PowerMockRunner;
55-
* @RunWith(PowerMockRunner.class)
56-
*
57-
*/
58-
@PrepareForTest({Auth.class})
5944
public class AuthTest {
6045

61-
/*
62-
* When using @PrepareForTest and PowerMockito the breakpoints when debugging
63-
* does not work. Define Rules!
64-
* (http://stackoverflow.com/questions/35140575/powermockito-junit-and-eclemma-debugging-dosent-work)
65-
*
66-
* https://github.com/jayway/powermock/wiki/PowerMockRule
67-
*
68-
* import org.junit.Rule;
69-
* import org.powermock.modules.junit4.rule.PowerMockRule;
70-
* @Rule
71-
* public PowerMockRule rule = new PowerMockRule();
72-
*
73-
*/
74-
75-
//import org.powermock.modules.junit4.rule.PowerMockRule;
76-
//@Rule
77-
//public PowerMockRule rule = new PowerMockRule();
78-
7946
/**
8047
* Tests the constructor of Auth
8148
* Case: No parameters

core/src/test/java/com/onelogin/saml2/test/MetadataTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.security.cert.CertificateEncodingException;
1313
import java.util.Calendar;
1414

15-
import org.powermock.core.classloader.annotations.PrepareForTest;
1615
import org.w3c.dom.Document;
1716
import org.junit.Test;
1817

@@ -25,7 +24,6 @@
2524
/**
2625
* Tests the com.onelogin.saml2.Metadata class
2726
*/
28-
@PrepareForTest({Metadata.class})
2927
public class MetadataTest {
3028
/**
3129
* Tests the constructor method of Metadata

core/src/test/java/com/onelogin/saml2/test/authn/AuthnRequestTest.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,22 @@
44
import static org.hamcrest.CoreMatchers.not;
55
import static org.junit.Assert.assertEquals;
66
import static org.junit.Assert.assertThat;
7-
import static org.mockito.Mockito.mock;
8-
import static org.mockito.Mockito.verify;
9-
import static org.mockito.Mockito.when;
107
import static org.powermock.api.mockito.PowerMockito.when;
118
import static org.powermock.api.support.membermodification.MemberMatcher.method;
129

1310
import java.util.ArrayList;
14-
import java.util.HashMap;
1511
import java.util.List;
16-
import java.util.Map;
1712

18-
import javax.servlet.http.HttpServletRequest;
19-
import javax.servlet.http.HttpServletResponse;
20-
21-
import org.junit.Rule;
2213
import org.junit.Test;
2314
import org.powermock.api.mockito.PowerMockito;
24-
import org.powermock.core.classloader.annotations.PrepareForTest;
25-
//import org.powermock.modules.junit4.PowerMockRunner;
26-
import org.powermock.modules.junit4.rule.PowerMockRule;
2715

2816
import com.onelogin.saml2.authn.AuthnRequest;
2917
import com.onelogin.saml2.settings.Saml2Settings;
3018
import com.onelogin.saml2.settings.SettingsBuilder;
3119
import com.onelogin.saml2.util.Util;
3220

33-
@PrepareForTest({AuthnRequest.class})
3421
public class AuthnRequestTest {
3522

36-
@Rule
37-
public PowerMockRule rule = new PowerMockRule();
38-
3923
/**
4024
* Tests the getEncodedAuthnRequest method of AuthnRequest
4125
*
@@ -278,4 +262,4 @@ public void testAuthNDestination() throws Exception {
278262
assertThat(authnRequestStr, containsString("<samlp:AuthnRequest"));
279263
assertThat(authnRequestStr, not(containsString("Destination=\"http://idp.example.com/simplesaml/saml2/idp/SSOService.php\"")));
280264
}
281-
}
265+
}

core/src/test/java/com/onelogin/saml2/test/authn/AuthnResponseTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import org.junit.Rule;
2020
import org.junit.Test;
21-
import org.powermock.core.classloader.annotations.PrepareForTest;
22-
import org.powermock.modules.junit4.rule.PowerMockRule;
2321
import org.w3c.dom.Document;
2422
import org.w3c.dom.Node;
2523
import org.w3c.dom.NodeList;
@@ -31,12 +29,8 @@
3129
import com.onelogin.saml2.util.Util;
3230
import com.onelogin.saml2.util.Constants;
3331

34-
@PrepareForTest({SamlResponse.class})
3532
public class AuthnResponseTest {
36-
37-
@Rule
38-
public PowerMockRule rule = new PowerMockRule();
39-
33+
4034
/**
4135
* Tests the constructor of SamlResponse
4236
*

core/src/test/java/com/onelogin/saml2/test/logout/LogoutRequestTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,20 @@
2121

2222
import java.security.PrivateKey;
2323

24+
import org.powermock.api.mockito.PowerMockito;
2425
import org.w3c.dom.Document;
2526

2627
import org.junit.Rule;
2728
import org.junit.Test;
28-
import org.powermock.api.mockito.PowerMockito;
29-
import org.powermock.core.classloader.annotations.PrepareForTest;
30-
import org.powermock.modules.junit4.rule.PowerMockRule;
3129

3230
import com.onelogin.saml2.exception.XMLEntityException;
3331
import com.onelogin.saml2.logout.LogoutRequest;
3432
import com.onelogin.saml2.settings.Saml2Settings;
3533
import com.onelogin.saml2.settings.SettingsBuilder;
3634
import com.onelogin.saml2.util.Util;
3735

38-
@PrepareForTest({LogoutRequest.class})
3936
public class LogoutRequestTest {
4037

41-
@Rule
42-
public PowerMockRule rule = new PowerMockRule();
43-
4438
/**
4539
* Tests the constructor and the getEncodedLogoutRequest method of LogoutRequest
4640
*
@@ -701,4 +695,4 @@ public void testGetError() throws URISyntaxException, IOException, XMLEntityExce
701695
logoutRequest.isValid();
702696
assertNull(logoutRequest.getError());
703697
}
704-
}
698+
}

core/src/test/java/com/onelogin/saml2/test/logout/LogoutResponseTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
import javax.servlet.http.HttpServletRequest;
1818
import javax.xml.xpath.XPathExpressionException;
1919

20-
import org.junit.Rule;
2120
import org.junit.Test;
2221
import org.powermock.api.mockito.PowerMockito;
23-
import org.powermock.core.classloader.annotations.PrepareForTest;
24-
import org.powermock.modules.junit4.rule.PowerMockRule;
2522

2623
import com.onelogin.saml2.exception.XMLEntityException;
2724
import com.onelogin.saml2.logout.LogoutResponse;
@@ -30,12 +27,8 @@
3027
import com.onelogin.saml2.util.Util;
3128
import com.onelogin.saml2.util.Constants;
3229

33-
@PrepareForTest({LogoutResponse.class})
3430
public class LogoutResponseTest {
3531

36-
@Rule
37-
public PowerMockRule rule = new PowerMockRule();
38-
3932
/**
4033
* Tests the constructor, the build and the getEncodedLogoutResponse method of LogoutResponse
4134
*
@@ -501,4 +494,4 @@ public void testGetError() throws URISyntaxException, IOException, XMLEntityExce
501494
logoutResponse.isValid();
502495
assertNull(logoutResponse.getError());
503496
}
504-
}
497+
}

core/src/test/java/com/onelogin/saml2/test/model/ContactTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.onelogin.saml2.test.model;
22

33
import org.junit.Test;
4-
import org.powermock.core.classloader.annotations.PrepareForTest;
54

65
import static org.junit.Assert.assertEquals;
76

@@ -10,7 +9,6 @@
109
/**
1110
* Tests the com.onelogin.saml2.model.Contact class
1211
*/
13-
@PrepareForTest({Contact.class})
1412
public class ContactTest {
1513

1614
/**

core/src/test/java/com/onelogin/saml2/test/model/OrganizationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.net.URL;
55

66
import org.junit.Test;
7-
import org.powermock.core.classloader.annotations.PrepareForTest;
87

98
import static org.junit.Assert.assertEquals;
109
import static org.junit.Assert.assertFalse;
@@ -15,7 +14,6 @@
1514
/**
1615
* Tests the com.onelogin.saml2.model.Organization class
1716
*/
18-
@PrepareForTest({Organization.class})
1917
public class OrganizationTest {
2018

2119
/**

0 commit comments

Comments
 (0)