Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zhangyd-c/JustAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Aug 6, 2019
2 parents 48a368b + 31c9832 commit 1fb8be6
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/test/java/me/zhyd/oauth/AuthRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void giteeTest() {
AuthRequest authRequest = new AuthGiteeRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -30,7 +30,7 @@ public void githubTest() {
AuthRequest authRequest = new AuthGithubRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -44,7 +44,7 @@ public void weiboTest() {
AuthRequest authRequest = new AuthWeiboRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -58,7 +58,7 @@ public void dingdingTest() {
AuthRequest authRequest = new AuthDingTalkRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -72,7 +72,7 @@ public void baiduTest() {
AuthRequest authRequest = new AuthBaiduRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -86,7 +86,7 @@ public void codingTest() {
AuthRequest authRequest = new AuthCodingRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -100,7 +100,7 @@ public void tencentCloudTest() {
AuthRequest authRequest = new AuthTencentCloudRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -114,7 +114,7 @@ public void oschinaTest() {
AuthRequest authRequest = new AuthOschinaRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -128,7 +128,7 @@ public void alipayTest() {
AuthRequest authRequest = new AuthAlipayRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.alipayPublicKey("publicKey")
.build());
// 返回授权页面,可自行跳转
Expand All @@ -143,7 +143,7 @@ public void qqTest() {
AuthRequest authRequest = new AuthQqRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -157,7 +157,7 @@ public void wechatTest() {
AuthRequest authRequest = new AuthWeChatRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -171,7 +171,7 @@ public void taobaoTest() {
AuthRequest authRequest = new AuthTaobaoRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -185,7 +185,7 @@ public void googleTest() {
AuthRequest authRequest = new AuthGoogleRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -199,7 +199,7 @@ public void facebookTest() {
AuthRequest authRequest = new AuthFacebookRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("https://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -213,7 +213,7 @@ public void douyinTest() {
AuthRequest authRequest = new AuthDouyinRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -227,7 +227,7 @@ public void linkedinTest() {
AuthRequest authRequest = new AuthLinkedinRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -241,7 +241,7 @@ public void microsoftTest() {
AuthRequest authRequest = new AuthMicrosoftRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -255,7 +255,7 @@ public void miTest() {
AuthRequest authRequest = new AuthMiRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand All @@ -269,7 +269,7 @@ public void toutiaoTest() {
AuthRequest authRequest = new AuthToutiaoRequest(AuthConfig.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.redirectUri("redirectUri")
.redirectUri("http://redirectUri")
.build());
// 返回授权页面,可自行跳转
authRequest.authorize("state");
Expand Down
93 changes: 93 additions & 0 deletions src/test/java/me/zhyd/oauth/utils/StringUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package me.zhyd.oauth.utils;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class StringUtilsTest {
@Rule public final ExpectedException thrown =
ExpectedException.none();

@Test
public void isEmptyNonEmptyInput() {
Assert.assertFalse(StringUtils.isEmpty("non-empty string"));
}

@Test
public void isEmptyEmptyInput() {
Assert.assertTrue(StringUtils.isEmpty(""));
}

@Test
public void isEmptyInputNull() {
Assert.assertTrue(StringUtils.isEmpty(null));
}

@Test
public void isNotEmptyNonEmptyInput() {
Assert.assertTrue(StringUtils.isNotEmpty("non-empty string"));
}

@Test
public void isNotEmptyEmptyInput() {
Assert.assertFalse(StringUtils.isNotEmpty(""));
}

@Test
public void isNotEmptyInputNull() {
Assert.assertFalse(StringUtils.isNotEmpty(null));
}

@Test
public void appendIfNotContainAppendedStringNotPresent() {
// (Check the case where appendStr doesn't occur in str)
final String str = "Prefix ";
final String appendStr = "suffix";
final String otherwise = "should be discarded";

final String result =
StringUtils.appendIfNotContain(str, appendStr, otherwise);

Assert.assertEquals("Prefix suffix", result);
}

@Test
public void appendIfNotContainAppendedStringPresent() {
// (Check the case where appendStr occurs in str)
final String str = "Prefix ";
final String appendStr = "Prefix";
final String otherwise = "should be appended";

final String result =
StringUtils.appendIfNotContain(str, appendStr, otherwise);

Assert.assertEquals("Prefix should be appended", result);
}

@Test
public void appendIfNotContainEmptyString() {
// (Check the special-case for str being empty)
final String str = "";
final String appendStr = "should not be appended";
final String otherwise = "should also not be appended";

final String result =
StringUtils.appendIfNotContain(str, appendStr, otherwise);

Assert.assertEquals("", result);
}

@Test
public void appendIfNotContainAppendingEmptyString() {
// (Check the special-case for appendStr being empty)
final String str = "should be kept";
final String appendStr = "";
final String otherwise = "should also not be appended";

final String result =
StringUtils.appendIfNotContain(str, appendStr, otherwise);

Assert.assertEquals("should be kept", result);
}
}

0 comments on commit 1fb8be6

Please sign in to comment.