Skip to content
Snippets Groups Projects
Commit 03d9045f authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Modified some tests; Fixed the RoleStringConverter class in order to suit the...

Modified some tests; Fixed the RoleStringConverter class in order to suit the API description; Added another FB filter and added some comments to the file.
parent 6eb605a8
Branches
Tags
No related merge requests found
Showing
with 375 additions and 63 deletions
...@@ -11,7 +11,12 @@ ...@@ -11,7 +11,12 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src/test/java"/> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
... ...
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
... ...
......
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//src/main/java=UTF-8 encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8
<FindBugsFilter> <FindBugsFilter>
<!-- This class is full of necessary hacks. -->
<Match> <Match>
<Class name="kieker.webgui.persistence.impl.util.CloseableURLClassLoader" /> <Class name="kieker.webgui.persistence.impl.util.CloseableURLClassLoader" />
<Bug code="DP, RI" /> <Bug code="DP, RI" />
</Match> </Match>
<!-- Ignores the fact that we don't close database connections in the DAO. The connections are automatically closed. -->
<Match> <Match>
<Class name="kieker.webgui.persistence.impl.DerbyUserDAOImpl" /> <Class name="kieker.webgui.persistence.impl.DerbyUserDAOImpl" />
<Bug code="ODR, OBL" /> <Bug code="ODR, OBL" />
</Match> </Match>
<!-- Ignores the fact that we ignore the return values of some delete methods. -->
<Match>
<Class name="kieker.webgui.persistence.impl.FSProjectDAOImpl" />
<Method name="addProject" params="java.lang.String, java.lang.String" returns="void" />
<Bug code="RV" />
</Match>
</FindBugsFilter> </FindBugsFilter>
\ No newline at end of file
...@@ -19,6 +19,7 @@ package kieker.webgui.web.converter; ...@@ -19,6 +19,7 @@ package kieker.webgui.web.converter;
import javax.faces.component.UIComponent; import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.convert.Converter; import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter; import javax.faces.convert.FacesConverter;
import kieker.webgui.domain.Role; import kieker.webgui.domain.Role;
...@@ -40,15 +41,25 @@ public class RoleStringConverter implements Converter { ...@@ -40,15 +41,25 @@ public class RoleStringConverter implements Converter {
@Override @Override
public Object getAsObject(final FacesContext context, final UIComponent comp, final String str) { public Object getAsObject(final FacesContext context, final UIComponent comp, final String str) {
if (str == null) {
return null;
} else {
try {
return Role.valueOf(str); return Role.valueOf(str);
} catch (final IllegalArgumentException ex) {
throw new ConverterException("The given string is not a valid role", ex);
}
}
} }
@Override @Override
public String getAsString(final FacesContext context, final UIComponent comp, final Object obj) { public String getAsString(final FacesContext context, final UIComponent comp, final Object obj) {
if (obj instanceof Role) { if (obj == null) {
return "";
} else if (obj instanceof Role) {
return ((Role) obj).toString(); return ((Role) obj).toString();
} else { } else {
return ""; throw new ConverterException("The class of the given object is invalid");
} }
} }
... ...
......
...@@ -74,12 +74,12 @@ public class ExceptionsExtendingAbstractClassTest { ...@@ -74,12 +74,12 @@ public class ExceptionsExtendingAbstractClassTest {
} }
private static Collection<File> listJavaSourceFiles() { private static Collection<File> listJavaSourceFiles() {
final IOFileFilter filter = new RegexFileFilter(ExceptionsExtendingAbstractClassTest.PATTERN_EXCEPTION_SOURCE_FILES); final IOFileFilter filter = new RegexFileFilter(PATTERN_EXCEPTION_SOURCE_FILES);
return FileUtils.listFiles(new File(ExceptionsExtendingAbstractClassTest.DIR_NAME_SOURCES), filter, TrueFileFilter.INSTANCE); return FileUtils.listFiles(new File(DIR_NAME_SOURCES), filter, TrueFileFilter.INSTANCE);
} }
private static boolean isSourceFileInExceptionPackage(final File file) { private static boolean isSourceFileInExceptionPackage(final File file) {
return file.getAbsolutePath().contains(ExceptionsExtendingAbstractClassTest.PATTERN_EXCEPTION_PACKAGE); return file.getAbsolutePath().contains(PATTERN_EXCEPTION_PACKAGE);
} }
private static boolean doesClassExtendAbstractKiekerWebGUIException(final Class<?> clazz) { private static boolean doesClassExtendAbstractKiekerWebGUIException(final Class<?> clazz) {
...@@ -90,8 +90,8 @@ public class ExceptionsExtendingAbstractClassTest { ...@@ -90,8 +90,8 @@ public class ExceptionsExtendingAbstractClassTest {
final String pathName = file.getPath(); final String pathName = file.getPath();
String className = pathName.replace("\\", "."); String className = pathName.replace("\\", ".");
className = className.substring(ExceptionsExtendingAbstractClassTest.UNNECESSARY_PREFIX.length()); className = className.substring(UNNECESSARY_PREFIX.length());
className = className.substring(0, className.length() - ExceptionsExtendingAbstractClassTest.UNNECESSARY_SUFFIX.length()); className = className.substring(0, className.length() - UNNECESSARY_SUFFIX.length());
return className; return className;
} }
... ...
......
/***************************************************************************
* Copyright 2012 Kieker Project (http://kieker-monitoring.net)
*
* Licensed 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 kieker.webgui.persistence.impl.util;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import org.junit.Assert;
import org.junit.Test;
import kieker.analysis.model.analysisMetaModel.MIFilter;
import kieker.analysis.model.analysisMetaModel.MIReader;
import kieker.analysis.model.analysisMetaModel.MIRepository;
import kieker.analysis.plugin.filter.forward.CountingFilter;
import kieker.analysis.plugin.reader.timer.TimeReader;
import kieker.tools.traceAnalysis.systemModel.repository.SystemModelRepository;
import kieker.webgui.common.ClassAndMethodContainer;
import kieker.webgui.common.exception.ReflectionException;
/**
* Test class for {@link Class2ModelInstanceConverter}.
*
* @author Nils Christian Ehmke
*/
public class Class2ModelInstanceConverterTest {
private static final String KIEKER_LIB = "kieker.jar";
/**
* Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b>
*/
public Class2ModelInstanceConverterTest() {
// No code necessary
}
/**
* A test which loads dynamically a reader from the Kieker library and checks the converting.
*
* @throws ReflectionException
* If something went wrong.
* @throws IOException
* If something went wrong.
*/
@Test
public void testReaderConverting() throws ReflectionException, IOException {
final PluginFinder pluginFinder = new PluginFinder();
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(KIEKER_LIB);
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null);
final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader);
final Class2ModelInstanceConverter converter = new Class2ModelInstanceConverter();
final Collection<Class<?>> readers = pluginFinder.getAllReadersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
// Find the class of the TimeReader
Class<?> timeReaderClass = null;
for (final Class<?> reader : readers) {
if (TimeReader.class.getCanonicalName().equals(reader.getCanonicalName())) {
timeReaderClass = reader;
break;
}
}
if (timeReaderClass == null) {
Assert.fail("TimeReader not available");
}
// Convert and check the reader
final MIReader reader = converter.convertReaderClass2ModelInstance(timeReaderClass, classAndMethodContainer);
Assert.assertEquals("Properties are not loaded correctly", timeReaderClass.getCanonicalName(), reader.getClassname());
Assert.assertTrue("Properties are not loaded correctly", reader.getDisplays().isEmpty());
Assert.assertTrue("Properties are not loaded correctly", reader.getRepositories().isEmpty());
Assert.assertEquals("Properties are not loaded correctly", 2, reader.getOutputPorts().size());
Assert.assertEquals("Properties are not loaded correctly", 3, reader.getProperties().size());
classLoader.close();
}
/**
* A test which loads dynamically a filter from the Kieker library and checks the converting.
*
* @throws ReflectionException
* If something went wrong.
* @throws IOException
* If something went wrong.
*/
@Test
public void testFilterConverting() throws ReflectionException, IOException {
final PluginFinder pluginFinder = new PluginFinder();
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(KIEKER_LIB);
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null);
final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader);
final Class2ModelInstanceConverter converter = new Class2ModelInstanceConverter();
final Collection<Class<?>> filters = pluginFinder.getAllFiltersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
// Find the class of the CountingFilter
Class<?> countingFilterCLass = null;
for (final Class<?> filter : filters) {
if (CountingFilter.class.getCanonicalName().equals(filter.getCanonicalName())) {
countingFilterCLass = filter;
break;
}
}
if (countingFilterCLass == null) {
Assert.fail("CountingFilter not available");
}
// Convert and check the reader
final MIFilter filter = converter.convertFilterClass2ModelInstance(countingFilterCLass, classAndMethodContainer);
Assert.assertEquals("Properties are not loaded correctly", countingFilterCLass.getCanonicalName(), filter.getClassname());
Assert.assertEquals("Properties are not loaded correctly", 3, filter.getDisplays().size());
Assert.assertTrue("Properties are not loaded correctly", filter.getRepositories().isEmpty());
Assert.assertEquals("Properties are not loaded correctly", 2, filter.getOutputPorts().size());
Assert.assertEquals("Properties are not loaded correctly", 1, filter.getInputPorts().size());
Assert.assertTrue("Properties are not loaded correctly", filter.getProperties().isEmpty());
classLoader.close();
}
/**
* A test which loads dynamically a repository from the Kieker library and checks the converting.
*
* @throws ReflectionException
* If something went wrong.
* @throws IOException
* If something went wrong.
*/
@Test
public void testRepositoryConverting() throws ReflectionException, IOException {
final PluginFinder pluginFinder = new PluginFinder();
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(KIEKER_LIB);
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null);
final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader);
final Class2ModelInstanceConverter converter = new Class2ModelInstanceConverter();
final Collection<Class<?>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer);
// Find the class of the SystemModelRepository
Class<?> systemModelRepository = null;
for (final Class<?> repository : repositories) {
if (SystemModelRepository.class.getCanonicalName().equals(repository.getCanonicalName())) {
systemModelRepository = repository;
break;
}
}
if (systemModelRepository == null) {
Assert.fail("SystemModelRepository not available");
}
// Convert and check the reader
final MIRepository repository = converter.convertRepositoryClass2ModelInstance(systemModelRepository, classAndMethodContainer);
Assert.assertEquals("Properties are not loaded correctly", systemModelRepository.getCanonicalName(), repository.getClassname());
Assert.assertTrue("Properties are not loaded correctly", repository.getProperties().isEmpty());
classLoader.close();
}
}
/***************************************************************************
* Copyright 2012 Kieker Project (http://kieker-monitoring.net)
*
* Licensed 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 kieker.webgui.persistence.impl.util;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import org.junit.Assert;
import org.junit.Test;
import com.google.common.io.Files;
import kieker.analysis.AnalysisController;
/**
* Test class for {@link CloseableURLClassLoader}.
*
* @author Nils Christian Ehmke
*/
public class CloseableURLClassLoaderTest {
private static final String KIEKER_LIB = "kieker.jar";
/**
* Default constructor. <b>Do not use this constructor. This is just a test class and not to be used outside a JUnit test!</b>
*/
public CloseableURLClassLoaderTest() {
// No code necessary
}
/**
* A test making sure that the class loader loads classes correctly.
*
* @throws URISyntaxException
* If something went wrong.
* @throws IOException
* If something went wrong.
*/
@Test
public void testClassLoading() throws IOException, URISyntaxException {
// Copy the kieker jar into a temporary directory
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(KIEKER_LIB);
final File tempDir = Files.createTempDir();
final File newJar = new File(tempDir, KIEKER_LIB);
Files.copy(new File(kiekerURL.toURI()), newJar);
// Create the loader
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { newJar.toURI().toURL() }, null);
// It should now be possible to load one of Kieker's classes
try {
classLoader.loadClass(AnalysisController.class.getCanonicalName());
} catch (final ClassNotFoundException ex) {
Assert.fail("Could not load class");
}
classLoader.close();
}
/**
* A test making sure that class loader can be closed.
*
* @throws URISyntaxException
* If something went wrong.
* @throws IOException
* If something went wrong.
*/
@Test
public void testClosing() throws IOException, URISyntaxException {
// Copy the kieker jar into a temporary directory
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(KIEKER_LIB);
final File tempDir = Files.createTempDir();
final File newJar = new File(tempDir, KIEKER_LIB);
Files.copy(new File(kiekerURL.toURI()), newJar);
// Create and close the class loader
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { newJar.toURI().toURL() }, null);
classLoader.close();
// It should be possible to delete the file now.
Assert.assertTrue("Classloader does not close correctly", newJar.delete());
}
}
...@@ -43,19 +43,20 @@ public class PluginFinderTest { ...@@ -43,19 +43,20 @@ public class PluginFinderTest {
} }
/** /**
* A test of this test class. * A test making sure that the kieker plugins are available.
* *
* @throws ReflectionException * @throws ReflectionException
* If something went wrong. * If something went wrong.
* @throws IOException
* If something went wrong.
*/ */
@Test @Test
public void testKiekerPlugins() throws ReflectionException { public void testKiekerPlugins() throws ReflectionException, IOException {
final PluginFinder pluginFinder = new PluginFinder(); final PluginFinder pluginFinder = new PluginFinder();
final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(PluginFinderTest.KIEKER_LIB); final URL kiekerURL = Thread.currentThread().getContextClassLoader().getResource(PluginFinderTest.KIEKER_LIB);
final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null); final CloseableURLClassLoader classLoader = new CloseableURLClassLoader(new URL[] { kiekerURL }, null);
final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader); final ClassAndMethodContainer classAndMethodContainer = new ClassAndMethodContainer(classLoader);
try {
final Collection<Class<?>> filters = pluginFinder.getAllFiltersWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> filters = pluginFinder.getAllFiltersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
final Collection<Class<?>> readers = pluginFinder.getAllReadersWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> readers = pluginFinder.getAllReadersWithinJar(kiekerURL, classLoader, classAndMethodContainer);
final Collection<Class<?>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer); final Collection<Class<?>> repositories = pluginFinder.getAllRepositoriesWithinJar(kiekerURL, classLoader, classAndMethodContainer);
...@@ -66,9 +67,6 @@ public class PluginFinderTest { ...@@ -66,9 +67,6 @@ public class PluginFinderTest {
Assert.assertFalse("No repositories found.", repositories.isEmpty()); Assert.assertFalse("No repositories found.", repositories.isEmpty());
classLoader.close(); classLoader.close();
} catch (final IOException ex) {
Assert.fail("An exception occured while testing the existence of plugins and repositories.");
}
} }
} }
...@@ -37,17 +37,16 @@ public class GraphLayoutServiceImplTest { ...@@ -37,17 +37,16 @@ public class GraphLayoutServiceImplTest {
} }
/** /**
* A test making sure that a invalid node/edge combination results in an exceptions. * A test making sure that an invalid node/edge combination results in an exceptions.
*/ */
@Test @Test
public void testLayoutFail() { public void testLayoutFail() {
final IGraphLayoutService layouter = new GraphLayoutServiceImpl(); final IGraphLayoutService layouter = new GraphLayoutServiceImpl();
// We assert that something goes wrong here
try { try {
layouter.layoutGraph("", ""); layouter.layoutGraph("", "");
Assert.fail(); Assert.fail("Graph layouting failed");
} catch (final GraphLayoutException ex) { // NOPMD (Empty catch block) } catch (final GraphLayoutException ex) { // NOPMD (JUnit Test)
} }
} }
...@@ -66,7 +65,7 @@ public class GraphLayoutServiceImplTest { ...@@ -66,7 +65,7 @@ public class GraphLayoutServiceImplTest {
// We assert that the layout method succeeds // We assert that the layout method succeeds
final String layoutString = layouter.layoutGraph(inputNodes, inputEdges); final String layoutString = layouter.layoutGraph(inputNodes, inputEdges);
Assert.assertTrue(layoutString.startsWith("autoLayout#")); Assert.assertTrue("Graph layouting failed", layoutString.startsWith("autoLayout#"));
} }
/** /**
...@@ -84,6 +83,6 @@ public class GraphLayoutServiceImplTest { ...@@ -84,6 +83,6 @@ public class GraphLayoutServiceImplTest {
// We assert that the layout method succeeds // We assert that the layout method succeeds
final String layoutString = layouter.layoutGraph(inputNodes, inputEdges); final String layoutString = layouter.layoutGraph(inputNodes, inputEdges);
Assert.assertTrue(layoutString.startsWith("autoLayout#")); Assert.assertTrue("Graph layouting failed", layoutString.startsWith("autoLayout#"));
} }
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package kieker.webgui.web.converter; package kieker.webgui.web.converter;
import javax.faces.convert.ConverterException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -36,7 +38,7 @@ public class RoleStringConverterTest { ...@@ -36,7 +38,7 @@ public class RoleStringConverterTest {
} }
/** /**
* A test of this test class. * A test making sure that the {@code getAsString} method works correctly.
*/ */
@Test @Test
public void testEqualAsString() { public void testEqualAsString() {
...@@ -48,48 +50,54 @@ public class RoleStringConverterTest { ...@@ -48,48 +50,54 @@ public class RoleStringConverterTest {
} }
/** /**
* A test of this test class. * A test making sure that the {@code getAsObject} method works correctly.
*/ */
@Test @Test
public void testNotEqualAsString() { public void testEqualFromString() {
final RoleStringConverter converter = new RoleStringConverter(); final RoleStringConverter converter = new RoleStringConverter();
Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsString(null, null, Role.ROLE_USER)); Assert.assertEquals("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString()));
Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsString(null, null, Role.ROLE_GUEST)); Assert.assertEquals("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_GUEST.toString()));
Assert.assertEquals("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_USER.toString()));
}
Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsString(null, null, Role.ROLE_ADMIN)); /**
Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsString(null, null, Role.ROLE_USER)); * A test making sure that the methods of the converter handle null values correctly. This is specified by the API of the converter interface.
*/
@Test
public void testNullHandling() {
final RoleStringConverter converter = new RoleStringConverter();
Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsString(null, null, Role.ROLE_GUEST)); Assert.assertNull("Conversion failed.", converter.getAsObject(null, null, null));
Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsString(null, null, Role.ROLE_ADMIN)); Assert.assertTrue("Conversion failed.", converter.getAsString(null, null, null).isEmpty());
} }
/** /**
* A test of this test class. * A test making sure that the {@code getAsObject} method handles invalid values correctly. This is specified by the API of the converter interface.
*/ */
@Test @Test
public void testEqualFromString() { public void testInvalidString() {
final RoleStringConverter converter = new RoleStringConverter(); final RoleStringConverter converter = new RoleStringConverter();
Assert.assertEquals("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString())); try {
Assert.assertEquals("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_GUEST.toString())); converter.getAsObject(null, null, "");
Assert.assertEquals("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_USER.toString())); Assert.fail("Conversion failed.");
} catch (final ConverterException ex) { // NOPMD (JUnit Test)
}
} }
/** /**
* A test of this test class. * A test making sure that the {@code getAsString} method handles invalid values correctly. This is specified by the API of the converter interface.
*/ */
@Test @Test
public void testNotEqualFromString() { public void testInvalidObject() {
final RoleStringConverter converter = new RoleStringConverter(); final RoleStringConverter converter = new RoleStringConverter();
Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_USER.toString())); try {
Assert.assertNotSame("Conversion failed.", Role.ROLE_ADMIN, converter.getAsObject(null, null, Role.ROLE_GUEST.toString())); converter.getAsString(null, null, new Object());
Assert.fail("Conversion failed.");
Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString())); } catch (final ConverterException ex) { // NOPMD (JUnit Test)
Assert.assertNotSame("Conversion failed.", Role.ROLE_GUEST, converter.getAsObject(null, null, Role.ROLE_USER.toString())); }
Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_GUEST.toString()));
Assert.assertNotSame("Conversion failed.", Role.ROLE_USER, converter.getAsObject(null, null, Role.ROLE_ADMIN.toString()));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment