[seam-commits] Seam SVN: r13463 - in sandbox/modules/spreadsheet/src: test/java/org/jboss/seam/spreadsheet/jxl and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Jul 21 08:40:44 EDT 2010


Author: nickarls
Date: 2010-07-21 08:40:44 -0400 (Wed, 21 Jul 2010)
New Revision: 13463

Modified:
   sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java
   sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
Log:
constant-factory tests

Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java	2010-07-21 12:35:37 UTC (rev 13462)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/ConstantFactory.java	2010-07-21 12:40:44 UTC (rev 13463)
@@ -1,6 +1,7 @@
 package org.jboss.seam.spreadsheet.jxl.formatting;
 
 import java.lang.reflect.Field;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -43,7 +44,7 @@
       underlineStyles = loadConstants(UnderlineStyle.values(), jxl.format.UnderlineStyle.class);
       numberFormats = loadConstants(DisplayFormat.class, NumberFormats.class);
       dateFormats = loadConstants(DisplayFormat.class, DateFormats.class);
-      numberFormatShorthands = loadConstants(String.class, NumberFormat.class);
+      numberFormatShorthands = loadConstants(String.class, NumberFormat.class, new String[] { "COMPLEX_FORMAT" });
       orientations = loadConstants(Orientation.values(), jxl.format.Orientation.class);
       alignments = loadConstants(Alignment.values(), jxl.format.Alignment.class);
       verticalAlignments = loadConstants(VerticalAlignment.values(), jxl.format.VerticalAlignment.class);
@@ -53,11 +54,15 @@
    }
 
    @SuppressWarnings("unchecked")
-   private <V> Map<String, V> loadConstants(Class<V> valueClass, Class<?> sourceClass)
+   public <V> Map<String, V> loadConstants(Class<V> valueClass, Class<?> sourceClass, String[] ignoreFields)
    {
       Map<String, V> constants = new HashMap<String, V>();
       for (Field field : sourceClass.getFields())
       {
+         if (Arrays.binarySearch(ignoreFields, field.getName()) >= 0)
+         {
+            continue;
+         }
          try
          {
             constants.put(field.getName(), (V) field.get(null));
@@ -70,6 +75,11 @@
       return constants;
    }
 
+   public <V> Map<String, V> loadConstants(Class<V> valueClass, Class<?> sourceClass)
+   {
+      return loadConstants(valueClass, sourceClass, new String[] {});
+   }
+
    public jxl.format.Colour getColour(Colour colour)
    {
       checkConstantPresent(colours, colour, "Color");
@@ -118,6 +128,7 @@
          }
       }
       return constants;
+
    }
 
    public DisplayFormat getNumberFormat(String mask)

Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java	2010-07-21 12:35:37 UTC (rev 13462)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java	2010-07-21 12:40:44 UTC (rev 13463)
@@ -1,29 +1,50 @@
 package org.jboss.seam.spreadsheet.jxl;
 
+import java.util.Map;
+
+import jxl.biff.DisplayFormat;
+import jxl.write.DateFormat;
+import jxl.write.DateFormats;
+import jxl.write.NumberFormat;
+import jxl.write.NumberFormats;
+
 import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
 import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
 import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
 import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.Test;
 
 public class ConstantFactoryTest extends SpreadsheetTest
 {
+   ConstantFactory constantFactory;
+
+   @Before
+   public void init()
+   {
+      constantFactory = new ConstantFactory();
+   }
+
    @Test
    public void coloursTest()
    {
-      ConstantFactory constantFactory = new ConstantFactory();
       for (Colour colour : Colour.values())
       {
          Assert.assertNotNull(constantFactory.getColour(colour));
       }
    }
-   
+
    @Test
    public void underlineStyleTest()
    {
-      ConstantFactory constantFactory = new ConstantFactory();
       for (UnderlineStyle underlineStyle : UnderlineStyle.values())
       {
          Assert.assertNotNull(constantFactory.getUnderlineStyle(underlineStyle));
@@ -33,11 +54,94 @@
    @Test
    public void scriptStyleTest()
    {
-      ConstantFactory constantFactory = new ConstantFactory();
       for (ScriptStyle scriptStyle : ScriptStyle.values())
       {
          Assert.assertNotNull(constantFactory.getScriptStyle(scriptStyle));
       }
    }
 
+   @Test
+   public void borderLineTest()
+   {
+      for (BorderLineStyle borderLineStyle : BorderLineStyle.values())
+      {
+         Assert.assertNotNull(constantFactory.getBorderLineStyle(borderLineStyle));
+      }
+   }
+
+   @Test
+   public void borderTypeTest()
+   {
+      for (BorderType borderType : BorderType.values())
+      {
+         Assert.assertNotNull(constantFactory.getBorder(borderType));
+      }
+   }
+
+   @Test
+   public void patternTest()
+   {
+      for (Pattern pattern : Pattern.values())
+      {
+         Assert.assertNotNull(constantFactory.getPattern(pattern));
+      }
+   }
+
+   @Test
+   public void verticalAlignmentTest()
+   {
+      for (VerticalAlignment verticalAlignment : VerticalAlignment.values())
+      {
+         Assert.assertNotNull(constantFactory.getVerticalAlignment(verticalAlignment));
+      }
+   }
+
+   @Test
+   public void orientationTest()
+   {
+      for (Orientation orientation : Orientation.values())
+      {
+         Assert.assertNotNull(constantFactory.getOrientation(orientation));
+      }
+   }
+
+   @Test
+   public void alignmentTest()
+   {
+      for (Alignment alignment : Alignment.values())
+      {
+         Assert.assertNotNull(constantFactory.getAlignment(alignment));
+      }
+   }
+
+   @Test
+   public void numberFormatTest()
+   {
+      Map<String, DisplayFormat> numberFormats = constantFactory.loadConstants(DisplayFormat.class, NumberFormats.class);
+      for (String key : numberFormats.keySet())
+      {
+         Assert.assertNotNull(constantFactory.getNumberFormat(key));
+      }
+   }
+
+   @Test
+   public void numberFormatShorthandTest()
+   {
+      Map<String, String> numberFormatShorthands = constantFactory.loadConstants(String.class, NumberFormat.class);
+      for (String key : numberFormatShorthands.keySet())
+      {
+//         Assert.assertNotNull(constantFactory.getNumberFormatShorthand(key));
+      }
+   }
+
+   @Test
+   public void dateFormatTest()
+   {
+      Map<String, DisplayFormat> dateFormats = constantFactory.loadConstants(DisplayFormat.class, DateFormats.class);
+      for (String key : dateFormats.keySet())
+      {
+         Assert.assertNotNull(constantFactory.getDateFormat(key));
+      }
+   }
+
 }



More information about the seam-commits mailing list