TreeMill { public static DerivationTree getDerivationTree(final GEGrammar gegrammar) { final DerivationTree derivationTree; if(gegrammar.getDerivationString() == null) { throw new NullPointerException("GEGrammar.derivationTreeType is null. Use key -"+Constants.DERIVATION_TREE+" and value is the class name"); } if(gegrammar.getDerivationString().equals(DerivationTree.class.getName())) { derivationTree = new DerivationTree(gegrammar, gegrammar.getGenotype()); } else if (gegrammar.getDerivationString().equals(ContextualDerivationTree.class.getName())) { derivationTree = new ContextualDerivationTree(gegrammar, gegrammar.getGenotype()); } else { derivationTree = null; throw new IllegalArgumentException("Illegal derivation tree:"+gegrammar.getDerivationString()); } return derivationTree; }  static DerivationTree getDerivationTree(final GEGrammar gegrammar);  }
@Test public void testGetDerivationTree() { System.out.println("testing ContextualDerivationTree"); DerivationTree result = TreeMill.getDerivationTree(cgeg); assertEquals(true,result instanceof ContextualDerivationTree); System.out.println("testing parent"); result = TreeMill.getDerivationTree(cgeg); assertEquals(true,result instanceof DerivationTree); System.out.println("testing false"); result = TreeMill.getDerivationTree(pageg); assertEquals(false,result instanceof ContextualDerivationTree); System.out.println("testing null"); GEIndividual gei = IndividualMaker.makeIndividual(); ((GEGrammar)gei.getMapper()).setDerivationTreeType(null); result = null; try { result = TreeMill.getDerivationTree((GEGrammar)gei.getMapper()); } catch(NullPointerException e) { assertTrue(true); } assertEquals(false,result instanceof DerivationTree); }