Skip to content

Milestone 1: 1. Project Foundation and Core Email Parsing CLI#43

Open
mcode-app-dev[bot] wants to merge 1 commit into
project_base_run_453from
emailslicer-dkasargod-milestone_1-41497d
Open

Milestone 1: 1. Project Foundation and Core Email Parsing CLI#43
mcode-app-dev[bot] wants to merge 1 commit into
project_base_run_453from
emailslicer-dkasargod-milestone_1-41497d

Conversation

@mcode-app-dev

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

Copy link
Copy Markdown

View Milestone


Table of Contents


Status

The milestone was successfully completed. All goals described in the Milestone Instructions were implemented: the Maven project was scaffolded with wrapper, the core email parsing logic was separated from console I/O, EmailResult was modeled as a Java 17 record, and a JUnit 5 test suite was added.

Deviation from spec: The Milestone Instructions noted that initial validation in slice() should match the Python original's minimal @-presence check, deferring stricter regex validation to Milestone 2. The implementation follows this approach — slice() checks only for the presence of @ via indexOf, consistent with the Python baseline. Inputs like @domain.com (empty username) and user@ (empty domain) are accepted, matching the Python original's behavior. Tests explicitly document this parity.


Feature Overview

This milestone migrates the Python emailSlicer.py CLI tool to a Java 17 project (emailslicer-java). The end user can:

  • Run ./mvnw compile exec:java to launch the Email Slicer CLI
  • Enter an email address at the prompt (e.g., user@domain.com)
  • See the parsed username and domain printed to stdout:
    Your username is:  user
    Your domain is:  domain.com
    
  • See an error message (Please enter a valid Email Id.) for inputs without @

The Java implementation preserves behavioral parity with the Python original while introducing proper class structure, type-safe return values (EmailResult record), and Optional-based null safety.


Testing

Automated testing

The EmailSlicerTest class contains 16 test cases run via ./mvnw test:

Category Tests Description
Valid emails slice_validEmail_returnsExpectedParts Parameterized test with 4 valid emails verifying correct username/domain extraction
Whitespace trimming slice_leadingAndTrailingWhitespace_isTrimmed, slice_tabsAndNewlines_areTrimmed Verifies strip() parity with Python's strip()
Invalid emails (no @) slice_noAtSign_returnsEmpty Parameterized test covering plain strings, empty string, whitespace-only input
Null input slice_null_returnsEmpty Null safety via @NullSource
Edge cases (Python parity) slice_emptyUsername_returnsResult, slice_emptyDomain_returnsResult, slice_multipleAtSigns_splitsOnFirst Documents that the Python-equivalent behavior is preserved
Record behavior emailResult_equalsAndHashCode, emailResult_toString_containsFields Verifies record auto-generated methods

Manual testing

  1. From the repository root, run:
    ./mvnw compile exec:java
  2. At the Please enter your Email Id: prompt, type alice@example.com and press Enter.
  3. Verify the output:
    Your username is:  alice
    Your domain is:  example.com
    
  4. Run again and enter invalidemail (no @ symbol). Verify the output:
    Please enter a valid Email Id.
    

Architecture

Overview

graph TD
    subgraph Legend
        L1[New]:::newNode
        L2[Reference Only]:::refNode
    end

    subgraph "emailslicer-dkasargod (Python)"
        PY["emailSlicer.py<br/>Python CLI Script"]:::refNode
    end

    subgraph "emailslicer-java (Java 17)"
        MAIN["Main.java<br/>Console I/O"]:::newNode
        SLICER["EmailSlicer.java<br/>Parsing Logic"]:::newNode
        RECORD["EmailResult.java<br/>Java 17 Record"]:::newNode
        POM["pom.xml<br/>Maven Build"]:::newNode
    end

    PY -.->|"migrated to"| MAIN
    MAIN --> SLICER
    SLICER --> RECORD

    classDef newNode fill:#90EE90,stroke:#333,color:#000
    classDef refNode fill:#D3D3D3,stroke:#333,color:#000
Loading

Changes

Maven Build Configuration (pom.xml)

  • New Maven project with groupId=com.emailslicer, artifactId=emailslicer, Java 17 source/target
  • JUnit 5.10.2 managed via junit-bom BOM import
  • Plugins: maven-compiler-plugin (3.11.0), maven-surefire-plugin (3.2.5), maven-jar-plugin (3.3.0 with Main-Class manifest), exec-maven-plugin (3.1.0)
  • Maven Wrapper (3.2.0) bundled via .mvn/wrapper/ and mvnw/mvnw.cmd scripts, targeting Maven 3.9.6

EmailResult Record (EmailResult.java)

  • Java 17 record with two fields: username and domain
  • Provides immutable value semantics with auto-generated equals(), hashCode(), and toString()
  • Replaces the implicit tuple-like return of the Python original

EmailSlicer Parsing Logic (EmailSlicer.java)

  • Final utility class with private constructor (non-instantiable)
  • Single static method slice(String email) returning Optional<EmailResult>
  • Trims input via String.strip() (matching Python's strip()), checks for @ via indexOf, splits into username/domain
  • Returns Optional.empty() for null input or missing @

Main Console I/O (Main.java)

  • Entry point with Scanner-based stdin reading
  • Prompts with "Please enter your Email Id:", delegates to EmailSlicer.slice(), and prints results using ifPresentOrElse
  • Output format matches the Python original: "Your username is: ..." / "Your domain is: ..."

Design Decisions

  1. Maven with maven-jar-plugin over maven-shade-plugin

    • The maven-jar-plugin with a Main-Class manifest entry was chosen over maven-shade-plugin (fat JAR). Since the project has zero runtime dependencies (JUnit is test-scoped only), a shade plugin adds unnecessary build complexity. The jar plugin satisfies the java -jar target/emailslicer.jar requirement from the Modernization Instructions.
  2. Separated concerns (3 classes) over single-class design

    • Main.java handles I/O, EmailSlicer.java holds pure parsing logic, and EmailResult.java is the value type. This separation — rather than mirroring the Python single-script approach — makes the parsing logic independently testable without stdout capture, aligning with the Modernization Instructions.
  3. Python-equivalent validation deferred to Milestone 2

    • slice() currently validates only @ presence (matching the Python original's email.find("@") != -1). Inputs like @domain.com or user@ are accepted. This establishes behavioral parity as a baseline; regex-based stricter validation is deferred to Milestone 2 per the Milestone Instructions.

Suggested Order of Review

  1. pom.xml — Start here to understand the build configuration, dependencies, and plugin setup
  2. src/main/java/com/emailslicer/EmailResult.java — The Java 17 record that models the parsed result
  3. src/main/java/com/emailslicer/EmailSlicer.java — Core parsing logic; the primary API surface
  4. src/main/java/com/emailslicer/Main.java — Console I/O entry point that consumes EmailSlicer
  5. src/test/java/com/emailslicer/EmailSlicerTest.java — Test suite covering valid, invalid, and edge-case inputs
  6. .gitignore, mvnw/mvnw.cmd, .mvn/wrapper/ — Supporting build infrastructure (skim only)

Complete Maven project with:
- EmailResult record (Java 17) for parsed email components
- EmailSlicer utility with static slice() returning Optional<EmailResult>
- Main class for CLI interaction matching Python original's I/O behavior
- JUnit 5 test suite with 16 parameterized tests
- Maven Wrapper for reproducible builds
- Build: ./mvnw clean verify | Run: ./mvnw compile exec:java
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