Milestone 1: 1 — Project Scaffolding, Core Email Slicing & CLI#46
Open
mcode-app-dev[bot] wants to merge 4 commits into
Open
Milestone 1: 1 — Project Scaffolding, Core Email Slicing & CLI#46mcode-app-dev[bot] wants to merge 4 commits into
mcode-app-dev[bot] wants to merge 4 commits into
Conversation
added 4 commits
March 27, 2026 04:42
Set up the Maven build structure with pom.xml (Java 17 compiler, JUnit 5 dependency, jar plugin with main class manifest), Maven Wrapper scripts, .gitignore, and standard src/ directory layout.
EmailParts is a Java 17 record holding username and domain. EmailSlicer.slice() trims input, validates with ^[^@]+@[^@]+$, and returns Optional<EmailParts> — empty for invalid input.
Reads email input via Scanner, calls EmailSlicer.slice(), and prints username/domain on success or an error message with exit code 1 on invalid input — matching the original Python behavior.
Cover valid emails, missing @, empty string, @-only, @ at boundaries, whitespace trimming, and null input — 9 tests total.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
View Milestone
Table of Contents
Status
The milestone was successfully completed. All four areas specified in the Milestone Instructions — Maven project scaffolding, domain model, core slicing logic, CLI entry point, and unit tests — were implemented as described. No deviations from the Modernization Instructions or Milestone Instructions were identified.
Feature Overview
This milestone migrates the Email Slicer CLI tool from a single Python script (
emailSlicer.py) to an idiomatic Java 17 application. The original tool prompts the user for an email address, splits it at the@symbol, and prints the username and domain parts.After this milestone, a user can:
./mvnw package(no global Maven installation required)java -jar target/email-slicer.jarThe Java version preserves the original Python behavior while introducing proper separation of concerns, a Java record for the result type, improved input validation (rejects malformed inputs like
@,user@,@domainthat the Python version would accept), and unit tests.Testing
Automated Testing
EmailSlicerTest.javacontains 9 JUnit 5 tests covering all cases specified in the Modernization Instructions:validStandardEmailavimax37@gmail.comavimax37, domain=gmail.comvalidEmailWithSubdomainuser@mail.example.comuser, domain=mail.example.commissingAtSymbolinvalidemail.comOptional.empty()emptyString""Optional.empty()onlyAtSymbol@Optional.empty()atSymbolAtStart@domain.comOptional.empty()atSymbolAtEnduser@Optional.empty()leadingAndTrailingWhitespaceuser@domain.comuser, domain=domain.comnullInputnullOptional.empty()Run with:
./mvnw testManual Testing
avimax37@gmail.comat the prompt. Expected output:invalidemail.com. Expected output:Architecture
Overview
graph TD subgraph Legend L1[New]:::new L2[Modified]:::modified end CLI["Main.java\n(CLI Entry Point)"]:::new SLICER["EmailSlicer.java\n(Core Logic)"]:::new RECORD["EmailParts.java\n(Record)"]:::new BUILD["pom.xml + Maven Wrapper\n(Build System)"]:::new CLI --> SLICER SLICER --> RECORD BUILD -.-> CLI classDef new fill:#90EE90,stroke:#333,color:#000 classDef modified fill:#FFD700,stroke:#333,color:#000Changes
Build System (
pom.xml, Maven Wrapper)Maven project scaffolding configured for Java 17. The
pom.xmldeclares:maven-compiler-plugin(3.11.0) targeting Java 17 source/targetmaven-jar-plugin(3.3.0) with manifest main classcom.emailslicer.Mainand final nameemail-slicermaven-surefire-plugin(3.2.5) for JUnit 5 test executionMaven Wrapper (
mvnw,mvnw.cmd,.mvn/wrapper/maven-wrapper.properties) is bundled so no global Maven installation is needed. A.gitignorecovering Java, Maven, IDE, and OS artifacts was added.EmailParts Record (
EmailParts.java)A Java 17 record with two fields:
usernameanddomain. Provides immutability,equals(),hashCode(), andtoString()with zero boilerplate.Core Logic (
EmailSlicer.java)A final utility class with a single static method
slice(String email)returningOptional<EmailParts>. The method:Optional.empty()for null input^[^@]+@[^@]+$(exactly one@with content on both sides)@and returnsOptional.of(new EmailParts(username, domain))This directly mirrors the Python
email.find("@")/email[:email.index("@")]logic while tightening validation.CLI Entry Point (
Main.java)Reads user input via
Scanner, delegates toEmailSlicer.slice(), and prints results. On invalid input, prints an error message and exits with code 1, consistent with the error handling guidelines from the Modernization Instructions.Design Decisions
Separation of I/O and Logic — The original Python script interleaves
input()/print()with string operations. The Java version separatesMain.java(I/O) fromEmailSlicer.java(pure logic). This makes the core slicing logic testable without mockingSystem.in/System.out.Simple Regex Validation over Python Parity — The Python code uses
email.find("@") != -1, which accepts malformed inputs like@oruser@. The Java version uses^[^@]+@[^@]+$, which is a deliberate, documented improvement that rejects these edge cases while remaining faithful to the tool's intent.Optional<EmailParts>Return Type — Invalid input is represented asOptional.empty()rather than null or an exception. This is idiomatic Java 17, avoids exceptions for a routine validation case, and makes the API self-documenting.Suggested Order of Review
pom.xml— Build configuration, dependencies, and plugin setupsrc/main/java/com/emailslicer/EmailParts.java— Domain model (record); smallest file, introduces the core data typesrc/main/java/com/emailslicer/EmailSlicer.java— Core slicing logic; usesEmailPartssrc/main/java/com/emailslicer/Main.java— CLI entry point; consumesEmailSlicersrc/test/java/com/emailslicer/EmailSlicerTest.java— Unit tests validating the core logic.gitignore— Ignore rules for Java/Maven/IDE artifacts