Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfe3e14a

Browse files
committed
switch to assertThrows from@test(expected = ...) in unit tests
1 parent5a0df76 commitfe3e14a

11 files changed

+188
-64
lines changed

‎scribejava-core/src/test/java/com/github/scribejava/core/extractors/BaseStringExtractorTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
importcom.github.scribejava.core.exceptions.OAuthParametersMissingException;
88
importcom.github.scribejava.core.model.OAuthRequest;
99
importcom.github.scribejava.core.model.Verb;
10+
importstaticorg.junit.Assert.assertThrows;
11+
importorg.junit.function.ThrowingRunnable;
1012

1113
publicclassBaseStringExtractorTest {
1214

@@ -83,15 +85,23 @@ public void shouldExcludePort443v2() {
8385
assertEquals(expected,baseString);
8486
}
8587

86-
@Test(expected =IllegalArgumentException.class)
8788
publicvoidshouldThrowExceptionIfRquestIsNull() {
88-
extractor.extract(null);
89+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
90+
@Override
91+
publicvoidrun()throwsThrowable {
92+
extractor.extract(null);
93+
}
94+
});
8995
}
9096

91-
@Test(expected =OAuthParametersMissingException.class)
9297
publicvoidshouldThrowExceptionIfRquestHasNoOAuthParameters() {
9398
finalOAuthRequestrequest =newOAuthRequest(Verb.GET,"http://example.com");
94-
extractor.extract(request);
99+
assertThrows(OAuthParametersMissingException.class,newThrowingRunnable() {
100+
@Override
101+
publicvoidrun()throwsThrowable {
102+
extractor.extract(request);
103+
}
104+
});
95105
}
96106

97107
@Test

‎scribejava-core/src/test/java/com/github/scribejava/core/extractors/HeaderExtractorTest.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
importstaticorg.junit.Assert.assertEquals;
44
importstaticorg.junit.Assert.assertTrue;
5+
importstaticorg.junit.Assert.assertThrows;
56
importorg.junit.Before;
67
importorg.junit.Test;
78
importcom.github.scribejava.core.exceptions.OAuthParametersMissingException;
89
importcom.github.scribejava.core.model.OAuthRequest;
910
importcom.github.scribejava.core.model.Verb;
1011
importcom.github.scribejava.core.ObjectMother;
12+
importorg.junit.function.ThrowingRunnable;
1113

1214
publicclassHeaderExtractorTest {
1315

@@ -36,21 +38,29 @@ public void shouldExtractStandardHeader() {
3638
assertTrue(header.contains(timestamp));
3739
// Assert that header only contains the checked elements above and nothing else
3840
assertEquals(", , , ",
39-
header.replaceFirst(oauth,"")
40-
.replaceFirst(callback,"")
41-
.replaceFirst(signature,"")
42-
.replaceFirst(key,"")
43-
.replaceFirst(timestamp,""));
41+
header.replaceFirst(oauth,"")
42+
.replaceFirst(callback,"")
43+
.replaceFirst(signature,"")
44+
.replaceFirst(key,"")
45+
.replaceFirst(timestamp,""));
4446
}
4547

46-
@Test(expected =IllegalArgumentException.class)
4748
publicvoidshouldExceptionIfRequestIsNull() {
48-
extractor.extract(null);
49+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
50+
@Override
51+
publicvoidrun()throwsThrowable {
52+
extractor.extract(null);
53+
}
54+
});
4955
}
5056

51-
@Test(expected =OAuthParametersMissingException.class)
5257
publicvoidshouldExceptionIfRequestHasNoOAuthParams() {
5358
finalOAuthRequestemptyRequest =newOAuthRequest(Verb.GET,"http://example.com");
54-
extractor.extract(emptyRequest);
59+
assertThrows(OAuthParametersMissingException.class,newThrowingRunnable() {
60+
@Override
61+
publicvoidrun()throwsThrowable {
62+
extractor.extract(emptyRequest);
63+
}
64+
});
5565
}
5666
}

‎scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth1AccessTokenExtractorTest.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
importjava.util.Collections;
1111

1212
importstaticorg.junit.Assert.assertEquals;
13+
importstaticorg.junit.Assert.assertThrows;
14+
importorg.junit.function.ThrowingRunnable;
1315

