-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e662ce1
commit e254cde
Showing
10 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
deploy-service/common/src/main/java/com/pinterest/deployservice/bean/BaseBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.pinterest.deployservice.bean; | ||
|
||
public class BaseBean { | ||
|
||
/** | ||
* Trims the input string to the specified size limit. If the input string's length | ||
* exceeds the limit, the method returns the substring from the end of the string | ||
* with the specified limit. Otherwise returns the original string. | ||
* | ||
* @param value the input string to be trimmed | ||
* @param limit the maximum length of the returned string | ||
* @return the trimmed string if the input string's length exceeds the limit, | ||
* otherwise the original string | ||
*/ | ||
protected String getStringWithSizeLimit(String value, int limit) { | ||
if (value != null && value.length() > limit) { | ||
return value.substring(value.length() - limit, value.length()); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
deploy-service/common/src/test/java/com/pinterest/deployservice/bean/BaseBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.pinterest.deployservice.bean; | ||
|
||
|
||
import static org.junit.Assert.assertSame; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class BaseBeanTest { | ||
@Test | ||
void testGetStringWithSizeLimitInputNull() { | ||
BaseBean baseBean = new BaseBean(); | ||
String result = baseBean.getStringWithSizeLimit(null, 10); | ||
assertNull(result); | ||
} | ||
|
||
@Test | ||
void testGetStringWithSizeLimitInputWithinLimit() { | ||
BaseBean baseBean = new BaseBean(); | ||
String input = "test"; | ||
String result = baseBean.getStringWithSizeLimit(input, 10); | ||
assertSame(input, result); | ||
} | ||
@Test | ||
void testGetStringWithSizeLimitInputExceedsLimit() { | ||
BaseBean baseBean = new BaseBean(); | ||
String result = baseBean.getStringWithSizeLimit("0123456789", 5); | ||
assertEquals("56789", result); | ||
} | ||
} |