Skip to content

Commit

Permalink
[LOGTOOL-125] Move from testng to junit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamezp committed Jul 17, 2017
1 parent f1d9159 commit 2d0c504
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 263 deletions.
9 changes: 5 additions & 4 deletions pom.xml
Expand Up @@ -61,7 +61,7 @@
<version.org.jboss.logging>3.1.2.GA</version.org.jboss.logging>
<version.org.jboss.logmanager>2.0.3.Final</version.org.jboss.logmanager>
<verion.org.jboss.forge.roaster>2.19.2.Final</verion.org.jboss.forge.roaster>
<version.org.testng>6.3.1</version.org.testng>
<version.junit>4.12</version.junit>
</properties>

<licenses>
Expand Down Expand Up @@ -110,9 +110,10 @@
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${version.org.testng}</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
4 changes: 2 additions & 2 deletions processor-tests/pom.xml
Expand Up @@ -64,8 +64,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions processor/pom.xml
Expand Up @@ -78,8 +78,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -25,8 +25,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.junit.AfterClass;
import org.junit.BeforeClass;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down
Expand Up @@ -22,29 +22,29 @@

package org.jboss.logging.processor.generated;

import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class ExpressionMessagesTest extends AbstractLoggerTest {

@AfterMethod
@After
public void clearHandler() {
HANDLER.close();
}

@Test
public void testExpressions() throws Exception {
ExpressionLogger.LOGGER.logProperty();
Assert.assertEquals(HANDLER.getMessage(), "test property value");
Assert.assertEquals("test property value", HANDLER.getMessage());

ExpressionLogger.LOGGER.logPropertyDefault();
Assert.assertEquals(HANDLER.getMessage(), "default value");
Assert.assertEquals("default value", HANDLER.getMessage());

Assert.assertEquals(ExpressionLogger.LOGGER.property(), "test property value");
Assert.assertEquals(ExpressionLogger.LOGGER.propertyDefault(), "default value");
Assert.assertEquals("test property value", ExpressionLogger.LOGGER.property());
Assert.assertEquals("default value", ExpressionLogger.LOGGER.propertyDefault());
}
}
Expand Up @@ -47,9 +47,9 @@
import org.jboss.forge.roaster.model.source.ParameterSource;
import org.jboss.logging.DelegatingBasicLogger;
import org.jboss.logging.Logger;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
Expand Down Expand Up @@ -113,13 +113,13 @@ public void testGeneratedTranslations() throws Exception {
public void testRootLocale() throws Exception {
JavaClassSource implementationSource = parseGenerated(RootLocaleLogger.class);
FieldSource<JavaClassSource> locale = implementationSource.getField("LOCALE");
Assert.assertNotNull(locale, "Expected a LOCALE field for " + implementationSource.getName());
Assert.assertEquals(locale.getLiteralInitializer(), "Locale.forLanguageTag(\"en-UK\")");
Assert.assertNotNull("Expected a LOCALE field for " + implementationSource.getName(), locale);
Assert.assertEquals("Locale.forLanguageTag(\"en-UK\")", locale.getLiteralInitializer());

implementationSource = parseGenerated(DefaultLogger.class);
locale = implementationSource.getField("LOCALE");
Assert.assertNotNull(locale, "Expected a LOCALE field for " + implementationSource.getName());
Assert.assertEquals(locale.getLiteralInitializer(), "Locale.ROOT");
Assert.assertNotNull("Expected a LOCALE field for " + implementationSource.getName(), locale);
Assert.assertEquals("Locale.ROOT", locale.getLiteralInitializer());
}

private void compareLogger(final Class<?> intf) throws IOException {
Expand All @@ -130,19 +130,20 @@ private void compareLogger(final Class<?> intf) throws IOException {
// Logger implementations should have a single constructor which accepts a org.jboss.logging.Logger
final List<MethodSource<JavaClassSource>> implementationMethods = implementationSource.getMethods();
final Optional<MethodSource<JavaClassSource>> constructor = findConstructor(implementationMethods);
Assert.assertTrue(constructor.isPresent(), "No constructor found for " + implementationSource.getName());
Assert.assertTrue("No constructor found for " + implementationSource.getName(), constructor.isPresent());
final List<ParameterSource<JavaClassSource>> parameters = constructor.get().getParameters();
Assert.assertEquals(parameters.size(), 1, "Found more than one parameter for " + implementationSource.getName() + ": " + parameters);
Assert.assertEquals("Found more than one parameter for " + implementationSource.getName() + ": " + parameters,
1, parameters.size());
final ParameterSource<JavaClassSource> parameter = parameters.get(0);
final Type<JavaClassSource> type = parameter.getType();
Assert.assertEquals(type.getQualifiedName(), Logger.class.getName());
Assert.assertEquals(Logger.class.getName(), type.getQualifiedName());

// If the logger is not extending the DelegatingBasicLogger there should be a protected final org.jboss.logging.Logger field
if (!DelegatingBasicLogger.class.getName().equals(implementationSource.getSuperType())) {
final FieldSource<JavaClassSource> log = implementationSource.getField("log");
Assert.assertNotNull(log, "Expected a log field in " + implementationSource.getName());
Assert.assertTrue(log.isProtected() && log.isFinal(),
"Expected the log field to be protected and final in " + implementationSource.getName());
Assert.assertNotNull("Expected a log field in " + implementationSource.getName(), log);
Assert.assertTrue("Expected the log field to be protected and final in " + implementationSource.getName(),
log.isProtected() && log.isFinal());
}
}

Expand All @@ -153,16 +154,16 @@ private void compareBundle(final Class<?> intf) throws IOException {

// Message bundles should have an INSTANCE field
final FieldSource<JavaClassSource> instance = implementationSource.getField("INSTANCE");
Assert.assertNotNull(instance, "Expected an INSTANCE field in " + implementationSource.getName());
Assert.assertTrue(instance.isStatic() && instance.isFinal() && instance.isPublic(),
"Expected the instance field to be public, static and final in " + implementationSource.getName());
Assert.assertNotNull("Expected an INSTANCE field in " + implementationSource.getName(), instance);
Assert.assertTrue("Expected the instance field to be public, static and final in " + implementationSource.getName(),
instance.isStatic() && instance.isFinal() && instance.isPublic());

// Expect a protected constructor with no parameters
final Optional<MethodSource<JavaClassSource>> constructor = findConstructor(implementationSource.getMethods());
Assert.assertTrue(constructor.isPresent(), "No constructor found for " + implementationSource.getName());
Assert.assertTrue("No constructor found for " + implementationSource.getName(), constructor.isPresent());
final MethodSource<JavaClassSource> c = constructor.get();
Assert.assertTrue(c.getParameters().isEmpty(), "Expected the constructor parameters to be empty for " + implementationSource.getName());
Assert.assertTrue(c.isProtected(), "Expected the constructor to be protected for " + implementationSource.getName());
Assert.assertTrue("Expected the constructor parameters to be empty for " + implementationSource.getName(), c.getParameters().isEmpty());
Assert.assertTrue("Expected the constructor to be protected for " + implementationSource.getName(), c.isProtected());
}

private void compareCommon(final JavaInterfaceSource interfaceSource, final JavaClassSource implementationSource) {
Expand All @@ -172,18 +173,18 @@ private void compareCommon(final JavaInterfaceSource interfaceSource, final Java
// Validate the implementation has all the interface methods, note this should be the cause
final Collection<String> interfaceMethodNames = toNames(interfaceMethods);
final Collection<String> implementationMethodNames = toNames(implementationMethods);
Assert.assertTrue(implementationMethodNames.containsAll(interfaceMethodNames),
String.format("Implementation is missing methods from the interface:%n\timplementation: %s%n\tinterface:%s", implementationMethodNames, interfaceMethodNames));
Assert.assertTrue(String.format("Implementation is missing methods from the interface:%n\timplementation: %s%n\tinterface:%s", implementationMethodNames, interfaceMethodNames),
implementationMethodNames.containsAll(interfaceMethodNames));

// The generates source files should have a serialVersionUID with a value of one
Assert.assertTrue(implementationSource.hasField("serialVersionUID"), "Expected a serialVersionUID field in " + implementationSource.getName());
Assert.assertTrue("Expected a serialVersionUID field in " + implementationSource.getName(), implementationSource.hasField("serialVersionUID"));
final FieldSource<JavaClassSource> serialVersionUID = implementationSource.getField("serialVersionUID");
Assert.assertEquals(serialVersionUID.getLiteralInitializer(), "1L", "Expected serialVersionUID to be set to 1L in " + implementationSource.getName());
Assert.assertEquals("Expected serialVersionUID to be set to 1L in " + implementationSource.getName(), "1L", serialVersionUID.getLiteralInitializer());

// All bundles should have a getLoggingLocale()
final MethodSource<JavaClassSource> getLoggingLocale = implementationSource.getMethod("getLoggingLocale");
Assert.assertNotNull(getLoggingLocale, "Expected a getLoggingLocale() method in " + implementationSource.getName());
Assert.assertTrue(getLoggingLocale.isProtected(), "Expected the getLoggingLocale() to be protected in " + implementationSource.getName());
Assert.assertNotNull("Expected a getLoggingLocale() method in " + implementationSource.getName(), getLoggingLocale);
Assert.assertTrue("Expected the getLoggingLocale() to be protected in " + implementationSource.getName(), getLoggingLocale.isProtected());
}

private void compareTranslations(final Class<?> intf) throws IOException {
Expand All @@ -209,20 +210,20 @@ private void compareTranslations(final JavaInterfaceSource interfaceSource, fina
found.add(method.getName());
}
}
Assert.assertTrue(found.isEmpty(), "Found methods in implementation that were in the interface " + implementationSource.getName() + " : " + found);
Assert.assertTrue("Found methods in implementation that were in the interface " + implementationSource.getName() + " : " + found, found.isEmpty());

// The getLoggerLocale() should be overridden
final MethodSource<JavaClassSource> getLoggerLocale = implementationSource.getMethod("getLoggingLocale");
Assert.assertNotNull(getLoggerLocale, "Missing overridden getLoggingLocale() method " + implementationSource.getName());
Assert.assertNotNull("Missing overridden getLoggingLocale() method " + implementationSource.getName(), getLoggerLocale);

// If the file should have a locale constant, validate the constant is one of the Locale constants
LOCALE_CONSTANTS.forEach((locale, constant) -> {
if (implementationSource.getName().endsWith(locale.toString())) {
// Get the LOCALE field
final FieldSource<JavaClassSource> localeField = implementationSource.getField("LOCALE");
Assert.assertNotNull(localeField, "Expected a LOCALE field " + implementationSource.getName());
Assert.assertEquals(localeField.getLiteralInitializer(), constant,
"Expected the LOCALE to be set to " + constant + " in " + implementationSource.getName());
Assert.assertNotNull("Expected a LOCALE field " + implementationSource.getName(), localeField);
Assert.assertEquals("Expected the LOCALE to be set to " + constant + " in " + implementationSource.getName(), constant,
localeField.getLiteralInitializer());
}
});

Expand All @@ -236,18 +237,14 @@ private void compareTranslations(final JavaInterfaceSource interfaceSource, fina
// All methods in the translation implementation should be overrides of methods in the super class
implementationSource.getMethods().forEach(method -> {
if (!method.isConstructor()) {
Assert.assertTrue(method.hasAnnotation(Override.class), String.format("Expected method %s to be overridden in %s.",
method.getName(), implementationSource.getName()));
Assert.assertTrue(superMethods.contains(method.getName()), String.format("Expected method %s to override the super (%s) method in %s.",
method.getName(), superImplementationSource.getName(), implementationSource.getName()));
Assert.assertTrue(String.format("Expected method %s to be overridden in %s.",
method.getName(), implementationSource.getName()), method.hasAnnotation(Override.class));
Assert.assertTrue(String.format("Expected method %s to override the super (%s) method in %s.",
method.getName(), superImplementationSource.getName(), implementationSource.getName()), superMethods.contains(method.getName()));
}
});
}

private void compareRootLocale(final Class<?> intf, final String expectedLocaleString) throws IOException {
final JavaClassSource implementationSource = parseGenerated(intf);
}

private Optional<MethodSource<JavaClassSource>> findConstructor(final List<MethodSource<JavaClassSource>> implementationMethods) {
return implementationMethods.stream()
.filter(Method::isConstructor)
Expand Down Expand Up @@ -275,8 +272,8 @@ private JavaClassSource parseGenerated(final Class<?> intf) throws IOException {
final File dir = new File(TEST_GENERATED_SRC_PATH, packageToPath(intf.getPackage()));
final File[] files = dir.listFiles(filter);
// There should only be one file
Assert.assertNotNull(files, "Did not find any implementation files for interface " + intf.getName());
Assert.assertEquals(1, files.length, "Found more than one implementation for interface " + intf.getName() + " " + Arrays.asList(files));
Assert.assertNotNull("Did not find any implementation files for interface " + intf.getName(), files);
Assert.assertEquals("Found more than one implementation for interface " + intf.getName() + " " + Arrays.asList(files), 1, files.length);

return Roaster.parse(JavaClassSource.class, files[0]);
}
Expand All @@ -288,8 +285,8 @@ private Collection<JavaClassSource> parseGeneratedTranslations(final Class<?> in
final File dir = new File(TEST_GENERATED_SRC_PATH, packageToPath(intf.getPackage()));
final File[] files = dir.listFiles(filter);
// There should only be one file
Assert.assertNotNull(files, "Did not find any implementation files for interface " + intf.getName());
Assert.assertTrue(files.length > 0, "Did not find any translation implementations for interface " + intf.getName());
Assert.assertNotNull("Did not find any implementation files for interface " + intf.getName(), files);
Assert.assertTrue("Did not find any translation implementations for interface " + intf.getName(), files.length > 0);
final Collection<JavaClassSource> result = new ArrayList<>();
for (final File file : files) {
result.add(Roaster.parse(JavaClassSource.class, file));
Expand Down
Expand Up @@ -22,16 +22,16 @@

package org.jboss.logging.processor.generated;

import org.testng.annotations.AfterMethod;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class LevelIdCheckTest extends AbstractLoggerTest {

@AfterMethod
@After
public void clearHandler() {
HANDLER.close();
}
Expand All @@ -42,10 +42,10 @@ public void inheritedId() throws Exception {
ValidLogger.LOGGER.processingError(new IllegalArgumentException());
ValidLogger.LOGGER.processingError(new IllegalArgumentException(), "generated");
ValidLogger.LOGGER.processingError(this, "invalid reference");
Assert.assertEquals(parseLoggerId(HANDLER.getMessage()), 203);
Assert.assertEquals(parseLoggerId(HANDLER.getMessage()), 203);
Assert.assertEquals(parseLoggerId(HANDLER.getMessage()), 203);
Assert.assertEquals(parseLoggerId(HANDLER.getMessage()), 203);
Assert.assertEquals(203, parseLoggerId(HANDLER.getMessage()));
Assert.assertEquals(203, parseLoggerId(HANDLER.getMessage()));
Assert.assertEquals(203, parseLoggerId(HANDLER.getMessage()));
Assert.assertEquals(203, parseLoggerId(HANDLER.getMessage()));
}


Expand Down

0 comments on commit 2d0c504

Please sign in to comment.