r25 - in trunk/src: main/java/org/nuiton/mapstoragemanager/core test test/java test/java/org test/java/org/nuiton test/java/org/nuiton/mapstoragemanager test/java/org/nuiton/mapstoragemanager/core test/java/org/nuiton/mapstoragemanager/plugins test/java/org/nuiton/mapstoragemanager/plugins/bighashmap
Author: dlanglais Date: 2010-01-27 22:59:17 +0100 (Wed, 27 Jan 2010) New Revision: 25 Added: trunk/src/test/java/ trunk/src/test/java/org/ trunk/src/test/java/org/nuiton/ trunk/src/test/java/org/nuiton/mapstoragemanager/ trunk/src/test/java/org/nuiton/mapstoragemanager/core/ trunk/src/test/java/org/nuiton/mapstoragemanager/core/ServiceLoaderTest.java trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/ trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellTest.java trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnTest.java Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java trunk/src/main/java/org/nuiton/mapstoragemanager/core/TestServiceLoader.java Log: Ajout de classe de test, Correction checkstyle sur BigTableLoader et TestServiceLoader (je tente de passer les classes de test en classe de test JUnit). Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java 2010-01-27 12:20:57 UTC (rev 24) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/core/BigTableLoader.java 2010-01-27 21:59:17 UTC (rev 25) @@ -9,30 +9,29 @@ import org.nuiton.mapstoragemanager.plugins.BigTable; /** - * * @author Crieloue Gilles * */ -public class BigTableLoader extends URLClassLoader{ +public class BigTableLoader extends URLClassLoader { - /** - * The BigTable Set Loader. - */ - private ServiceLoader<BigTable> bigTableSetLoader; + /** + * The BigTable Set Loader. + */ + private ServiceLoader < BigTable > bigTableSetLoader; - /** - * Class constructor. - * @param pluginsFolderPath the plugins folder path - * @param classLoader the parent classloader - * @throws MalformedURLException if the plugin folder is not found - */ - public BigTableLoader(final String pluginsFolderPath, - final ClassLoader classLoader) throws MalformedURLException { + /** + * Class constructor. + * @param pluginsFolderPath the plugins folder path + * @param classLoader the parent classloader + * @throws MalformedURLException if the plugin folder is not found + */ + public BigTableLoader(final String pluginsFolderPath, + final ClassLoader classLoader) throws MalformedURLException { - super(new URL[]{new File(pluginsFolderPath).toURI().toURL()}, - classLoader); + super(new URL[]{new File(pluginsFolderPath).toURI().toURL()}, + classLoader); - for (File file : new File(pluginsFolderPath).listFiles()) { + for (File file : new File(pluginsFolderPath).listFiles()) { if (file.getAbsolutePath().endsWith(".jar")) { try { this.addURL(file.toURI().toURL()); @@ -43,32 +42,30 @@ } bigTableSetLoader = ServiceLoader.load(BigTable.class, this); - } + } - /** - * Returns a string displaying all the available BigTable implementations. - * @return a string displaying all the available BigTable implementations - */ + /** + * Returns a string displaying all the available BigTable implementations. + * @return a string displaying all the available BigTable implementations + */ public final String getBigTable() { - String s = "Available Plugins :\n"; + String s = "Available Plugins :\n"; - s += "\t* "; - if (!bigTableSetLoader.iterator().hasNext()) { - s += "No plugin."; - } - else { - for (BigTable bt : bigTableSetLoader) { - s += bt.getClass().getName(); - bt.put("key", "value"); - if (bt.get("key").equals("value")) { - s += " (working)" + "\n"; - } - else { - s += " (not working)" + "\n"; - } - } - } + s += "\t* "; + if (!bigTableSetLoader.iterator().hasNext()) { + s += "No plugin."; + } else { + for (BigTable bt : bigTableSetLoader) { + s += bt.getClass().getName(); + bt.put("key", "value"); + if (bt.get("key").equals("value")) { + s += " (working)" + "\n"; + } else { + s += " (not working)" + "\n"; + } + } + } return s; } @@ -76,8 +73,8 @@ * Returns the BigTable Set Loader. * @return the BigTable Set Loader */ - public final ServiceLoader<BigTable> getBigTableSetLoader() { - return bigTableSetLoader; - } + public final ServiceLoader < BigTable > getBigTableSetLoader() { + return bigTableSetLoader; + } } Modified: trunk/src/main/java/org/nuiton/mapstoragemanager/core/TestServiceLoader.java =================================================================== --- trunk/src/main/java/org/nuiton/mapstoragemanager/core/TestServiceLoader.java 2010-01-27 12:20:57 UTC (rev 24) +++ trunk/src/main/java/org/nuiton/mapstoragemanager/core/TestServiceLoader.java 2010-01-27 21:59:17 UTC (rev 25) @@ -3,18 +3,21 @@ import java.net.MalformedURLException; public class TestServiceLoader { - public TestServiceLoader(){ - try { - BigTableLoader p = new BigTableLoader("plugins", this.getClass().getClassLoader()); - System.out.println(p.getBigTable()); - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public static void main(String[] args) { - - TestServiceLoader t = new TestServiceLoader(); - } -} + + public TestServiceLoader() { + try { + BigTableLoader p = + new BigTableLoader("plugins", + this.getClass().getClassLoader()); + System.out.println(p.getBigTable()); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public static void main(final String[] args) { + + TestServiceLoader t = new TestServiceLoader(); + } +} \ No newline at end of file Added: trunk/src/test/java/org/nuiton/mapstoragemanager/core/ServiceLoaderTest.java =================================================================== --- trunk/src/test/java/org/nuiton/mapstoragemanager/core/ServiceLoaderTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/mapstoragemanager/core/ServiceLoaderTest.java 2010-01-27 21:59:17 UTC (rev 25) @@ -0,0 +1,15 @@ +package org.nuiton.mapstoragemanager.core; + +import junit.framework.TestCase; + +/** + * Classe to test the Core class. + * @author Dorian Langlais + * + */ +public class ServiceLoaderTest extends TestCase { + + public void testCore(){ + + } +} Added: trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellTest.java =================================================================== --- trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/CellTest.java 2010-01-27 21:59:17 UTC (rev 25) @@ -0,0 +1,85 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmap; + +import org.nuiton.mapstoragemanager.plugins.bighashmap.Cell; +import java.util.NoSuchElementException; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Classe de test pour la classe Cell. + * Teste les fonctions de base d'une cellule, put et get. + * @author Dorian Langlais + * + */ +public final class CellTest extends TestCase { + + /** + * On teste le comportement de get avec une cellule vide. + */ + public void testGetVoid() { + Cell < Object > cell = new CellImpl < Object > (); + try { + assertNull(cell.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + System.out.println("Exception levée correctement"); + } + } + + /** + * Test de la fonction put sur une cellule. + * On ajoute un objet obj1, on tente de le récupérer. + */ + public void testPut() { + + Cell < Object > cell = new CellImpl < Object > (); + + Object obj1 = new Object(); + + try { + assertNull(cell.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + System.out.println("Exception levée correctement"); + } + cell.put(obj1); + + assertEquals(cell.get(), obj1); + } + + /** + * Test de la fonction put sur une cellule. + * On ajoute un objet obj1, on tente de le récupérer. + * On ajoute un objet obj2, on tente de le récupérer. + * On ajoute un objet obj3, on tente de le récupérer. + */ + public void testPutReput() { + + Cell < Object > cell = new CellImpl < Object > (); + + Object obj1 = new Object(); + + try { + assertNull(cell.get()); + Assert.fail(); + } catch (NoSuchElementException e) { + System.out.println("Exception levée correctement"); + } + cell.put(obj1); + + assertEquals(cell.get(), obj1); + + Object obj2 = new Object(); + + cell.put(obj2); + + assertEquals(cell.get(), obj2); + + Object obj3 = new Object(); + + cell.put(obj3); + + assertEquals(cell.get(), obj3); + } +} Added: trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnTest.java =================================================================== --- trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnTest.java (rev 0) +++ trunk/src/test/java/org/nuiton/mapstoragemanager/plugins/bighashmap/ColumnTest.java 2010-01-27 21:59:17 UTC (rev 25) @@ -0,0 +1,44 @@ +package org.nuiton.mapstoragemanager.plugins.bighashmap; + +import java.util.NoSuchElementException; + +import junit.framework.Assert; +import junit.framework.TestCase; + +public final class ColumnTest extends TestCase { + + /** + * On teste le comportement de get avec une cellule vide. + */ + public void testGetVoid() { + Column < Object > col = new ColumnImpl < Object > (); + try { + col.get("test"); + Assert.fail(); + } catch (NoSuchElementException e) { + System.out.println("Exception levée correctement"); + } + } + + /** + * On ajoute un objet avec une clé. + * On tente de récupérer celui-ci. + */ + public void testPut() { + Column < Object > col = new ColumnImpl < Object > (); + + Object obj1 = new Object(); + + try { + col.get("object 1"); + Assert.fail(); + } catch (NoSuchElementException e) { + System.out.println("Exception levée correctement"); + } + + col.put("object 1", obj1); + + assertEquals(col.get("object 1"), obj1); + + } +}
participants (1)
-
dlanglais@users.nuiton.org