1416
publicclassOAuth1AccessTokenExtractorTest {
1517

@@ -65,34 +67,50 @@ public void shouldExtractTokenWithEmptySecret() throws IOException {
6567
assertEquals("",extracted.getTokenSecret());
6668
}
6769

68-
@Test(expected =OAuthException.class)
6970
publicvoidshouldThrowExceptionIfTokenIsAbsent()throwsIOException {
7071
finalStringresponseBody ="oauth_secret=hh5s93j4hdidpola&callback_confirmed=true";
7172
try (Responseresponse =ok(responseBody)) {
72-
extractor.extract(response);
73+
assertThrows(OAuthException.class,newThrowingRunnable() {
74+
@Override
75+
publicvoidrun()throwsThrowable {
76+
extractor.extract(response);
77+
}
78+
});
7379
}
7480
}
7581

76-
@Test(expected =OAuthException.class)
7782
publicvoidshouldThrowExceptionIfSecretIsAbsent()throwsIOException {
7883
finalStringresponseBody ="oauth_token=hh5s93j4hdidpola&callback_confirmed=true";
7984
try (Responseresponse =ok(responseBody)) {
80-
extractor.extract(response);
85+
assertThrows(OAuthException.class,newThrowingRunnable() {
86+
@Override
87+
publicvoidrun()throwsThrowable {
88+
extractor.extract(response);
89+
}
90+
});
8191
}
8292
}
8393

84-
@Test(expected =IllegalArgumentException.class)
8594
publicvoidshouldThrowExceptionIfResponseIsNull()throwsIOException {
8695
try (Responseresponse =ok(null)) {
87-
extractor.extract(response);
96+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
97+
@Override
98+
publicvoidrun()throwsThrowable {
99+
extractor.extract(response);
100+
}
101+
});
88102
}
89103
}
90104

91-
@Test(expected =IllegalArgumentException.class)
92105
publicvoidshouldThrowExceptionIfResponseIsEmptyString()throwsIOException {
93106
finalStringresponseBody ="";
94107
try (Responseresponse =ok(responseBody)) {
95-
extractor.extract(response);
108+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
109+
@Override
110+
publicvoidrun()throwsThrowable {
111+
extractor.extract(response);
112+
}
113+
});
96114
}
97115
}
98116

‎scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenExtractorTest.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
importjava.util.Collections;
1111

1212
importstaticorg.junit.Assert.assertEquals;
13+
importstaticorg.junit.Assert.assertThrows;
14+
importorg.junit.function.ThrowingRunnable;
1315

1416
publicclassOAuth2AccessTokenExtractorTest {
1517

@@ -70,34 +72,50 @@ public void shouldExtractTokenFromResponseWithManyParameters() throws IOExceptio
7072
assertEquals("foo1234",extracted.getAccessToken());
7173
}
7274

73-
@Test(expected =OAuthException.class)
7475
publicvoidshouldThrowExceptionIfErrorResponse()throwsIOException {
7576
finalStringresponseBody ="";
7677
try (Responseresponse =error(responseBody)) {
77-
extractor.extract(response);
78+
assertThrows(OAuthException.class,newThrowingRunnable() {
79+
@Override
80+
publicvoidrun()throwsThrowable {
81+
extractor.extract(response);
82+
}
83+
});
7884
}
7985
}
8086

81-
@Test(expected =OAuthException.class)
8287
publicvoidshouldThrowExceptionIfTokenIsAbsent()throwsIOException {
8388
finalStringresponseBody ="&expires=5108";
8489
try (Responseresponse =ok(responseBody)) {
85-
extractor.extract(response);
90+
assertThrows(OAuthException.class,newThrowingRunnable() {
91+
@Override
92+
publicvoidrun()throwsThrowable {
93+
extractor.extract(response);
94+
}
95+
});
8696
}
8797
}
8898

89-
@Test(expected =IllegalArgumentException.class)
9099
publicvoidshouldThrowExceptionIfResponseIsNull()throwsIOException {
91100
try (Responseresponse =ok(null)) {
92-
extractor.extract(response);
101+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
102+
@Override
103+
publicvoidrun()throwsThrowable {
104+
extractor.extract(response);
105+
}
106+
});
93107
}
94108
}
95109

96-
@Test(expected =IllegalArgumentException.class)
97110
publicvoidshouldThrowExceptionIfResponseIsEmptyString()throwsIOException {
98111
finalStringresponseBody ="";
99112
try (Responseresponse =ok(responseBody)) {
100-
extractor.extract(response);
113+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
114+
@Override
115+
publicvoidrun()throwsThrowable {
116+
extractor.extract(response);
117+
}
118+
});
101119
}
102120
}
103121

‎scribejava-core/src/test/java/com/github/scribejava/core/extractors/OAuth2AccessTokenJsonExtractorTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,26 @@ public void shouldParseScopeFromResponse() throws IOException {
6363
assertEquals("refresh_token1",token3.getRefreshToken());
6464
}
6565

66-
@Test(expected =IllegalArgumentException.class)
6766
publicvoidshouldThrowExceptionIfForNullParameters()throwsIOException {
6867
try (Responseresponse =ok(null)) {
69-
extractor.extract(response);
68+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
69+
@Override
70+
publicvoidrun()throwsThrowable {
71+
extractor.extract(response);
72+
}
73+
});
7074
}
7175
}
7276

73-
@Test(expected =IllegalArgumentException.class)
7477
publicvoidshouldThrowExceptionIfForEmptyStrings()throwsIOException {
7578
finalStringresponseBody ="";
7679
try (Responseresponse =ok(responseBody)) {
77-
extractor.extract(response);
80+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
81+
@Override
82+
publicvoidrun()throwsThrowable {
83+
extractor.extract(response);
84+
}
85+
});
7886
}
7987
}
8088

‎scribejava-core/src/test/java/com/github/scribejava/core/model/OAuthRequestTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
packagecom.github.scribejava.core.model;
22

