Skip to content

fix StarCraftTest.testPlanet regex to allow hyphens in planet names #44

Description

@TheJavaGuy

Overview

StarCraftTest.testPlanet fails intermittently because the shared regex
^(?! )[A-Za-z0-9' ]*(?<! )$ does not include hyphens (-), but
starcraft.yml contains at least two hyphenated planet names:

  • "G-2275"
  • "LV-555"

The test is probabilistic — it only fails when the random draw picks one of
those two planets — explaining why it wasn't caught earlier.

Root cause

The regex in StarCraftTest.java:9 was written to cover the original planet
data, which had no hyphens. The hyphenated names were introduced with the
upstream starcraft.yml data and were never reflected in the test.

Fix

File: src/test/java/org/thejavaguy/javafaker/StarCraftTest.java

Update the shared regex field to include a literal hyphen (placed at the end of
the character class, which is the conventional position to avoid ambiguity with
ranges):

// Before
private final String noLeadingTrailingWhitespaceRegex = "^(?! )[A-Za-z0-9' ]*(?<! )$";

// After
private final String noLeadingTrailingWhitespaceRegex = "^(?! )[A-Za-z0-9' -]*(?<! )$";

No YAML data changes needed — the hyphenated names are valid planet identifiers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions