Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spring-trpc junit #36

Conversation

chenhao26-nineteen
Copy link
Contributor

linked: #34

Copy link

github-actions bot commented May 24, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@chenhao26-nineteen
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

liuzengh added a commit to trpc-group/cla-database that referenced this pull request May 24, 2024
import org.junit.Assert;
import org.junit.Test;


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多余空行,下面也是,一般只有一个空行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it

}

@Test
public void testEmptyIfNull() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数可以通过AddFilterTRpcConfigManagerCustomizer构造函数测,尽量减少使用setAccessible。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it

}

@Test
public void testMerge() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数可以通过customize函数测,尽量减少使用setAccessible。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it

Assert.assertEquals((long) value, addFilterTRpcConfigManagerCustomizer.getOrder());
}

static final class AddFilterTRpcConfigManagerCustomizer2 extends AddFilterTRpcConfigManagerCustomizer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议不用出现1 2 3这种数字的命名,可以命名为TestFilterConfigManagerCustomizer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it

public void testGetOrder() {
AddFilterTRpcConfigManagerCustomizer addFilterTRpcConfigManagerCustomizer = new AddFilterTRpcConfigManagerCustomizer2();
Assert.assertEquals(Integer.MAX_VALUE, addFilterTRpcConfigManagerCustomizer.getOrder());
Integer value = 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把这个定义为常量,getOrder里面直接返回常量就行。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it


@Test
public void testGetOrder() {
AddFilterTRpcConfigManagerCustomizer addFilterTRpcConfigManagerCustomizer = new AddFilterTRpcConfigManagerCustomizer2();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new AddFilterTRpcConfigManagerCustomizer();然后断言

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it


@Override
public int getOrder() {
return System.getProperty(KEY) == null ? super.getOrder() : Integer.parseInt(System.getProperty(KEY));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返回一个固定值就行

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it

public void testAddClientFilters() {
AddFilterTRpcConfigManagerCustomizer addFilterTRpcConfigManagerCustomizer = new AddFilterTRpcConfigManagerCustomizer();
AddFilterTRpcConfigManagerCustomizer customizer = addFilterTRpcConfigManagerCustomizer.addClientFilters(
"filter1", "filter2");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这些字符串也提取为常量

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fix it


@Test
public void testConstructorWithNullEmpty() {
addFilterTRpcConfigManagerCustomizer.addClientFilters(FILTER_ONE, FILTER_TWO);
Copy link
Collaborator

@wardseptember wardseptember May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行可以移动到L95行之后

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

@Test
public void testConstructorWithNullEmpty() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数是测emptyIfNull,可以在new AddFilterTRpcConfigManagerCustomizer(null, null);后,向clientFilters和serverFilters添加插件,然后断言

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@wardseptember wardseptember merged commit c3fe93f into trpc-group:master May 27, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants