Skip to content

Milestone 1: 1 — Project Scaffolding, Core Email Slicing & CLI#46

Open
mcode-app-dev[bot] wants to merge 4 commits into
project_base_run_503from
emailslicer-dkasargod-milestone_1-f043b2
Open

Milestone 1: 1 — Project Scaffolding, Core Email Slicing & CLI#46
mcode-app-dev[bot] wants to merge 4 commits into
project_base_run_503from
emailslicer-dkasargod-milestone_1-f043b2

Conversation

@mcode-app-dev

@mcode-app-dev mcode-app-dev Bot commented Mar 27, 2026

Copy link
Copy Markdown

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:

  • Build the project with ./mvnw package (no global Maven installation required)
  • Run the tool with java -jar target/email-slicer.jar
  • Enter an email address at the prompt and receive the username and domain printed to the console
  • Receive a clear error message and exit code 1 for invalid input

The 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@, @domain that the Python version would accept), and unit tests.


Testing

Automated Testing

EmailSlicerTest.java contains 9 JUnit 5 tests covering all cases specified in the Modernization Instructions:

Test Input Expected
validStandardEmail avimax37@gmail.com username=avimax37, domain=gmail.com
validEmailWithSubdomain user@mail.example.com username=user, domain=mail.example.com
missingAtSymbol invalidemail.com Optional.empty()
emptyString "" Optional.empty()
onlyAtSymbol @ Optional.empty()
atSymbolAtStart @domain.com Optional.empty()
atSymbolAtEnd user@ Optional.empty()
leadingAndTrailingWhitespace user@domain.com username=user, domain=domain.com
nullInput null Optional.empty()

Run with: ./mvnw test

Manual Testing

  1. Build the project:
    ./mvnw package
    
  2. Run the JAR:
    java -jar target/email-slicer.jar
    
  3. Enter avimax37@gmail.com at the prompt. Expected output:
    Your username is: avimax37
    Your domain is: gmail.com
    
  4. Run again and enter invalidemail.com. Expected output:
    Please enter a valid Email Id.
    
    The process should exit with code 1.

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:#000
Loading

Changes

Build System (pom.xml, Maven Wrapper)

Maven project scaffolding configured for Java 17. The pom.xml declares:

  • maven-compiler-plugin (3.11.0) targeting Java 17 source/target
  • maven-jar-plugin (3.3.0) with manifest main class com.emailslicer.Main and final name email-slicer
  • maven-surefire-plugin (3.2.5) for JUnit 5 test execution
  • JUnit Jupiter 5.10.2 as a test-scoped dependency

Maven Wrapper (mvnw, mvnw.cmd, .mvn/wrapper/maven-wrapper.properties) is bundled so no global Maven installation is needed. A .gitignore covering Java, Maven, IDE, and OS artifacts was added.

EmailParts Record (EmailParts.java)

A Java 17 record with two fields: username and domain. Provides immutability, equals(), hashCode(), and toString() with zero boilerplate.

Core Logic (EmailSlicer.java)

A final utility class with a single static method slice(String email) returning Optional<EmailParts>. The method:

  1. Returns Optional.empty() for null input
  2. Trims leading/trailing whitespace
  3. Validates against the regex ^[^@]+@[^@]+$ (exactly one @ with content on both sides)
  4. Splits on @ and returns Optional.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 to EmailSlicer.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

  1. Separation of I/O and Logic — The original Python script interleaves input()/print() with string operations. The Java version separates Main.java (I/O) from EmailSlicer.java (pure logic). This makes the core slicing logic testable without mocking System.in/System.out.

  2. Simple Regex Validation over Python Parity — The Python code uses email.find("@") != -1, which accepts malformed inputs like @ or user@. The Java version uses ^[^@]+@[^@]+$, which is a deliberate, documented improvement that rejects these edge cases while remaining faithful to the tool's intent.

  3. Optional<EmailParts> Return Type — Invalid input is represented as Optional.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

  1. pom.xml — Build configuration, dependencies, and plugin setup
  2. src/main/java/com/emailslicer/EmailParts.java — Domain model (record); smallest file, introduces the core data type
  3. src/main/java/com/emailslicer/EmailSlicer.java — Core slicing logic; uses EmailParts
  4. src/main/java/com/emailslicer/Main.java — CLI entry point; consumes EmailSlicer
  5. src/test/java/com/emailslicer/EmailSlicerTest.java — Unit tests validating the core logic
  6. .gitignore — Ignore rules for Java/Maven/IDE artifacts

Modernization Agent 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.
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.

0 participants