eventmesh icon indicating copy to clipboard operation
eventmesh copied to clipboard

[Enhancement] Do some code optimization.[StandaloneAdminTest TestUtils]

Open Alonexc opened this issue 2 years ago • 0 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Enhancement Request

image image image image located at: eventmesh-storage-plugin/eventmesh-storage-standalone/src/test/java/org/apache/eventmesh/storage/standalone/admin/StandaloneAdminTest.java line 73,90,99 eventmesh-storage-plugin/eventmesh-storage-standalone/src/test/java/org/apache/eventmesh/storage/standalone/TestUtils.java line 66 analysis and explanation: a. This method makes two consecutive calls to the same method, using the same constant parameters, on the same instance, without any intervening changes to the objects. If this method does not make changes to the object, which it appears it doesn't, then making two calls is just a waste. These method calls could be combined by assigning the result into a temporary variable, and using the variable the second time. b. Method needlessly boxes a boolean constant. c. Method builds a list from one element using Arrays.asList This method builds a list using Arrays.asList(foo), passing in a single element. Arrays.asList needs to first create an array from this one element, and then build a List that wraps this array. It is simpler to use Collections.singletonList(foo), which does not create the array, and produces a far simpler instance of List. Since both of these arrays are immutable (from the List's point of view) they are equivalent from a usage s tandpoint.

Describe the solution you'd like

a. Use intermediate variables as storage. image

b. Use 'Boolean.xxxx'. image

c. Replace with Collections.singletonList(). image

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

Alonexc avatar Apr 27 '23 02:04 Alonexc