Categorize2Color extends Categorize<ColorParameter, ColorLiteral> implements ColorParameter { @Override public Color getColor(ResultSet rs, long fid) throws ParameterException { if (rs == null) { throw new ParameterException("No feature"); } return getParameter(rs, fid).getColor(rs, fid); } Categorize2Color(ColorParameter initialClass, ColorLiteral fallback, RealParameter lookupValue);  Categorize2Color(JAXBElement<CategorizeType> expr); @Override Color getColor(ResultSet rs, long fid); @Override Color getColor(Map<String,Object> map);  }
@Test public void testConstructor(){ assertTrue(categorize.getNumClasses() == 1); try { assertTrue(categorize.get(0).getColor(null, -1) == class1.getColor(null, -1)); } catch (ParameterException ex) { Logger.getLogger(Categorize2ColorTest.class.getName()).log(Level.SEVERE, null, ex); } }
@Test public void testAddClasses(){ try { categorize.put(t1, class2); assertTrue(categorize.getNumClasses() == 2); assertTrue(categorize.get(0).getColor(null, -1) == class1.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class2.getColor(null, -1)); categorize.put(t2, class3); assertTrue(categorize.getNumClasses() == 3); assertTrue(categorize.get(0).getColor(null, -1) == class1.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class2.getColor(null, -1)); assertTrue(categorize.get(2).getColor(null, -1) == class3.getColor(null, -1)); categorize.put(t3, class4); assertTrue(categorize.getNumClasses() == 4); assertTrue(categorize.get(0).getColor(null, -1) == class1.getColor(null, -1)); assertTrue(categorize.get(2).getColor(null, -1) == class2.getColor(null, -1)); assertTrue(categorize.get(3).getColor(null, -1) == class3.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class4.getColor(null, -1)); } catch (ParameterException ex) { Logger.getLogger(Categorize2ColorTest.class.getName()).log(Level.SEVERE, null, ex); } }
@Test public void testSetThresholds(){ try { getCategorize(); categorize.setThreshold(2, t4); assertTrue(categorize.getNumClasses() == 4); assertTrue(categorize.get(0).getColor(null, -1) == class1.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class4.getColor(null, -1)); assertTrue(categorize.get(2).getColor(null, -1) == class2.getColor(null, -1)); assertTrue(categorize.get(3).getColor(null, -1) == class3.getColor(null, -1)); double first = categorize.getThreshold(0).getValue(null, -1); assertTrue(Double.isInfinite(first) && first < 0); assertEquals(categorize.getThreshold(1).getValue(null, -1), t3.getValue(null, -1)); assertEquals(categorize.getThreshold(2).getValue(null, -1), t4.getValue(null, -1)); assertEquals(categorize.getThreshold(3).getValue(null, -1), t2.getValue(null, -1)); categorize.setThreshold(0, t5); assertTrue(categorize.getNumClasses() == 4); assertTrue(categorize.get(0).getColor(null, -1) == class4.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class2.getColor(null, -1)); assertTrue(categorize.get(2).getColor(null, -1) == class3.getColor(null, -1)); assertTrue(categorize.get(3).getColor(null, -1) == class1.getColor(null, -1)); first = categorize.getThreshold(0).getValue(null, -1); assertTrue(Double.isInfinite(first) && first < 0); assertEquals(categorize.getThreshold(1).getValue(null, -1), t4.getValue(null, -1)); assertEquals(categorize.getThreshold(2).getValue(null, -1), t2.getValue(null, -1)); assertEquals(categorize.getThreshold(3).getValue(null, -1), t5.getValue(null, -1)); } catch (ParameterException ex) { Logger.getLogger(Categorize2ColorTest.class.getName()).log(Level.SEVERE, null, ex); } }
@Test public void testRemoveClasses(){ try { getCategorize(); categorize.remove(0); double first = categorize.getThreshold(0).getValue(null, -1); assertTrue(Double.isInfinite(first) && first < 0); assertTrue(categorize.getNumClasses() == 3); assertTrue(categorize.get(0).getColor(null, -1) == class4.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class2.getColor(null, -1)); assertTrue(categorize.get(2).getColor(null, -1) == class3.getColor(null, -1)); categorize.remove(2); first = categorize.getThreshold(0).getValue(null, -1); assertTrue(Double.isInfinite(first) && first < 0); assertTrue(categorize.getNumClasses() == 2); assertTrue(categorize.get(0).getColor(null, -1) == class4.getColor(null, -1)); assertTrue(categorize.get(1).getColor(null, -1) == class2.getColor(null, -1)); categorize.remove(1); first = categorize.getThreshold(0).getValue(null, -1); assertTrue(Double.isInfinite(first) && first < 0); assertTrue(categorize.getNumClasses() == 1); assertTrue(categorize.get(0).getColor(null, -1) == class4.getColor(null, -1)); } catch (ParameterException ex) { Logger.getLogger(Categorize2ColorTest.class.getName()).log(Level.SEVERE, null, ex); } }
@Test public void testNullGivesFallback() throws Exception { String fname = "youhou"; categorize.setLookupValue(new RealAttribute(fname)); categorize.put(t1, class2); HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put(fname, null); Color cpm = categorize.getColor(hm); assertTrue(cpm == categorize.getFallbackValue().getColor(null, -1)); }
@Test public void testFromJaxb() throws Exception { Categorize2Color c2c = getFromJaxb(); assertTrue(c2c.get(0).getColor(null, 0).equals(new Color(0x11, 0x33, 0x55))); assertTrue(c2c.get(1).getColor(null, 0).equals(new Color(0xdd, 0x66, 0xee))); assertTrue(c2c.get(2).getColor(null, 0).equals(new Color(0xff, 0xaa, 0x99))); }