.encoding(Charset.forName(encoding)) .rootDir(getProject().getRootDir().toPath()) .steps(steps)
try (Formatter paddedFormatter = Formatter.builder() .lineEndingsPolicy(formatter.getLineEndingsPolicy()) .encoding(formatter.getEncoding()) .rootDir(formatter.getRootDir()) .steps(Collections.singletonList(paddedCellStep))
public final Formatter newFormatter(List<File> filesToFormat, FormatterConfig config) { Charset formatterEncoding = encoding(config); LineEnding formatterLineEndings = lineEndings(config); LineEnding.Policy formatterLineEndingPolicy = formatterLineEndings.createPolicy(config.getBaseDir(), () -> filesToFormat); FormatterStepConfig stepConfig = stepConfig(formatterEncoding, config); List<FormatterStepFactory> factories = gatherStepFactories(config.getGlobalStepFactories(), stepFactories); List<FormatterStep> formatterSteps = factories.stream() .filter(Objects::nonNull) // all unrecognized steps from XML config appear as nulls in the list .map(factory -> factory.newFormatterStep(stepConfig)) .collect(toList()); return Formatter.builder() .encoding(formatterEncoding) .lineEndingsPolicy(formatterLineEndingPolicy) .exceptionPolicy(new FormatExceptionPolicyStrict()) .steps(formatterSteps) .rootDir(config.getBaseDir().toPath()) .build(); }
private void testCase(FormatterFunc step, String input, PaddedCell.Type expectedOutputType, String expectedSteps, String canonical, boolean misbehaved) throws IOException { List<FormatterStep> formatterSteps = new ArrayList<>(); formatterSteps.add(FormatterStep.createNeverUpToDate("step", step)); try (Formatter formatter = Formatter.builder() .lineEndingsPolicy(LineEnding.UNIX.createPolicy()) .encoding(StandardCharsets.UTF_8) .rootDir(folder.getRoot().toPath()) .steps(formatterSteps).build()) { File file = folder.newFile(); Files.write(file.toPath(), input.getBytes(StandardCharsets.UTF_8)); PaddedCell result = PaddedCell.check(formatter, file); Assert.assertEquals(misbehaved, result.misbehaved()); Assert.assertEquals(expectedOutputType, result.type()); String actual = String.join(",", result.steps()); Assert.assertEquals(expectedSteps, actual); if (canonical == null) { try { result.canonical(); Assert.fail("Expected exception"); } catch (IllegalArgumentException expected) {} } else { Assert.assertEquals(canonical, result.canonical()); } } }
@Override protected Formatter create() { return Formatter.builder() .lineEndingsPolicy(lineEndingsPolicy) .encoding(encoding) .rootDir(rootDir) .steps(steps) .exceptionPolicy(exceptionPolicy) .build(); } }.testEquals();