Skip to content

Commit

Permalink
Replace tab characters with space characters
Browse files Browse the repository at this point in the history
  • Loading branch information
NozomiIto committed Jan 6, 2015
1 parent dd91b30 commit 6d13f2f
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/main/resources/js/share"]
path = src/main/resources/js/share
url = https://github.com/SahaginOrg/sahagin-js-share.git
path = src/main/resources/js/share
url = https://github.com/SahaginOrg/sahagin-js-share.git
8 changes: 4 additions & 4 deletions src/main/java/org/sahagin/main/SahaginPreMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static void premain(String agentArgs, Instrumentation inst)
configFilePath = agentArgs;
}
Config config = Config.generateFromYamlConfig(new File(configFilePath));
AcceptableLocales locales = AcceptableLocales.getInstance(config.getUserLocale());
AcceptableLocales locales = AcceptableLocales.getInstance(config.getUserLocale());
// TODO change adapter according to the configuration value
AdapterContainer.globalInitialize(locales);
AdapterContainer.globalInitialize(locales);
new JUnit4Adapter().initialSetAdapter();
new WebDriverAdapter().initialSetAdapter();

Expand All @@ -52,8 +52,8 @@ public static void premain(String agentArgs, Instrumentation inst)
inst.addTransformer(transformer);
}

