Skip to content

Add JUnit 5 unit tests for core DayTrader classes#3

Draft
alexlang74 wants to merge 1 commit intomainfrom
cursor/core-classes-unit-tests-6caa
Draft

Add JUnit 5 unit tests for core DayTrader classes#3
alexlang74 wants to merge 1 commit intomainfrom
cursor/core-classes-unit-tests-6caa

Conversation

@alexlang74
Copy link
Copy Markdown
Owner

Summary

This PR introduces a comprehensive JUnit 5 unit test suite for the most important classes in the DayTrader 8 application. The project had no automated tests before this change.

Changes

pom.xml

  • Added junit-jupiter 5.10.1 (test scope)
  • Added javax.json 1.1.4 Glassfish reference implementation (test scope, required for MarketSummaryDataBean.toJSON())
  • Added maven-surefire-plugin 3.1.2 to enable the JUnit 5 platform runner

New test files (src/test/java/)

Entity beans

Test class Tests What's covered
AccountDataBeanTest 17 Constructors, login()/logout(), equals/hashCode, toString/toHTML, random instance
AccountProfileDataBeanTest 12 Constructors, all accessor setters/getters, equals/hashCode, random instance
HoldingDataBeanTest 14 Constructors, getQuoteID() delegation to QuoteDataBean, equals/hashCode, random instance
OrderDataBeanTest 26 isBuy/isSell/isOpen/isCompleted/isCancelled, cancel(), symbol delegation, equals/hashCode
QuoteDataBeanTest 12 All field accessors, equals/hashCode, random instance

Utility classes

Test class Tests What's covered
FinancialUtilsTest 17 computeGain, computeGainPercent (including zero open balance), computeHoldingsTotal (null/empty/populated), HTML formatters
TradeConfigTest 47 Runtime modes, order processing modes, MAX_USERS/QUOTES/HOLDINGS, order fees, all random generators, setConfigParam, constants
KeyBlockTest 16 size(), sequential forward iteration, hasPrevious/previous, nextIndex, unsupported operations
TimerStatTest 13 Default state, setters/getters, ms-to-seconds conversions, average computation

Data beans

Test class Tests What's covered
MarketSummaryDataBeanTest 12 Constructor, lazy gainPercent caching, toJSON() keys, toString/toHTML with and without collections, random instance
RunStatsDataBeanTest 16 All counter setters/getters (12 fields), toString output

Total: 202 tests — all passing.

Test selection rationale

Classes were selected based on: (1) centrality to the trading domain (entity beans used across all layers), (2) pure business logic with no container/EJB dependencies (making them straightforwardly unit-testable), and (3) non-trivial behaviour worth guarding (financial calculations, state machines in OrderDataBean, key iteration in KeyBlock, configuration management in TradeConfig).

Open in Web Open in Cursor 

Add 202 unit tests covering the most important classes:

Entity beans (src/test/java/.../entities/):
- AccountDataBeanTest: constructors, login/logout, equals/hashCode, toString
- AccountProfileDataBeanTest: CRUD accessors, equals/hashCode, random instance
- HoldingDataBeanTest: constructors, quoteID delegation, equals/hashCode
- OrderDataBeanTest: isBuy/isSell/isOpen/isCompleted/isCancelled, cancel(), equals
- QuoteDataBeanTest: all field accessors, equals/hashCode, random instance

Utility classes (src/test/java/.../util/):
- FinancialUtilsTest: computeGain, computeGainPercent, computeHoldingsTotal, HTML formatters
- TradeConfigTest: runtime modes, max limits, order fees, random generators, setConfigParam
- KeyBlockTest: size, sequential iteration, boundary conditions, unsupported operations
- TimerStatTest: min/max/count/totalTime, seconds conversions, average computation

Data beans (src/test/java/.../beans/):
- MarketSummaryDataBeanTest: constructor, gainPercent computation, JSON output, toString
- RunStatsDataBeanTest: all counter getters/setters, toString output

Also adds to pom.xml:
- junit-jupiter 5.10.1 (test scope)
- javax.json 1.1.4 glassfish impl (test scope, for MarketSummaryDataBean.toJSON())
- maven-surefire-plugin 3.1.2 for JUnit 5 runner support

Co-authored-by: Alexander Lang <alexlang@de.ibm.com>
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