package org.hybridlabs.source.formatter;
/**
* Copyright 2008 hybrid labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.hybridlabs.file.FileHelper;
import org.hybridlabs.source.beautifier.CharacterSequence;
import org.hybridlabs.source.beautifier.JavaImportBeautifierImpl;
public class DocumentationTest extends TestCase {
public void testSampleEntityBean() throws Exception {
JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
beautifier.setFormat(true);
beautifier.setOrganizeImports(true);
CharacterSequence sequence = new CharacterSequence(loadTestFile("Documentation_Sample1.java_input"));
beautifier.beautify(sequence);
CharacterSequence expectedOutput = new CharacterSequence(loadTestFile("Documentation_Sample1.java_output"));
compare(expectedOutput, sequence);
}
private StringBuffer loadTestFile(String name) throws Exception {
InputStream is = ClassLoader.getSystemResourceAsStream(name);
if (is == null) {
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
}
Assert.assertNotNull("Could not open test file "+name, is);
return FileHelper.loadStringBuffer(new InputStreamReader(is));
}
private void compare(CharacterSequence expected, CharacterSequence actual) {
assertEquals(normalized(expected), normalized(actual));
}
private String normalized (CharSequence seq) {
return seq.toString().trim().replaceAll("\r\n", System.getProperty("line.separator"));
}
}