Skip to content

Labb3#1

Open
gitnes94 wants to merge 3 commits intomainfrom
Labb3
Open

Labb3#1
gitnes94 wants to merge 3 commits intomainfrom
Labb3

Conversation

@gitnes94
Copy link
Collaborator

@gitnes94 gitnes94 commented Nov 17, 2025

Features

  • ✅ MVC architecture
  • ✅ Send/receive messages via ntfy
  • ✅ File upload functionality
  • ✅ Environment configuration (.env)
  • ✅ Unit tests
  • ✅ Beautiful UI

How to run

  1. Start Docker: docker run -d --name ntfy-server -p 8080:80 -v ${PWD}/ntfy-server.yml:/etc/ntfy/server.yml -v ntfy-cache:/var/cache/ntfy binwiederhier/ntfy serve
  2. Create .env: NTFY_BASE_URL=http://localhost:8080
  3. Run: ./mvnw clean javafx:run

Summary by CodeRabbit

  • Documentation

    • Added author information.
  • Bug Fixes

    • Message validation now prevents empty or blank message submissions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Walkthrough

Documentation updated with author attribution. Input validation added to ChatModel.sendMessage to reject null or blank messages. Inline comment removed from NtfyMessage. Test suite refactored: ChatModelTest migrated to setup-based approach with focus on message list state; NtfyMessageTest converted from Jackson serialization tests to constructor-based validation tests.

Changes

Cohort / File(s) Summary
Documentation
README.md
Adds new "Author" section crediting Lab 3 - Network Programming.
Input Validation
src/main/java/com/example/model/ChatModel.java
Adds early-exit validation in sendMessage to reject null or blank text with IllegalArgumentException.
Comment Cleanup
src/main/java/com/example/model/NtfyMessage.java
Removes inline comment from attachment field declaration.
ChatModel Test Refactoring
src/test/java/com/example/model/ChatModelTest.java
Introduces @BeforeEach setup with ChatModel field. Adds four focused tests: testInitialState, testGetMessages, testAddMessageToList, testMessageOrder. Shifts assertions from NtfyMessage construction to ChatModel message list behavior and ordering.
NtfyMessage Test Migration
src/test/java/com/example/model/NtfyMesageTest.java
Removes Jackson ObjectMapper usage. Replaces serialization/deserialization tests with six constructor-based tests: testCreateMessage, testDefaultEventType, testNewMessageHasNullIdAndTime, testFullConstructor, testEmptyMessage, testMessageWithAttachment, testSpecialCharacters.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant ChatModel
    participant NtfyMessage

    rect rgb(200, 220, 255)
    Note over ChatModel: Input Validation (NEW)
    Caller->>ChatModel: sendMessage(text)
    alt text is null or blank
        ChatModel-->>Caller: throw IllegalArgumentException("Message cannot be empty")
    else text is valid
        ChatModel->>NtfyMessage: create NtfyMessage
        NtfyMessage-->>ChatModel: NtfyMessage instance
        ChatModel->>ChatModel: add to messages list
        ChatModel-->>Caller: success
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • ChatModelTest.java requires careful review of refactoring logic: verify all new test cases correctly validate message list state, ordering, and initialization.
  • NtfyMessageTest.java requires verification that constructor-based tests adequately cover field validation and behavior, especially with the removal of JSON serialization coverage.
  • ChatModel.java validation logic should be confirmed to align with expected behavior for null and blank input handling.

Poem

🐰 A hop through validation, tests refined anew,
Comments trimmed clean, and messages vetted true.
From Jackson's grasp to constructors we spring,
Lists ordered just right—hear the unit tests sing! 🎵

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Labb3' is vague and generic, providing no meaningful information about the specific changes in the pull request. Use a descriptive title that summarizes the main changes, such as 'Add input validation to ChatModel and refactor tests' or 'Implement message validation and update test suite'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Labb3

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/main/java/com/example/model/NtfyMessage.java (1)

12-20: Record definition and convenience constructors look good; consider clarifying attachment semantics

The record shape and the two convenience constructors (defaulting event to "message" and id/time to null) are consistent and easy to work with. Since attachment is nullable, it might be useful (in Javadoc or class-level comments elsewhere) to briefly document what values are expected (e.g., file name vs URL, when it can be null) to guide future callers.

src/main/java/com/example/model/ChatModel.java (1)

50-57: Input validation in sendMessage is correct; add tests and UI handling

The null/blank check with text == null || text.trim().isEmpty() and throwing IllegalArgumentException("Message cannot be empty") is a solid guard and avoids sending useless messages.

To fully close the loop, consider:

  • Adding unit tests that assert this exception is thrown for null and whitespace-only input.
  • Ensuring the UI layer catches this exception (or checks input upfront) and surfaces a friendly validation message instead of letting it propagate unexpectedly.
src/test/java/com/example/model/NtfyMesageTest.java (1)

10-82: Constructor/field tests are solid; consider minor naming and assertion polish

These tests give good coverage of NtfyMessage behavior: convenience vs canonical constructor, default event, null id/time, attachment handling, empty text, and special characters. That aligns well with how the record is defined.

A couple of minor, non-blocking suggestions:

  • The file name NtfyMesageTest.java does not match the class name NtfyMessageTest; consider renaming the file for consistency with standard Java conventions and easier navigation.
  • In testFullConstructor, you could also assert that attachment is null to fully exercise all fields created there (similar for other tests where it matters).

These are nice-to-have improvements; the current tests are already useful.

src/test/java/com/example/model/ChatModelTest.java (1)

3-56: Tests capture list behavior but are tightly coupled to real ChatModel/network

The refactor to a shared ChatModel instance with @BeforeEach and the assertions around an initially empty, ordered messages list all look correct and readable.

Two non-blocking design points to consider:

  • Dependency injection for tests: new ChatModel() immediately creates an NtfyHttpClient and calls connect(), which may hit a real ntfy server or fail noisily. For more stable unit tests, it would be cleaner if ChatModel accepted a ChatNetworkClient (and maybe baseUrl/topic) via a constructor so tests can pass a stub/mock that does not perform network I/O.
  • Slight duplication: testInitialState and testGetMessages both assert that getMessages() is non-null and empty. You could merge these into a single test or differentiate them (e.g., one focusing on type/observability, the other on state) to reduce duplication.

The current tests are fine functionally; these changes would mainly improve test robustness and maintainability.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 403ae72 and 6e945ca.

📒 Files selected for processing (5)
  • README.md (1 hunks)
  • src/main/java/com/example/model/ChatModel.java (1 hunks)
  • src/main/java/com/example/model/NtfyMessage.java (1 hunks)
  • src/test/java/com/example/model/ChatModelTest.java (1 hunks)
  • src/test/java/com/example/model/NtfyMesageTest.java (1 hunks)
🔇 Additional comments (1)
README.md (1)

19-21: Author section addition is clear and non-intrusive

The new Author section reads clearly and fits well after the run instructions. No technical or structural concerns from a project/documentation perspective.

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.

1 participant