Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the color decode test by using a nested class #819

Merged

Conversation

Josef-Friedrich
Copy link
Contributor

@Josef-Friedrich Josef-Friedrich commented May 12, 2024

This prevents the variables and their value assignments from having to be repeated four times.

Instead of

  @Test
  void testRedFromAlphaHexString() {
    String red200 = "#c8ff0000";

    Color redDecoded = ColorHelper.decode(red200);

    Color alphaRed = new Color(255, 0, 0, 200);
    assertEquals(alphaRed.getRed(), redDecoded.getRed());
  }

  @Test
  void testGreenFromAlphaHexString() {
    String red200 = "#c8ff0000";

    Color redDecoded = ColorHelper.decode(red200);

    Color alphaRed = new Color(255, 0, 0, 200);
    assertEquals(alphaRed.getGreen(), redDecoded.getGreen());
  }

  @Test
  void testBlueFromAlphaHexString() {
    String red200 = "#c8ff0000";

    Color redDecoded = ColorHelper.decode(red200);

    Color alphaRed = new Color(255, 0, 0, 200);
    assertEquals(alphaRed.getBlue(), redDecoded.getBlue());
  }

  @Test
  void testAlphaFromAlphaHexString() {
    String red200 = "#c8ff0000";

    Color redDecoded = ColorHelper.decode(red200);

    Color alphaRed = new Color(255, 0, 0, 200);
    assertEquals(alphaRed.getAlpha(), redDecoded.getAlpha());
  }

DRY Don’t repeat yourself ->

  @Nested
  class DecodeTest
  {
      String red200 = "#c8ff0000";

      Color redDecoded = ColorUtil.decode(red200);

      Color alphaRed = new Color(255, 0, 0, 200);

      @Test
      void testRedFromAlphaHexString() {
        assertEquals(alphaRed.getRed(), redDecoded.getRed());
      }

      @Test
      void testGreenFromAlphaHexString() {
        assertEquals(alphaRed.getGreen(), redDecoded.getGreen());
      }

      @Test
      void testBlueFromAlphaHexString() {
        assertEquals(alphaRed.getBlue(), redDecoded.getBlue());
      }

      @Test
      void testAlphaFromAlphaHexString() {
        assertEquals(alphaRed.getAlpha(), redDecoded.getAlpha());
      }
  }

This prevents the variables and their value assignments from
having to be repeated four times.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Amazing, your first Pull Request in the LITIENGINE repository! You have earned the rank of "contributor" - let us know your nickname in the Forum and on Discord so we can reward you with the new role :).

@Josef-Friedrich
Copy link
Contributor Author

@Gamebuster19901 thank you for your review! All your suggestions make sense. I have tried to implement all your suggestions. Hopefully I have succeeded.

Copy link
Member

@nightm4re94 nightm4re94 left a comment

Choose a reason for hiding this comment

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

Thanks a lot, both @Josef-Friedrich and @Gamebuster19901 :)

@nightm4re94 nightm4re94 merged commit e7e995f into gurkenlabs:main May 27, 2024
@Josef-Friedrich Josef-Friedrich deleted the refactor-color-helper-tests-decode branch May 29, 2024 14:11
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.

None yet

3 participants