Skip to content

Instantly share code, notes, and snippets.

View alebaffa's full-sized avatar
🗼
Focusing

Alessandro alebaffa

🗼
Focusing
View GitHub Profile
@Test
public void should_convert_to_html() throws IOException {
HtmlTextConverter converter = new FakeHtmlTextConverter("ciao");
assertThat(converter.convertToHtml(), is("ciao<br />"));
}
public class FakeHtmlTextConverter extends HtmlTextConverter {
private String fullFilenameWithPath;
public FakeHtmlTextConverter(String fullFilenameWithPath) {
super(fullFilenameWithPath);
this.fullFilenameWithPath = fullFilenameWithPath;
}
@Override
protected Reader getReader() throws FileNotFoundException {
public class HtmlTextConverter {
private String fullFilenameWithPath;
public HtmlTextConverter(String fullFilenameWithPath) {
this.fullFilenameWithPath = fullFilenameWithPath;
}
public String convertToHtml() throws IOException {
HtmlFormatter formatter = getHtmlFormatter(getReader());
formatter.convertToHtml();
String text = "Hello";
ReaderFactory readerFactory = new StringReaderFactory(text);
HtmlTextConverter converter = new HtmlTextConverter(readerFactory);
assertThat(converter.convertToHtml(), is("Hello<br />"));
public class HtmlTextConverter {
private ReaderFactory readerFactory;
public HtmlTextConverter(String fullFilenameWithPath) {
this(new FileReaderFactory(fullFilenameWithPath));
}
public HtmlTextConverter(ReaderFactory readerFactory) {
this.readerFactory = readerFactory;
}
public class HtmlTextConverter
{
private String fullFilenameWithPath;
public HtmlTextConverter(String fullFilenameWithPath) { this.fullFilenameWithPath = fullFilenameWithPath; }
public String convertToHtml() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(fullFilenameWithPath));
String line = reader.readLine();
@alebaffa
alebaffa / Number.java
Created July 7, 2016 20:54
Roman Numeral Kata in Java
public class Number implements Comparable<Number> {
private int arabic;
private String roman;
public Number(int arabicIn, String romanIn) {
arabic = arabicIn;
roman = romanIn;
}
public class RomanNumbers {
// LinkedHashMap allows the fetch of the items in the same order of the insert
private static Map<Integer, String> dictionary = new LinkedHashMap<>();
static {
dictionary.put(50, "L");
dictionary.put(40, "XL");
dictionary.put(10, "X");
dictionary.put(9, "IX");
public String convertToRoman(int number) {
if(dictionary.containsKey(number))
return dictionary.get(number);
String result = "";
while(number >= 50){
result += "L";
number -= 50;
public String convertToRoman(int number) {
if(dictionary.containsKey(number))
return dictionary.get(number);
String result = "";
if(number > 50){
result += "L";
return result + convertToRoman(number - 50);