Skip to content

Commit b790d8c

Browse files
committed
Update tests with newer dependencies versions
1 parent bdb861a commit b790d8c

13 files changed

Lines changed: 122 additions & 124 deletions

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/HttpLibrariesTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import static org.mockito.Matchers.eq;
55
import static org.mockito.Mockito.verify;
66

7+
import androidx.test.platform.app.InstrumentationRegistry;
78
import android.os.Build;
8-
import android.support.annotation.RequiresApi;
9-
import android.support.test.InstrumentationRegistry;
10-
import android.support.test.runner.AndroidJUnit4;
9+
import androidx.annotation.RequiresApi;
10+
1111
import com.datatheorem.android.trustkit.pinning.PinningValidationResult;
1212
import com.datatheorem.android.trustkit.reporting.BackgroundReporter;
1313
import java.io.IOException;
@@ -23,12 +23,10 @@
2323
import okhttp3.Request;
2424
import org.junit.Before;
2525
import org.junit.Test;
26-
import org.junit.runner.RunWith;
2726
import org.mockito.Mock;
2827
import org.mockito.MockitoAnnotations;
2928

3029
@SuppressWarnings("unchecked")
31-
@RunWith(AndroidJUnit4.class)
3230
public class HttpLibrariesTest {
3331

3432
@Mock
@@ -58,7 +56,7 @@ public void testHttpsUrlConnectionWithTrustKit() throws MalformedURLException {
5856
}
5957
// Initialize TrustKit
6058
TestableTrustKit.initializeWithNetworkSecurityConfiguration(
61-
InstrumentationRegistry.getContext(), reporter);
59+
InstrumentationRegistry.getInstrumentation().getContext(), reporter);
6260

6361
// Test a connection
6462
HttpsURLConnection connection = null;
@@ -109,7 +107,7 @@ public void testHttpsUrlConnectionWithTrustKitApiLevelUnder17() throws IOExcepti
109107
}
110108
// Initialize TrustKit
111109
TestableTrustKit.initializeWithNetworkSecurityConfiguration(
112-
InstrumentationRegistry.getContext(), reporter);
110+
InstrumentationRegistry.getInstrumentation().getContext(), reporter);
113111

114112
// Test a connection
115113
// Although the pins are invalid, the connection should succeed because TrustKit's pinning
@@ -145,7 +143,7 @@ public void testOkhttp3WithTrustKit() throws MalformedURLException {
145143
}
146144
// Initialize TrustKit
147145
TestableTrustKit.initializeWithNetworkSecurityConfiguration(
148-
InstrumentationRegistry.getContext(), reporter);
146+
InstrumentationRegistry.getInstrumentation().getContext(), reporter);
149147

150148
// Test a connection
151149
boolean didReceiveHandshakeError = false;
@@ -191,7 +189,7 @@ public void testOkhttp3WithTrustKitOldBuilder() throws MalformedURLException {
191189
}
192190
// Initialize TrustKit
193191
TestableTrustKit.initializeWithNetworkSecurityConfiguration(
194-
InstrumentationRegistry.getContext(), reporter);
192+
InstrumentationRegistry.getInstrumentation().getContext(), reporter);
195193

196194
// Test a connection
197195
boolean didReceiveHandshakeError = false;

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/TestableTrustKit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
import android.content.Context;
5-
import android.support.annotation.NonNull;
6-
import android.support.annotation.Nullable;
5+
import androidx.annotation.NonNull;
6+
import androidx.annotation.Nullable;
77
import com.datatheorem.android.trustkit.config.DomainPinningPolicy;
88
import com.datatheorem.android.trustkit.config.TestableTrustKitConfiguration;
99
import com.datatheorem.android.trustkit.config.TrustKitConfiguration;

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/TrustKitTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.datatheorem.android.trustkit;
22

3-
import static junit.framework.Assert.assertNotNull;
4-
import static junit.framework.Assert.assertTrue;
5-
63
import android.content.Context;
74
import android.content.res.Resources;
85
import android.os.Build;
9-
import android.support.test.InstrumentationRegistry;
10-
import android.support.test.runner.AndroidJUnit4;
6+
7+
import androidx.test.platform.app.InstrumentationRegistry;
8+
119
import com.datatheorem.android.trustkit.config.ConfigurationException;
10+
1211
import org.junit.Before;
1312
import org.junit.Test;
14-
import org.junit.runner.RunWith;
1513

