Imported from law23sum/JavaTutorial (
AGENTS.md). Install upstream withnpx skills add law23sum/JavaTutorial. Copyright stays with the author.
AGENTS.md
Purpose and scope
- This is a single-module Maven training repo with three pillars: core Java/OOP/algorithms (
src/main/java/com/javatutorial/{fundamentals,oop,datastructures,algorithms}), a small Spring Boot app (src/main/java/com/javatutorial/springapp), and a Selenium/TestNG framework (src/test/java/com/javatutorial/automation). - Treat examples as instructional code first: most classes are intentionally small and heavily commented (see
TwoSum.java,WrapperClassesDemo.java).
Big-picture architecture
- Spring app flow is
controller -> service -> repository -> H2usingUserController,UserService,UserRepository,User. - Error mapping is centralized in
GlobalExceptionHandler(@RestControllerAdvice), so service exceptions likeUserNotFoundExceptionbecome HTTP responses without controller-level try/catch. - Startup seed data is created in
AppConfigviaCommandLineRunner; tests and manual API checks assume at least 2 initial users. - MVC and REST coexist:
HomeControllerreturns Thymeleaf viewtemplates/index.html, while/api/usersis JSON REST.
Build, run, and test workflows
- Prereqs used by the repo: Java 17 + Maven (see
pom.xmlproperties and plugin config). - Run app:
mvn spring-boot:run(serves on port8080, configured insrc/main/resources/application.yml). - Run tutorial class directly:
mvn exec:java -Dexec.mainClass=com.javatutorial.algorithms.arrays.TwoSum. - Default tests:
mvn testruns JUnit 5 plus TestNG, but excludes TestNG groupuivia Surefire propertytestng.excluded.groups. - UI tests opt-in:
mvn test -Pui(or narrow with-Dtest=BankStatementAnalyzerTest).
Test strategy and boundaries
- JUnit 5 is used for fundamentals/algorithms and Spring API tests (
src/test/java/com/javatutorial/{fundamentals,algorithms,springapp}). UserControllerTestis a full Spring context +MockMvcintegration test (@SpringBootTest,@AutoConfigureMockMvc) against in-memory H2.- TestNG suite config lives in
src/test/resources/testng.xmland includes lifecycle/data-provider demos plus UI group wiring. - Selenium tests are example-style and may need environment edits (e.g., placeholder URL in
BankStatementAnalyzerTest).
Project-specific coding patterns
- Tutorial classes generally include JavaDoc with concept + complexity notes and a runnable
main(String[])demo (e.g.,TwoSum.java). - Keep Spring controllers thin and delegate behavior to service methods (
UserControllervsUserService). - Use domain-specific exceptions in automation helpers/pages (e.g.,
ElementNotClickableException,DataNotFoundException) instead of leaking raw Selenium/SQL exceptions. - Page Object Model convention: locators/actions stay in
automation/pages/*, tests call intent-level methods likeloginAs(...). - Browser setup is centralized in
DriverFactory; only Chrome is supported, controlled by-Dbrowserand-Dheadlesssystem properties.
Integration points and external dependencies
- Spring Boot starters: Web, Thymeleaf, Data JPA, Validation (
pom.xml). - Persistence is in-memory H2 (
jdbc:h2:mem:tutorialdb) with console enabled at/h2. - Test automation relies on Selenium + TestNG + WebDriverManager; driver binaries are managed automatically in code.
documentation/Commands.mdcontains mixed historical commands (including Gradle), but Maven commands inREADME.md/pom.xmlare the source of truth for this repo.