You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2020/03/17 19:48:50 UTC

svn commit: r1875320 - /pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java

Author: rwhitcomb
Date: Tue Mar 17 19:48:50 2020
New Revision: 1875320

URL: http://svn.apache.org/viewvc?rev=1875320&view=rev
Log:
Add a CSSColorTest to thoroughly test all the round-trip paths.

Added:
    pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java

Added: pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java?rev=1875320&view=auto
==============================================================================
--- pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java (added)
+++ pivot/trunk/wtk/test/org/apache/pivot/wtk/test/CSSColorTest.java Tue Mar 17 19:48:50 2020
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.test;
+
+import java.awt.Color;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import org.apache.pivot.wtk.CSSColor;
+import org.apache.pivot.wtk.GraphicsUtilities;
+import org.apache.pivot.wtk.util.ColorUtilities;
+
+
+/**
+ * Tests the {@link CSSColor} enum and various {@link ColorUtilities} methods.
+ */
+public class CSSColorTest {
+    @Test
+    public void test() {
+        // We're going to do a full round-trip cycle to test everything
+        for (CSSColor css : CSSColor.values()) {
+            Color underlyingColor = css.getColor();
+            String name = css.getColorName();
+            CSSColor lookupByName = CSSColor.fromString(name);
+            assertEquals(css, lookupByName);
+
+            CSSColor lookupByColor = CSSColor.fromColor(underlyingColor);
+            assertEquals(css, lookupByColor);
+
+            String stringValue = ColorUtilities.toStringValue(css);
+            Color decodedColor = GraphicsUtilities.decodeColor(stringValue, name);
+            CSSColor lookupByDecodedValue = CSSColor.fromColor(decodedColor);
+            assertEquals(css, lookupByDecodedValue);
+
+            String enumName = ((Object)css).toString();
+            CSSColor lookupByEnumName = CSSColor.fromString(enumName);
+            assertEquals(css, lookupByEnumName);
+        }
+    }
+}