16-
@RunWith(AndroidJUnit4.class)
14+
import static junit.framework.Assert.assertNotNull;
15+
import static junit.framework.Assert.assertTrue;
16+
1717
public class TrustKitTest {
1818

1919
@Before
@@ -23,7 +23,7 @@ public void setUp() {
2323

2424
@Test
2525
public void testInitializeWithDefaultXmlFile() {
26-
Context context = InstrumentationRegistry.getContext();
26+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
2727
TrustKit trustkit = TrustKit.initializeWithNetworkSecurityConfiguration(context);
2828
assertNotNull(trustkit);
2929
assertNotNull(TrustKit.getInstance());
@@ -43,7 +43,7 @@ public void testInitializeWithDefaultXmlFile() {
4343

4444
@Test
4545
public void testInitializeWithValidXmlFile() {
46-
Context context = InstrumentationRegistry.getContext();
46+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
4747
int networkSecurityConfigId = context.getResources().getIdentifier(
4848
"network_security_config", "xml", context.getPackageName());
4949
TrustKit trustkit = TrustKit.initializeWithNetworkSecurityConfiguration(context,
@@ -53,7 +53,7 @@ public void testInitializeWithValidXmlFile() {
5353

5454
@Test
5555
public void testInitializeWithBadResourceId() {
56-
Context context = InstrumentationRegistry.getContext();
56+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
5757

5858
boolean didInitFail = false;
5959
try {
@@ -71,7 +71,7 @@ public void testInitializeWithBadResourceId() {
7171

7272
@Test
7373
public void testInitializeWithBadFile() {
74-
Context context = InstrumentationRegistry.getContext();
74+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
7575
int pemFileId = context.getResources().getIdentifier("cacertorg", "raw",
7676
context.getPackageName());
7777

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/config/DomainPinningPolicyTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package com.datatheorem.android.trustkit.config;
22

33

4-
import static junit.framework.Assert.assertEquals;
5-
import static junit.framework.Assert.assertTrue;
4+
import org.junit.Test;
65

7-
import android.support.test.runner.AndroidJUnit4;
86
import java.net.MalformedURLException;
97
import java.net.URL;
108
import java.util.Date;
119
import java.util.HashSet;
1210
import java.util.Set;
13-
import org.junit.Test;
14-
import org.junit.runner.RunWith;
11+
12+
import static junit.framework.Assert.assertEquals;
13+
import static junit.framework.Assert.assertTrue;
1514

1615

17-
@RunWith(AndroidJUnit4.class)
1816
public class DomainPinningPolicyTest {
1917

2018
private final static Set<String> pins = new HashSet<>();

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/config/PublicKeyPinTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package com.datatheorem.android.trustkit.config;
22

33

4-
import static junit.framework.Assert.assertEquals;
5-
import static junit.framework.Assert.assertTrue;
6-
7-
import android.support.test.runner.AndroidJUnit4;
84
import com.datatheorem.android.trustkit.CertificateUtils;
5+
6+
import org.junit.Test;
7+
98
import java.security.cert.Certificate;
109
import java.security.cert.CertificateException;
11-
import org.junit.Test;
12-
import org.junit.runner.RunWith;
10+
11+
import static junit.framework.Assert.assertEquals;
12+
import static junit.framework.Assert.assertTrue;
1313

1414

15-
@RunWith(AndroidJUnit4.class)
1615
public class PublicKeyPinTest {
1716

1817
@Test

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/config/TestableTrustKitConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.datatheorem.android.trustkit.config;
22

3-
import android.support.annotation.NonNull;
4-
import android.support.annotation.Nullable;
3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
56
import java.security.cert.Certificate;
67
import java.util.Set;
78

trustkit/src/androidTest/java/com/datatheorem/android/trustkit/config/TrustKitConfigurationTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.datatheorem.android.trustkit.config;
22

3-
import static junit.framework.Assert.assertEquals;
4-
import static junit.framework.Assert.assertFalse;
5-
import static junit.framework.Assert.assertNotNull;
6-
import static junit.framework.Assert.assertNull;
7-
import static junit.framework.Assert.assertTrue;
8-
93
import android.content.Context;
10-
import android.support.test.InstrumentationRegistry;
11-
import android.support.test.runner.AndroidJUnit4;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
7+
import org.junit.Test;
8+
import org.xmlpull.v1.XmlPullParser;
9+
import org.xmlpull.v1.XmlPullParserException;
10+
import org.xmlpull.v1.XmlPullParserFactory;
11+
1212
import java.io.IOException;
1313
import java.io.InputStream;
1414
import java.io.StringReader;
@@ -21,13 +21,13 @@
2121
import java.util.Date;
2222
import java.util.HashSet;
2323
import java.util.Locale;
24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
26-
import org.xmlpull.v1.XmlPullParser;
27-
import org.xmlpull.v1.XmlPullParserException;
28-
import org.xmlpull.v1.XmlPullParserFactory;
2924

30-
@RunWith(AndroidJUnit4.class)
25+
import static junit.framework.Assert.assertEquals;
26+
import static junit.framework.Assert.assertFalse;
27+
import static junit.framework.Assert.assertNotNull;
28+
import static junit.framework.Assert.assertNull;
29+
import static junit.framework.Assert.assertTrue;
30+
3131
public class TrustKitConfigurationTest {
3232

3333
private XmlPullParser parseXmlString(String xmlString) throws XmlPullParserException {
@@ -42,7 +42,7 @@ private XmlPullParser parseXmlString(String xmlString) throws XmlPullParserExcep
4242

4343
@Test
4444
public void testBadHostnameValidation() throws XmlPullParserException, IOException, CertificateException {
45-
Context context = InstrumentationRegistry.getContext();
45+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
4646
String xml = "" +
4747
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
4848
"<network-security-config>\n" +
@@ -70,7 +70,7 @@ public void testBadHostnameValidation() throws XmlPullParserException, IOExcepti
7070
@Test
7171
public void testDefaultValues() throws XmlPullParserException, IOException, ParseException,
7272
CertificateException {
73-
Context context = InstrumentationRegistry.getContext();
73+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
7474
String xml = "" +
7575
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
7676
"<network-security-config>\n" +
@@ -114,7 +114,7 @@ public void testDefaultValues() throws XmlPullParserException, IOException, Pars
114114
@Test
115115
public void testIncludeSubdomainsAndNoTrustkitTag() throws XmlPullParserException, IOException,
116116
ParseException, CertificateException {
117-
Context context = InstrumentationRegistry.getContext();
117+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
118118
String xml = "" +
119119
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
120120
"<network-security-config>\n" +
@@ -148,7 +148,7 @@ public void testIncludeSubdomainsAndNoTrustkitTag() throws XmlPullParserExceptio
148148
@Test
149149
public void testEnforcePinning() throws XmlPullParserException, IOException,
150150
ParseException, CertificateException {
151-
Context context = InstrumentationRegistry.getContext();
151+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
152152
String xml = "" +
153153
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
154154
"<network-security-config>\n" +
@@ -174,7 +174,7 @@ public void testEnforcePinning() throws XmlPullParserException, IOException,
174174
@Test
175175
public void testExpirationDate() throws XmlPullParserException, IOException,
176176
ParseException, CertificateException {
177-
Context context = InstrumentationRegistry.getContext();
177+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
178178
String xml = "" +
179179
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
180180
"<network-security-config>\n" +
@@ -199,7 +199,7 @@ public void testExpirationDate() throws XmlPullParserException, IOException,
199199
@Test
200200
public void testDisableDefaultReportUri() throws XmlPullParserException, IOException,
201201
ParseException, CertificateException {
202-
Context context = InstrumentationRegistry.getContext();
202+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
203203
String xml = "" +
204204
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
205205
"<network-security-config>\n" +
@@ -225,7 +225,7 @@ public void testDisableDefaultReportUri() throws XmlPullParserException, IOExcep
225225
@Test
226226
public void testDebugOverrides() throws XmlPullParserException, IOException,
227227
ParseException, CertificateException {
228-
Context context = InstrumentationRegistry.getContext();
228+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
229229
String xml = "" +
230230
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
231231
"<network-security-config>\n" +
@@ -272,7 +272,7 @@ public void testDebugOverrides() throws XmlPullParserException, IOException,
272272
@Test
273273
public void testNestedDomainConfig() throws XmlPullParserException, IOException,
274274
ParseException, CertificateException {
275-
Context context = InstrumentationRegistry.getContext();
275+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
276276
String xml = "" +
277277
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
278278
"<network-security-config>\n" +
@@ -354,7 +354,7 @@ public void testNestedDomainConfig() throws XmlPullParserException, IOException,
354354
@Test
355355
public void testIgnoreDomainWithNoPins(
356356
) throws XmlPullParserException, IOException, CertificateException {
357-
Context context = InstrumentationRegistry.getContext();
357+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
358358
// Given a valid network security config
359359
String xml = "" +
360360
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
@@ -391,7 +391,7 @@ context, parseXmlString(xml)
391391
@Test
392392
public void testAllowsEmptyPinningConfig(
393393
) throws XmlPullParserException, IOException, CertificateException {
394-
Context context = InstrumentationRegistry.getContext();
394+
Context context = InstrumentationRegistry.getInstrumentation().getContext();
395395
// Given a valid network security config that has no entries related to pinning
396396
String xml = "" +
397397
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +

0 commit comments

Comments
 (0)