Skip to content

Milestone 1: 1 — Project Foundation and Core Email Slicing#47

Open
mcode-app-dev[bot] wants to merge 5 commits into
project_base_run_557from
emailslicer-dkasargod-milestone_1-40595a
Open

Milestone 1: 1 — Project Foundation and Core Email Slicing#47
mcode-app-dev[bot] wants to merge 5 commits into
project_base_run_557from
emailslicer-dkasargod-milestone_1-40595a

Conversation

@mcode-app-dev

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

Copy link
Copy Markdown

View Milestone


Table of Contents


Status

Milestone 1 was successfully completed. All goals defined in the Milestone Instructions were implemented:

  • Maven project scaffolding with Maven Wrapper
  • EmailSliceResult record, EmailSlicer parsing logic, and Main CLI entry point
  • JUnit 5 unit tests covering valid emails, missing @, empty/blank input, whitespace trimming, and edge cases

Deviation from Milestone Instructions: A Messages.java class was added to centralize all user-facing strings. This was not explicitly called for in the spec but is a minor structural improvement that aids maintainability and future localization without changing any external behavior.

The initial validation strategy uses contains("@") (matching the original Python behavior), as prescribed by the Milestone Instructions for this milestone, with regex-based validation deferred to Milestone 2.


Feature Overview

This milestone establishes the complete Java 17 Maven project and implements core email slicing functionality, migrating the original Python emailSlicer.py to an idiomatic Java CLI application.

End-user capability: A user can run the application, enter an email address at the prompt, and see the username and domain printed to the console — matching the original Python tool's behavior.

Example session:

$ java -jar target/email-slicer.jar
Please enter your Email Id:
user@example.com
Your username is:  user
Your domain is:  example.com

Testing

Automated Testing

EmailSlicerTest.java contains 14 JUnit 5 tests organized into nested test classes:

Category Tests Description
Valid emails 3 Simple email, dotted username, plus addressing
Whitespace handling 2 Leading/trailing spaces, tabs/mixed whitespace
Missing @ 2 No @ symbol, plain word
Empty/blank input 3 Null, empty string, blank string
Edge cases 5 @ only, @ at start, @ at end, multiple @, three-part @
Error messages 1 Verifies user-friendly error message text

Run tests with:

./mvnw test

Manual Testing

  1. Build the project:
    ./mvnw package
  2. Run the JAR:
    java -jar target/email-slicer.jar
  3. Enter user@example.com — verify output:
    Your username is:  user
    Your domain is:  example.com
    
  4. Enter invalidemail — verify output:
    Please enter a valid Email Id.
    
    and a non-zero exit code (echo $? should print 1).

Architecture

Overview

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

    A["emailSlicer.py<br/>(Original Python Script)"]:::refNode
    B["Main.java<br/>(CLI Entry Point)"]:::newNode
    C["EmailSlicer.java<br/>(Parsing Logic)"]:::newNode
    D["EmailSliceResult.java<br/>(Record)"]:::newNode
    E["Messages.java<br/>(User-Facing Strings)"]:::newNode
    F["pom.xml + Maven Wrapper<br/>(Build System)"]:::newNode

    A -.->|"migrated to"| B
    B -->|"delegates to"| C
    C -->|"returns"| D
    B -->|"uses"| E
    C -->|"uses"| E
    F -->|"builds"| B
    F -->|"builds"| C

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

Changes

Build System (pom.xml + Maven Wrapper)

  • pom.xml configured with groupId=com.emailslicer, artifactId=email-slicer, targeting Java 17
  • Dependencies: JUnit 5.10.2 (test scope only)
  • Plugins: maven-compiler-plugin 3.11.0, maven-surefire-plugin 3.2.5, maven-jar-plugin 3.3.0 (with Main as manifest main class, final name email-slicer)
  • Maven Wrapper (mvnw/mvnw.cmd + .mvn/wrapper/) checked in for zero-install builds
  • .gitignore configured for Maven target/, IDE files, and OS artifacts

Parsing Logic (EmailSlicer.java)

  • Utility class with private constructor; single static method slice(String email)
  • Trims input via String.strip() (matching Python's strip() behavior)
  • Validates presence of @ using contains("@") — matching original Python validation
  • Splits on the first @ using indexOf + substring
  • Throws IllegalArgumentException with a user-friendly message for null, blank, or missing-@ input

Data Carrier (EmailSliceResult.java)

  • Java 17 record with two fields: username and domain
  • Provides immutability and auto-generated equals/hashCode/toString

CLI Entry Point (Main.java)

  • Reads email from System.in via Scanner, delegates to EmailSlicer.slice()
  • Prints formatted username and domain using System.out.printf
  • Catches IllegalArgumentException, prints the error message, and exits with code 1

User-Facing Strings (Messages.java)

  • Constants-only utility class centralizing all prompt text, error messages, and format strings
  • Referenced by both Main and EmailSlicer to ensure consistent messaging

Design Decisions

1. Two-class separation of parsing logic and console I/O

  • EmailSlicer contains pure parsing logic; Main handles all I/O
  • Justification: Enables unit testing of parsing without mocking System.in/System.out. Prescribed by the Modernization Instructions.

2. Initial validation matches Python behavior (contains("@"))

  • The simpler check was chosen for this milestone to achieve behavioral parity first
  • Justification: Keeps this milestone focused on project scaffolding and structure. Regex-based validation is deferred to Milestone 2 as specified in the Milestone Instructions.

3. IllegalArgumentException for invalid input signaling

  • Chosen over Optional.empty() return type
  • Justification: Aligns with the project's error handling guidelines. Makes test assertions straightforward via assertThrows. Provides descriptive error messages to end users.

4. Dedicated Messages class for user-facing strings

  • All prompt text, error messages, and format strings extracted into Messages.java
  • Justification: Avoids string duplication across Main and EmailSlicer, simplifies future localization, and makes message content easily reviewable in one place.

Suggested Order of Review

  1. pom.xml — Build configuration, dependencies, and plugins
  2. src/main/java/com/emailslicer/EmailSliceResult.java — Data carrier record (simplest class; introduces the core data model)
  3. src/main/java/com/emailslicer/Messages.java — User-facing string constants (referenced by the next two files)
  4. src/main/java/com/emailslicer/EmailSlicer.java — Core parsing logic (uses EmailSliceResult and Messages)
  5. src/main/java/com/emailslicer/Main.java — CLI entry point (uses all of the above)
  6. src/test/java/com/emailslicer/EmailSlicerTest.java — Unit tests (validates the parsing logic)
  7. .gitignore — Repository ignore rules

Modernization Agent added 5 commits March 30, 2026 23:05
Set up the Java 17 Maven project structure for the email slicer
migration including pom.xml with JUnit 5 dependency, Maven Wrapper
scripts, .gitignore, and standard src/main/java + src/test/java layout.
Implement the core email slicing: EmailSliceResult Java 17 record for
the parsed result, and EmailSlicer.slice() static method that trims
input and splits on '@'. Throws IllegalArgumentException for null,
blank, or missing-@ inputs, matching the original Python validation.
Implement the CLI entry point that prompts for an email address, calls
EmailSlicer.slice(), and prints the username and domain. Catches
IllegalArgumentException to print the error and exit with code 1,
matching the original Python tool's behavior.
16 tests covering valid emails, whitespace trimming, missing @,
null/empty/blank input, edge cases (@-only, empty username/domain,
multiple @ symbols), and error message content verification.
Move all hardcoded user-facing message literals into Messages.java
with public static final constants, per the error handling guidelines.
Update EmailSlicer and Main to reference Messages constants.
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