Skip to content

Milestone 1: 1 — Project Scaffold, Core Email Parsing, and CLI Entry Point#44

Open
mcode-app-dev[bot] wants to merge 1 commit into
project_base_run_455from
emailslicer-dkasargod-milestone_1-dfcdad
Open

Milestone 1: 1 — Project Scaffold, Core Email Parsing, and CLI Entry Point#44
mcode-app-dev[bot] wants to merge 1 commit into
project_base_run_455from
emailslicer-dkasargod-milestone_1-dfcdad

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 scope items from the Milestone Instructions are implemented:

  • Maven project initialized with standard directory layout and Maven Wrapper
  • EmailParts Java 17 record implemented
  • EmailSlicer.parse() static method with validation (null/blank, missing @, multiple @, empty username, empty domain)
  • Main CLI entry point matching the original Python output format
  • JUnit 5 test suite with 8 passing tests covering happy-path and error cases

Deviations from Milestone Instructions: None. The output format of the Java CLI matches the Python original exactly (including the trailing space produced by Python's comma-separated print). A Messages class was added per the error handling guidelines to centralize user-facing strings; this was not explicitly listed in the Milestone Instructions but is prescribed by the project-level instruction file on error handling.


Feature Overview

This milestone establishes the Java 17 Email Slicer project — a 1:1 migration of the Python emailSlicer.py CLI tool. The application:

  • Prompts the user for an email address via stdin
  • Validates the input contains exactly one @ with non-empty username and domain parts
  • Prints Your username is: <username> and Your domain is: <domain> to stdout
  • Prints Please enter a valid Email Id. and exits with code 1 on invalid input

A user can build and run the application with:

./mvnw package && java -jar target/email-slicer.jar

Testing

Automated testing

EmailSlicerTest.java contains 8 JUnit 5 tests exercising EmailSlicer.parse() directly:

Test Input Expectation
validEmail avimax37@gmail.com Returns EmailParts("avimax37", "gmail.com")
leadingTrailingWhitespace user@example.org Returns EmailParts("user", "example.org")
missingAtSign invalidemail Throws IllegalArgumentException
emptyString "" Throws IllegalArgumentException
nullInput null Throws IllegalArgumentException
multipleAtSigns a@b@c.com Throws IllegalArgumentException
emptyUsername @domain.com Throws IllegalArgumentException
emptyDomain user@ Throws IllegalArgumentException

Run with: ./mvnw test

Manual testing

  1. Build the project:
    cd emailslicer-dkasargod-java && ./mvnw package
    
  2. Run with a valid email:
    echo "avimax37@gmail.com" | java -jar target/email-slicer.jar
    
    Expected output:
    Please enter your Email Id:
    Your username is:  avimax37
    Your domain is:  gmail.com
    
  3. Run with an invalid email:
    echo "invalidemail" | java -jar target/email-slicer.jar
    
    Expected output:
    Please enter your Email Id:
    Please enter a valid Email Id.
    
    The process should exit with code 1.
  4. Compare outputs with the Python original:
    echo "avimax37@gmail.com" | python3 emailSlicer.py
    
    Both should produce identical output.

Architecture

Overview

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

    subgraph "emailslicer-dkasargod (Python - Reference)"
        PY[emailSlicer.py]:::refNode
    end

    subgraph "emailslicer-dkasargod-java (Java 17)"
        MAIN[Main.java - CLI Entry Point]:::newNode
        SLICER[EmailSlicer.java - Parse Logic]:::newNode
        PARTS[EmailParts.java - Record]:::newNode
        MSGS[Messages.java - Constants]:::newNode
    end

    PY -.->|migrated to| MAIN
    MAIN --> SLICER
    SLICER --> PARTS
    MAIN --> MSGS
    SLICER --> MSGS

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

Changes

CLI Entry Point (Main.java)

Handles all console I/O: prints the prompt, reads a line from stdin, delegates to EmailSlicer.parse(), and prints the result. On invalid input, catches IllegalArgumentException, prints the error message, and calls System.exit(1).

Parse Logic (EmailSlicer.java)

Contains a single static method parse(String): EmailParts that encapsulates all validation and splitting logic. Validates that input is non-null/non-blank, contains exactly one @, and has non-empty username and domain segments. Throws IllegalArgumentException on any violation.

Result Record (EmailParts.java)

A Java 17 record holding username and domain. Provides immutability and automatic equals/hashCode/toString, which simplifies test assertions.

User-Facing Messages (Messages.java)

Centralizes all user-facing strings (PROMPT_MESSAGE, INVALID_EMAIL_MESSAGE, USERNAME_PREFIX, DOMAIN_PREFIX) as public static final constants, per the error handling guidelines.

Build Configuration (pom.xml, Maven Wrapper)

Maven pom.xml targets Java 17, declares JUnit 5 as the sole (test-scoped) dependency, and configures maven-jar-plugin to produce an executable JAR with Main-Class manifest entry. The Maven Wrapper (mvnw, mvnw.cmd, .mvn/wrapper/maven-wrapper.properties) enables building without a pre-installed Maven.

Design Decisions

  1. Separation of parsing logic from I/O

    • Description: EmailSlicer (pure function) is separated from Main (console I/O).
    • Justification: The Python original mixes input()/print() with string slicing. Separating these concerns allows unit testing the parse logic directly without mocking System.in/System.out.
  2. Java 17 record for result type

    • Description: EmailParts is declared as a record rather than a POJO.
    • Justification: Records are the idiomatic Java 17 approach for immutable value objects. They provide equals/hashCode/toString automatically, enabling concise assertEquals assertions in tests.
  3. IllegalArgumentException for invalid input

    • Description: EmailSlicer.parse() throws IllegalArgumentException on invalid input; Main catches it and prints the message.
    • Justification: Aligns with the error handling guidelines, which prescribe IllegalArgumentException for precondition violations. Produces clean assertThrows test assertions and establishes a convention for future validation enhancements.
  4. Centralized Messages class

    • Description: All user-facing strings are stored as constants in Messages.java.
    • Justification: Required by the error handling guidelines. Avoids string duplication between production code and tests, and provides a single place to update output text.

Suggested Order of Review

  1. emailslicer-dkasargod-java/pom.xml — Build configuration, dependencies, and packaging
  2. emailslicer-dkasargod-java/.mvn/wrapper/maven-wrapper.properties — Maven Wrapper configuration
  3. emailslicer-dkasargod-java/mvnw — Maven Wrapper shell script
  4. emailslicer-dkasargod-java/src/main/java/com/emailslicer/EmailParts.java — Data model (record)
  5. emailslicer-dkasargod-java/src/main/java/com/emailslicer/Messages.java — Constants used across the app
  6. emailslicer-dkasargod-java/src/main/java/com/emailslicer/EmailSlicer.java — Core parse logic
  7. emailslicer-dkasargod-java/src/main/java/com/emailslicer/Main.java — CLI entry point consuming the above
  8. emailslicer-dkasargod-java/src/test/java/com/emailslicer/EmailSlicerTest.java — Test suite validating parse logic

Migrate the Python email slicer to Java 17 with standard Maven layout,
Maven Wrapper, EmailParts record, EmailSlicer parser, Messages constants,
Main CLI entry point, and JUnit 5 test suite (8 tests).
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