SourceCodeAppender { void appendExtensionPostAssignSourceCode(StringBuilder buf, String code, String[] fromList, String to) { Assertion.on("code").mustNotBeNull(code); Assertion.on("fromList").mustNotBeNull(fromList); Assertion.on("to").mustNotBeNull(to); String[] separatedListBySemicolon = code.split(StringValue.Semicolon); for (String separatedBySemicolon : separatedListBySemicolon) { if (separatedBySemicolon != null && separatedBySemicolon.trim().length() > 0) { separatedBySemicolon = separatedBySemicolon.trim().replaceAll(StringValue.CarriageReturn, ""); String[] lines = separatedBySemicolon.split(StringValue.LineFeed); for (int i = 0; i < (lines.length - 1); i++) { String line = lines[i]; if (line != null && line.trim().length() > 0) { appendTabs(buf, 2); buf.append(line.trim()); appendLineBreak(buf); } } String lastLine = lines[lines.length - 1]; if (lastLine != null && lastLine.trim().length() > 0) { appendTabs(buf, 2); buf.append(lastLine.trim()); if (!lastLine.endsWith("}") && !lastLine.endsWith("/")) { buf.append(StringValue.Semicolon); } appendLineBreak(buf); } } } } SourceCodeAppender(LineBreakProvider lineBreakProvider, IndentationProvider indentationProvider);   }
@Test public void appendExtensionPostAssignSourceCode_A$StringBuilder$String$StringArray$String() throws Exception { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, currentLineBreak); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = "foo"; String[] fromList = new String[] {}; String to = "bar"; target.appendExtensionPostAssignSourceCode(buf, code, fromList, to); assertThat(buf.toString(), is(equalTo("\t\tfoo;\r\n"))); }
@Test public void appendExtensionPostAssignSourceCode_A$StringBuilder$String$StringArray$String_StringIsNull() throws Exception { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, currentLineBreak); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = "foo"; String[] fromList = new String[] {}; String to = "bar"; target.appendExtensionPostAssignSourceCode(buf, code, fromList, to); assertThat(buf.toString(), is(equalTo("\t\tfoo;\r\n"))); }
@Test public void appendExtensionPostAssignSourceCode_A$StringBuilder$String$StringArray$String_StringIsEmpty() throws Exception { LineBreakProvider lineBreakProvider = new LineBreakProvider(config, currentLineBreak); SourceCodeAppender target = new SourceCodeAppender(lineBreakProvider, indentationProvider); StringBuilder buf = new StringBuilder(); String code = ""; String[] fromList = new String[] {}; String to = ""; target.appendExtensionPostAssignSourceCode(buf, code, fromList, to); assertThat(buf.toString(), is(equalTo(""))); }