Skip to content

Commit

Permalink
refactor ListenerTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyccs committed Oct 11, 2015
1 parent f496611 commit 98f0ac2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.sqatntu.stylechecker;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestName;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
* Created by andyccs on 11/10/15.
*/
public class ListenerTest {

@Rule
public TestName name = new TestName();

protected String testCode;
protected String testConfig;

@Before
public void before() throws NoSuchMethodException, IOException {
Method method = this.getClass().getMethod(name.getMethodName());
Annotation[] annotations = method.getDeclaredAnnotations();

for(Annotation annotation : annotations) {
if(annotation instanceof TestCode){
TestCode testCodeAnnotation = (TestCode) annotation;
testCode = TestUtil.loadFile(testCodeAnnotation.fileName());
}
else if(annotation instanceof TestConfig) {
TestConfig testConfigAnnotation = (TestConfig) annotation;
testConfig = TestUtil.loadFile(testConfigAnnotation.fileName());
}
}
}

@After
public void after() {
testCode = null;
testConfig = null;
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
package com.sqatntu.stylechecker.listener;

import static org.junit.Assert.assertEquals;

import com.sqatntu.stylechecker.ListenerTest;
import com.sqatntu.stylechecker.StyleChecker;
import com.sqatntu.stylechecker.StyleCheckerException;
import com.sqatntu.stylechecker.TestCode;
import com.sqatntu.stylechecker.TestConfig;
import com.sqatntu.stylechecker.TestUtil;
import com.sqatntu.stylechecker.report.StyleReport;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import static org.junit.Assert.assertEquals;

/**
* Created by andyccs on 11/10/15.
*/
public class BraceStyleListenerTest {

@Rule
public TestName name = new TestName();

private String testCode;
private String testConfig;

@Before
public void before() throws NoSuchMethodException, IOException {
Method method = this.getClass().getMethod(name.getMethodName());
Annotation[] annotations = method.getDeclaredAnnotations();

for(Annotation annotation : annotations) {
if(annotation instanceof TestCode){
TestCode testCodeAnnotation = (TestCode) annotation;
testCode = TestUtil.loadFile(testCodeAnnotation.fileName());
}
else if(annotation instanceof TestConfig) {
TestConfig testConfigAnnotation = (TestConfig) annotation;
testConfig = TestUtil.loadFile(testConfigAnnotation.fileName());
}
}
}

@After
public void after() {
testCode = null;
testConfig = null;
}
public class BraceStyleListenerTest extends ListenerTest {

@Test
@TestCode(detail = "krStyleCode", fileName = "src/test/resources/BraceKRStyle.java")
Expand Down

0 comments on commit 98f0ac2

Please sign in to comment.