Remove code smells and improve test coverage #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactored code to remove various Implementation and Design smells from various files and improved test coverage.
Added 6 new unit tests -
JSONSignalStoreTest (4 tests)
SegmentInputStreamTest (2 tests)
Refactoring Techniques used to remove smells and improve readability-
Class name - NoiseInputStream
Method - readDecryptedSegment
Used explaining variable to remove Magic Number
Package - nl.ben221199.wapi
Class - JSONSignalStore
Method - getJSON
Cyclomatic complexity of the method is 10
Refactored using Extract Method to remove Complex Method smell
Refactoring - Rename method/variable
Package - com.southernstorm.noise.crypto
Class- NewHope
Method name - f() and g()
From line- 539
Smells removed - Magic Number
Refactoring- Decompose Conditional
Package - com.southernstorm.noise.protocol
Class- HandshakeState
Method- fallback
Method Line- 632
The conditional expression (action != FAILED && action != READ_MESSAGE) || !localEphemeral.hasPublicKey() is complex.
And the conditional expression (action != FAILED && action != WRITE_MESSAGE) || !remoteEphemeral.hasPublicKey() is
complex.
Refactoring - Pull-up method/variable
Package- nl.ben221199.wapi.fun.token
Class 1- ShortList
Class 1 method line - 9
Class 2- LongList
Class 2 method line - 9
Both the classes extend the class AbstractList, and no other class extends AbstractList. There is a variable ‘length’ in
both the subclasses ShortList and LongList which can be taken common into the AbstractList class.
Refactoring- Replace conditional with polymorphism
Package - nl.ben221199.wapi
Class- Verification
Method- calculateToken
Method Line- 115
The method has a switch statement that calculates a token based on the specified platform in the Verification class. This
code violates the open/closed principle, as adding support for a new platform requires modifying the existing code.
Refactoring - Extract Class
Package - nl.ben221199.wapi
Class- Connection
The Connection class exhibits the multifaceted abstraction smell. It combines several responsibilities related to
establishing a connection and performing a handshake. Additionally, it handles different types of handshakes (XX, IK) and
fallback scenarios, leading to increased complexity. To address this smell, I refactored the Connection class by applying
the Single Responsibility Principle (SRP) and Extract Class technique. Each responsibility (connection management,
handshake) should ideally be encapsulated within its own class.
I refactored the code into two separate classes: “HandshakeManager” and “Connection”. The code is now more modular,
making it easier to understand, test, and maintain.