Closed Josef-Friedrich closed 1 month ago
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()); } }
@Gamebuster19901 thank you for your review! All your suggestions make sense. I have tried to implement all your suggestions. Hopefully I have succeeded.
This prevents the variables and their value assignments from having to be repeated four times.
Instead of
DRY Don’t repeat yourself ->