33
importstaticorg.junit.Assert.assertEquals;
4+
importstaticorg.junit.Assert.assertThrows;
45
importstaticorg.junit.Assert.assertTrue;
56
importorg.junit.Before;
67
importorg.junit.Test;
8+
importorg.junit.function.ThrowingRunnable;
79

810
publicclassOAuthRequestTest {
911

@@ -25,9 +27,13 @@ public void shouldAddOAuthParamters() {
2527
assertEquals(5,request.getOauthParameters().size());
2628
}
2729

28-
@Test(expected =IllegalArgumentException.class)
2930
publicvoidshouldThrowExceptionIfParameterIsNotOAuth() {
30-
request.addOAuthParameter("otherParam","value");
31+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
32+
@Override
33+
publicvoidrun()throwsThrowable {
34+
request.addOAuthParameter("otherParam","value");
35+
}
36+
});
3137
}
3238

3339
@Test

‎scribejava-core/src/test/java/com/github/scribejava/core/model/ParameterListTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
importorg.junit.Test;
66

77
importstaticorg.junit.Assert.assertNotSame;
8+
importstaticorg.junit.Assert.assertThrows;
9+
importorg.junit.function.ThrowingRunnable;
810

911
publicclassParameterListTest {
1012

@@ -15,9 +17,13 @@ public void setUp() {
1517
this.params =newParameterList();
1618
}
1719

18-
@Test(expected =IllegalArgumentException.class)
1920
publicvoidshouldThrowExceptionWhenAppendingNullMapToQuerystring() {
20-
params.appendTo(null);
21+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
22+
@Override
23+
publicvoidrun()throwsThrowable {
24+
params.appendTo(null);
25+
}
26+
});
2127
}
2228

2329
@Test

‎scribejava-core/src/test/java/com/github/scribejava/core/services/HMACSha1SignatureServiceTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
importorg.junit.Before;
55
importorg.junit.Test;
66
importcom.github.scribejava.core.exceptions.OAuthException;
7+
importstaticorg.junit.Assert.assertThrows;
8+
importorg.junit.function.ThrowingRunnable;
79

810
publicclassHMACSha1SignatureServiceTest {
911

@@ -29,19 +31,31 @@ public void shouldReturnSignature() {
2931
assertEquals(signature,service.getSignature(baseString,apiSecret,tokenSecret));
3032
}
3133

32-
@Test(expected =OAuthException.class)
3334
publicvoidshouldThrowExceptionIfBaseStringIsNull() {
34-
service.getSignature(null,"apiSecret","tokenSecret");
35+
assertThrows(OAuthException.class,newThrowingRunnable() {
36+
@Override
37+
publicvoidrun()throwsThrowable {
38+
service.getSignature(null,"apiSecret","tokenSecret");
39+
}
40+
});
3541
}
3642

37-
@Test(expected =OAuthException.class)
3843
publicvoidshouldThrowExceptionIfBaseStringIsEmpty() {
39-
service.getSignature(" ","apiSecret","tokenSecret");
44+
assertThrows(OAuthException.class,newThrowingRunnable() {
45+
@Override
46+
publicvoidrun()throwsThrowable {
47+
service.getSignature(" ","apiSecret","tokenSecret");
48+
}
49+
});
4050
}
4151

42-
@Test(expected =OAuthException.class)
4352
publicvoidshouldThrowExceptionIfApiSecretIsNull() {
44-
service.getSignature("base string",null,"tokenSecret");
53+
assertThrows(OAuthException.class,newThrowingRunnable() {
54+
@Override
55+
publicvoidrun()throwsThrowable {
56+
service.getSignature("base string",null,"tokenSecret");
57+
}
58+
});
4559
}
4660

4761
publicvoidshouldNotThrowExceptionIfApiSecretIsEmpty() {

‎scribejava-core/src/test/java/com/github/scribejava/core/utils/OAuthEncoderTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
packagecom.github.scribejava.core.utils;
22

33
importstaticorg.junit.Assert.assertEquals;
4+
importstaticorg.junit.Assert.assertThrows;
45
importorg.junit.Test;
6+
importorg.junit.function.ThrowingRunnable;
57

68
publicclassOAuthEncoderTest {
79

@@ -34,14 +36,22 @@ public void shouldNotPercentEncodeReservedCharacters() {
3436
assertEquals(encoded,OAuthEncoder.encode(plain));
3537
}
3638

37-
@Test(expected =IllegalArgumentException.class)
3839
publicvoidshouldThrowExceptionIfStringToEncodeIsNull() {
39-
OAuthEncoder.encode(null);
40+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
41+
@Override
42+
publicvoidrun()throwsThrowable {
43+
OAuthEncoder.encode(null);
44+
}
45+
});
4046
}
4147

42-
@Test(expected =IllegalArgumentException.class)
4348
publicvoidshouldThrowExceptionIfStringToDecodeIsNull() {
44-
OAuthEncoder.decode(null);
49+
assertThrows(IllegalArgumentException.class,newThrowingRunnable() {
50+
@Override
51+
publicvoidrun()throwsThrowable {
52+
OAuthEncoder.decode(null);
53+
}
54+
});
4555
}
4656

4757
@Test

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp