1
2
3
4 package net.sourceforge.pmd.cpd;
5
6 import java.io.File;
7 import java.io.IOException;
8
9 import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
10
11 import org.apache.commons.io.FileUtils;
12 import org.apache.commons.io.IOUtils;
13 import org.junit.After;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.sonar.plugins.scala.cpd.ScalaTokenizer;
17
18
19 public class ScalaTokenizerTest extends AbstractTokenizerTest {
20
21 private static final String ENCODING = "UTF-8";
22
23 private static final String FILENAME = "sample-LiftActor.scala";
24
25 private File tempFile;
26
27 @Before
28 @Override
29 public void buildTokenizer() throws IOException {
30 createTempFileOnDisk();
31
32 this.tokenizer = new ScalaTokenizer();
33 this.sourceCode = new SourceCode(new SourceCode.FileCodeLoader(tempFile, "UTF-8"));
34 }
35
36 private void createTempFileOnDisk() throws IOException {
37 this.tempFile = File.createTempFile("scala-tokenizer-test-", ".scala");
38 FileUtils.writeStringToFile(tempFile, getSampleCode(), ENCODING);
39 }
40
41 @Override
42 public String getSampleCode() throws IOException {
43 return IOUtils.toString(ScalaTokenizer.class.getResourceAsStream(FILENAME), ENCODING);
44 }
45
46 @Test
47 public void tokenizeTest() throws IOException {
48 this.expectedTokenCount = 2591;
49 super.tokenizeTest();
50 }
51
52 @After
53 public void cleanUp() {
54 FileUtils.deleteQuietly(this.tempFile);
55 this.tempFile = null;
56 }
57 }