BAEL-5729 Convert Hex to RGB Using Java (#13432)

This commit is contained in:
Michael Olayemi 2023-02-11 05:19:29 +01:00 committed by GitHub
parent 5fb9fe4642
commit 749cace098
4 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-hex</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-hex</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
</dependencies>
<properties>
</properties>
</project>

View File

@ -0,0 +1,25 @@
package com.baeldung.hextorgb;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class HexToRgbUnitTest {
@Test
public void givenHexCode_whenConvertedToRgb_thenCorrectRgbValuesAreReturned() {
String hexCode = "FF9933";
int red = 255;
int green = 153;
int blue = 51;
int resultRed = Integer.valueOf(hexCode.substring(0, 2), 16);
int resultGreen = Integer.valueOf(hexCode.substring(2, 4), 16);
int resultBlue = Integer.valueOf(hexCode.substring(4, 6), 16);
assertEquals(red, resultRed);
assertEquals(green, resultGreen);
assertEquals(blue, resultBlue);
}
}

View File

@ -62,6 +62,7 @@
<module>core-java-exceptions-4</module>
<module>core-java-function</module>
<module>core-java-functional</module>
<module>core-java-hex</module>
<module>core-java-io</module>
<module>core-java-io-2</module>
<module>core-java-io-3</module>