private static SrcTree generateAndDumpSrcTree(Config config, AcceptableLocales locales)
throws IllegalTestScriptException {
private static SrcTree generateAndDumpSrcTree(Config config, AcceptableLocales locales)
throws IllegalTestScriptException {
// generate and dump srcTree
SrcTreeGenerator generator = new SrcTreeGenerator(
AdapterContainer.globalInstance().getAdditionalTestDocs(), locales);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sahagin/runlib/external/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Locale getLocale(java.util.Locale locale) {

// returns null if not Locale found
public static Locale getSystemLocale() {
return getLocale(java.util.Locale.getDefault());
return getLocale(java.util.Locale.getDefault());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ public class AdapterContainer {

// make constructor private
private AdapterContainer() {}

private void initialize(AcceptableLocales locales) {
if (locales == null) {
throw new NullPointerException();
}
this.locales = locales;
initialized = true;
if (locales == null) {
throw new NullPointerException();
}
this.locales = locales;
initialized = true;
}

// some method call of this class requires initialization before calling the method
public static void globalInitialize(AcceptableLocales locales) {
globalInstance.initialize(locales);
globalInstance.initialize(locales);
}

public static AdapterContainer globalInstance() {
if (globalInstance == null) {
throw new IllegalStateException("globalInitialize is not called yet");
}
if (globalInstance == null) {
throw new IllegalStateException("globalInitialize is not called yet");
}
return globalInstance;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public void addAdditionalTestDocsAdapter(
throw new NullPointerException();
}
if (!initialized) {
throw new IllegalStateException("initialize not called");
throw new IllegalStateException("initialize not called");
}
additionalTestDocsAdapter.add(additionalTestDocs, locales);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ private void classAddSub(AdditionalClassTestDoc classTestDocInstance, String qua
classTestDocInstance.setQualifiedName(qualifiedName);
String testDoc = ""; // set empty string if no locale data is found
for (Locale locale : locales.getLocales()) {
Map<String, Object> map = localeClassYamlObjMap.get(locale);
if (map == null) {
continue;
}
Object value = map.get(qualifiedName);
if (value != null) {
testDoc = (String) value;
break;
}
Map<String, Object> map = localeClassYamlObjMap.get(locale);
if (map == null) {
continue;
}
Object value = map.get(qualifiedName);
if (value != null) {
testDoc = (String) value;
break;
}
}
classTestDocInstance.setTestDoc(testDoc);
docs.classAdd(classTestDocInstance);
Expand All @@ -95,23 +95,23 @@ protected final void pageAdd(String qualifiedName) {
public abstract void classAdd();

protected final void methodAdd(String classQualifiedName,
String methodSimpleName, CaptureStyle captureStyle) {
AdditionalMethodTestDoc methodTestDocInstance = new AdditionalMethodTestDoc();
String methodQualifiedName = classQualifiedName + "." + methodSimpleName;
String methodSimpleName, CaptureStyle captureStyle) {
AdditionalMethodTestDoc methodTestDocInstance = new AdditionalMethodTestDoc();
String methodQualifiedName = classQualifiedName + "." + methodSimpleName;
methodTestDocInstance.setClassQualifiedName(classQualifiedName);
methodTestDocInstance.setQualifiedName(methodQualifiedName);
methodTestDocInstance.setCaptureStyle(captureStyle);
String testDoc = ""; // set empty string if no locale data is found
for (Locale locale : locales.getLocales()) {
Map<String, Object> map = localeFuncYamlObjMap.get(locale);
if (map == null) {
continue;
}
Object value = map.get(methodQualifiedName);
if (value != null) {
testDoc = (String) value;
break;
}
Map<String, Object> map = localeFuncYamlObjMap.get(locale);
if (map == null) {
continue;
}
Object value = map.get(methodQualifiedName);
if (value != null) {
testDoc = (String) value;
break;
}
}
methodTestDocInstance.setTestDoc(testDoc);
docs.funcAdd(methodTestDocInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ private static class RootFunctionAdapterImpl implements RootFunctionAdapter {

@Override
public boolean isRootFunction(IMethodBinding methodBinding) {
return ASTUtils.getAnnotationBinding(methodBinding.getAnnotations(), Test.class) != null;
return ASTUtils.getAnnotationBinding(
methodBinding.getAnnotations(), Test.class) != null;
}

@Override
Expand All @@ -40,22 +41,23 @@ public boolean isRootFunction(CtMethod method) {

private static class AdditionalTestDocsAdapterImpl extends ResourceAdditionalTestDocsAdapter {

@Override
public String resourceDirPath() {
return CommonPath.standardAdapdaterLocaleResDirPath() + "/junit4";
}
@Override
public String resourceDirPath() {
return CommonPath.standardAdapdaterLocaleResDirPath() + "/junit4";
}

@Override
public void classAdd() {}
@Override
public void classAdd() {
}

@Override
public void funcAdd() {
// TODO cannot handle methods defined on subclass
// TODO cannot handle methods defined on subclass

// in alphabetical order
methodAdd("org.hamcrest.core.Is", "is");
methodAdd("org.hamcrest.CoreMatchers", "is");
methodAdd("org.junit.Assert", "assertEquals");
// in alphabetical order
methodAdd("org.hamcrest.core.Is", "is");
methodAdd("org.hamcrest.CoreMatchers", "is");
methodAdd("org.junit.Assert", "assertEquals");
methodAdd("org.junit.Assert", "assertThat");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static void setAdapter(final WebDriver driver) {
container.setScreenCaptureAdapter(new ScreenCaptureAdapterImpl(driver));
}

public static class ScreenCaptureAdapterImpl implements ScreenCaptureAdapter {
public static class ScreenCaptureAdapterImpl implements
ScreenCaptureAdapter {
private WebDriver driver;

public ScreenCaptureAdapterImpl(WebDriver driver) {
Expand All @@ -44,7 +45,8 @@ public byte[] captueScreen() {
return null;
}
try {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
} catch (SessionNotFoundException e) {
// just do nothing if WebDriver instance is in invalid state
return null;
Expand All @@ -53,15 +55,18 @@ public byte[] captueScreen() {

}

private static class AdditionalTestDocsAdapterImpl extends ResourceAdditionalTestDocsAdapter {
private static class AdditionalTestDocsAdapterImpl extends
ResourceAdditionalTestDocsAdapter {

@Override
public String resourceDirPath() {
return CommonPath.standardAdapdaterLocaleResDirPath() + "/webdriver";
}
@Override
public String resourceDirPath() {
return CommonPath.standardAdapdaterLocaleResDirPath()
+ "/webdriver";
}

@Override
public void classAdd() {}
public void classAdd() {
}

@Override
public void funcAdd() {
Expand All @@ -85,7 +90,7 @@ public void funcAdd() {
methodAdd("org.openqa.selenium.WebElement", "isSelected");
methodAdd("org.openqa.selenium.WebElement", "sendKeys");
}

}

}
36 changes: 18 additions & 18 deletions src/main/java/org/sahagin/runlib/srctreegen/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,41 +205,41 @@ private static Map<Locale, String> getAllPageTestDocs(
// second... captureStyle value.
// return null pair if no TestDoc is found
private static Pair<String, CaptureStyle> getTestDoc(
IAnnotationBinding[] annotations, AcceptableLocales locales) {
Pair<Map<Locale, String>, CaptureStyle> allTestDocs = getAllTestDocs(annotations);
Map<Locale, String> testDocMap = allTestDocs.getLeft();
IAnnotationBinding[] annotations, AcceptableLocales locales) {
Pair<Map<Locale, String>, CaptureStyle> allTestDocs = getAllTestDocs(annotations);
Map<Locale, String> testDocMap = allTestDocs.getLeft();
if (testDocMap.isEmpty()) {
return Pair.of(null, null);
}

String testDoc = null;
String testDoc = null;
for (Locale locale : locales.getLocales()) {
String value = testDocMap.get(locale);
if (value != null) {
testDoc = value;
break;
}
String value = testDocMap.get(locale);
if (value != null) {
testDoc = value;
break;
}
}
if (testDoc == null) {
return Pair.of(null, null);
return Pair.of(null, null);
} else {
return Pair.of(testDoc, allTestDocs.getRight());
return Pair.of(testDoc, allTestDocs.getRight());
}
}

// return null if no Page found
private static String getPageTestDoc(
IAnnotationBinding[] annotations, AcceptableLocales locales) {
Map<Locale, String> allPages = getAllPageTestDocs(annotations);
IAnnotationBinding[] annotations, AcceptableLocales locales) {
Map<Locale, String> allPages = getAllPageTestDocs(annotations);
if (allPages.isEmpty()) {
return null;
}

for (Locale locale : locales.getLocales()) {
String value = allPages.get(locale);
if (value != null) {
return value;
}
String value = allPages.get(locale);
if (value != null) {
return value;
}
}
return null;
}
Expand All @@ -257,7 +257,7 @@ public static String getTestDoc(ITypeBinding type, AcceptableLocales locales) {

// return null pair if not found
public static Pair<String, CaptureStyle> getTestDoc(
IMethodBinding method, AcceptableLocales locales) {
IMethodBinding method, AcceptableLocales locales) {
return getTestDoc(method.getAnnotations(), locales);
}

Expand Down
30 changes: 15 additions & 15 deletions src/main/java/org/sahagin/share/AcceptableLocales.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
import org.sahagin.runlib.external.Locale;

public class AcceptableLocales {
private List<Locale> locales = new ArrayList<Locale>(4);
// private constructor
private AcceptableLocales() {}
private List<Locale> locales = new ArrayList<Locale>(4);
// private constructor
private AcceptableLocales() {}
public static AcceptableLocales getInstance(Locale userLocale) {
AcceptableLocales result = new AcceptableLocales();
if (userLocale != null) {
result.locales.add(userLocale);
}
result.locales.add(Locale.DEFAULT);
if (userLocale != Locale.EN_US) {
result.locales.add(Locale.EN_US);
}
return result;
AcceptableLocales result = new AcceptableLocales();
if (userLocale != null) {
result.locales.add(userLocale);
}
result.locales.add(Locale.DEFAULT);
if (userLocale != Locale.EN_US) {
result.locales.add(Locale.EN_US);
}
return result;
}

public List<Locale> getLocales() {
return locales;
return locales;
}

}
Loading

0 comments on commit 6d13f2f

Please sign in to comment.