Created
February 4, 2012 14:23
-
-
Save rhiguchi/1738161 to your computer and use it in GitHub Desktop.
アルファ値を持つ16進数文字列からColorオブジェクトを作成するテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import java.awt.Color; | |
import org.junit.Test; | |
public class AlphaDigitsHexNumberColorDecodingTest { | |
@Test | |
public void decodeHexStringToColor() { | |
Color color = Color.decode("#000000"); | |
assertEquals("no-alpha", 255, color.getAlpha()); | |
assertEquals("red", 0, color.getRed()); | |
assertEquals("blue", 0, color.getBlue()); | |
assertEquals("green", 0, color.getGreen()); | |
} | |
@Test | |
public void decodeHexStringToColorWithAlpha() { | |
assertEquals("decode method ignores alpha digits", | |
255, Color.decode("#00000000").getAlpha()); | |
assertEquals("color construction with alpha", | |
0, new Color(Integer.decode("#00000000").intValue(), true).getAlpha()); | |
} | |
@Test | |
public void overflowToDecodeHexString() { | |
assertEquals("max value of integer", | |
127, new Color(Integer.decode("#7FFFFFFF").intValue(), true).getAlpha()); | |
Integer result = null; | |
try { | |
result = Integer.decode("#80000000"); | |
} | |
catch (NumberFormatException expected) { | |
assertNull("cannot format #80000000", result); | |
return; | |
} | |
fail("unreachable"); | |
} | |
@Test | |
public void decodeHexStringUsingDecodeOfLong() { | |
Color decode = new Color(Long.decode("#FFFFFFFF").intValue(), true); | |
assertEquals("alpha", 255, decode.getAlpha()); | |
assertEquals("red", 255, decode.getRed()); | |
assertEquals("blue", 255, decode.getBlue()); | |
assertEquals("green", 255, decode.getGreen()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment