Skip to content

Commit

Permalink
JBEHAVE-1600 Switch to use non-deprecated 3-rd party APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Dec 29, 2023
1 parent 6b09056 commit a3397a8
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jbehave.core.context;

import static java.text.MessageFormat.format;
import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4;
import static org.apache.commons.text.StringEscapeUtils.escapeHtml4;

import java.awt.BorderLayout;
import java.awt.Point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.apache.commons.lang3.StringUtils.contains;
import static org.apache.commons.lang3.StringUtils.substringAfterLast;
import static org.apache.commons.lang3.StringUtils.substringBeforeLast;
import static org.apache.commons.lang3.text.WordUtils.capitalize;
import static org.apache.commons.text.WordUtils.capitalize;

public class UnderscoredToCapitalized implements StoryNameResolver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import java.io.Writer;
import java.util.Map;

import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
import freemarker.template.Version;

public class FreemarkerProcessor implements TemplateProcessor {
private ClassLoader templateLoadingFrom;
Expand Down Expand Up @@ -32,9 +33,10 @@ public void process(String resource, Map<String, Object> dataModel, Writer write
}

public Configuration configuration() {
Configuration configuration = new Configuration();
Version incompatibleImprovementsVersion = Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
Configuration configuration = new Configuration(incompatibleImprovementsVersion);
configuration.setClassLoaderForTemplateLoading(templateLoadingFrom, "/");
configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
configuration.setObjectWrapper(new BeansWrapperBuilder(incompatibleImprovementsVersion).build());
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class SurefireReporter {
private static final String XML = ".xml";
private static final String DOT = ".";
private static final String HYPHEN = "-";
private static final String SLASH = "/";

private final Class<?> embeddableClass;
private final TestCaseNamingStrategy namingStrategy;
Expand Down Expand Up @@ -118,7 +117,7 @@ public synchronized void generate(PerformableRoot root,
}

private String reportName(String path) {
return reportName + HYPHEN + StringUtils.replaceAll(StringUtils.substringBefore(path, DOT), SLASH, DOT);
return reportName + HYPHEN + StringUtils.substringBefore(path, DOT).replace('/', '.');
}

private void generateReport(List<PerformableStory> stories, File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
import org.jbehave.core.steps.StepCreator.PendingStep;
import org.jbehave.core.steps.Timing;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.Configuration;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModelException;

Expand Down Expand Up @@ -237,7 +238,8 @@ public void afterStory(boolean givenStory) {
model.put("story", outputStory);
model.put("keywords", new OutputKeywords(keywords));

TemplateHashModel enumModels = BeansWrapper.getDefaultInstance().getEnumModels();
TemplateHashModel enumModels =
new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build().getEnumModels();
TemplateHashModel escapeEnums;
try {
String escapeModeEnum = EscapeMode.class.getCanonicalName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.Before;
import org.reflections.Reflections;
import org.reflections.ReflectionsException;
import org.reflections.scanners.MethodAnnotationsScanner;
import org.reflections.scanners.Scanners;

/**
* An {@link InjectableStepsFactory} that scans for classes in the classpath.
Expand Down Expand Up @@ -62,8 +62,7 @@ public ScanningStepsFactory notMatchingNames(String notMatchingRegex) {
}

private Set<Class<?>> scanTypes(String packageName) {
Reflections reflections = new Reflections(packageName,
new MethodAnnotationsScanner());
Reflections reflections = new Reflections(packageName, Scanners.MethodsAnnotated);
Set<Class<?>> types = new HashSet<>();
types.addAll(typesAnnotatedWith(reflections, Given.class));
types.addAll(typesAnnotatedWith(reflections, When.class));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jbehave.core.steps;

import static org.apache.commons.lang3.StringEscapeUtils.escapeJava;
import static org.apache.commons.text.StringEscapeUtils.escapeJava;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -92,7 +93,7 @@ private String contentOf(File file) {
return EMPTY;
}
try {
return FileUtils.readFileToString(file);
return FileUtils.readFileToString(file, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(
"Failed to read content of file " + file, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Collection<Page> parse(String entity) {
}

private String jsonMember(String entity, String memberName) {
return new JsonParser().parse(entity).getAsJsonObject().get(memberName).toString();
return JsonParser.parseString(entity).getAsJsonObject().get(memberName).toString();
}

private static class Page {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected String text(String entity, Type type) {
}

private String jsonMember(String entity, String memberName) {
return new JsonParser().parse(entity).getAsJsonObject().get(memberName).toString();
return JsonParser.parseString(entity).getAsJsonObject().get(memberName).toString();
}

private static class WikiPage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ private Collection<Page> parse(String entity) {
}

private String jsonMember(String entity, String memberName) {
return new JsonParser().parse(entity).getAsJsonObject().get(memberName)
.toString();
return JsonParser.parseString(entity).getAsJsonObject().get(memberName).toString();
}

private static class Page {
Expand Down

0 comments on commit a3397a8

Please sign in to comment.