Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #682 from zanata/improve-coverage
Browse files Browse the repository at this point in the history
Improve unit test coverage
  • Loading branch information
seanf committed Feb 4, 2015
2 parents 6603f7c + b03c36c commit b4b3c38
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 21 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -1059,6 +1059,12 @@
<formats>
<format>xml</format>
</formats>
<instrumentation>
<ignoreMethodAnnotations>
<ignoreMethodAnnotation>org.zanata.util.CoverageIgnore</ignoreMethodAnnotation>
</ignoreMethodAnnotations>
<ignoreTrivial>true</ignoreTrivial>
</instrumentation>
</configuration>
</plugin>
<!-- change maven-release-plugin back to defaults (instead of oss-parent's settings) -->
Expand Down
15 changes: 15 additions & 0 deletions zanata-war/src/main/java/org/zanata/util/CoverageIgnore.java
@@ -0,0 +1,15 @@
package org.zanata.util;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Cobertura 2.0+ will ignore any method with this annotation.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CoverageIgnore {
String value() default "";
}
Expand Up @@ -5,6 +5,7 @@
import net.customware.gwt.presenter.client.EventBus;

import org.zanata.common.LocaleId;
import org.zanata.util.CoverageIgnore;
import org.zanata.webtrans.client.EventProcessor.StartCallback;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
Expand Down Expand Up @@ -286,6 +287,7 @@ public static String getUploadFileUrl() {
return GWT.getModuleBaseURL() + "files/upload";
}

@CoverageIgnore("JSNI")
public static native void redirectToUrl(String url)/*-{
$wnd.location = url;
}-*/;
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.webtrans.client.presenter;

import org.zanata.util.CoverageIgnore;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEventHandler;

Expand All @@ -36,6 +37,7 @@ public UserScriptCallbackHook() {
attachCallbackMapToWindow();
}

@CoverageIgnore("JSNI")
private static native void attachCallbackMapToWindow()/*-{
$wnd.zanataEvent = {
description : "Add callback functions to the arrays for the available event types.\n"
Expand All @@ -54,6 +56,7 @@ public void onTransUnitUpdated(TransUnitUpdatedEvent event) {
triggerAllTransUnitUpdatedCallbacksWith(event);
}

@CoverageIgnore("JSNI")
private static native void triggerAllTransUnitUpdatedCallbacksWith(
TransUnitUpdatedEvent event)/*-{
callbacks = $wnd.zanataEvent.events.transUnitUpdated.callbacks;
Expand Down
Expand Up @@ -20,6 +20,7 @@
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import org.zanata.util.CoverageIgnore;

public class CodeMirrorEditor extends Composite implements TextAreaWrapper {
private static CodeMirrorEditorUiBinder ourUiBinder = GWT
Expand All @@ -39,6 +40,7 @@ public CodeMirrorEditor(Command onFocusCallback) {
}

// see http://codemirror.net/doc/manual.html#usage
@CoverageIgnore("JSNI")
private native JavaScriptObject initCodeMirror(TextAreaElement element) /*-{
var self = this;
Expand Down Expand Up @@ -110,18 +112,21 @@ private void onChange() {
ValueChangeEvent.fire(this, getCodeMirrorContent());
}

@CoverageIgnore("JSNI")
private native String getCodeMirrorContent() /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
return editor.getValue();
}-*/;

@CoverageIgnore("JSNI")
private native void setCodeMirrorContent(String text) /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
if (editor) {
editor.setValue(text);
}
}-*/;

@CoverageIgnore("JSNI")
private native void focusEditor() /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
editor.focus();
Expand All @@ -136,13 +141,15 @@ public void setReadOnly(boolean readOnly) {
}
}

@CoverageIgnore("JSNI")
private native void setEditorOption(String option, String value) /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
if (editor) {
editor.setOption(option, value);
}
}-*/;

@CoverageIgnore("JSNI")
private native String getEditorOption(String option, String defaultValue) /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
if (editor) {
Expand All @@ -161,6 +168,7 @@ public int getCursorPos() {
return getCodeMirrorCursorPos();
}

@CoverageIgnore("JSNI")
private native int getCodeMirrorCursorPos() /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
var pos = editor.getCursor();
Expand All @@ -172,6 +180,7 @@ public void setCursorPos(int pos) {
setCodeMirrorCursorPos(pos);
}

@CoverageIgnore("JSNI")
private native void setCodeMirrorCursorPos(int cursorIndex) /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
var pos = editor.posFromIndex(cursorIndex);
Expand All @@ -185,6 +194,7 @@ public void highlight(String term) {
}
}

@CoverageIgnore("JSNI")
private native void codeMirrorHighlight(String term) /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
var searchCursor = editor.getSearchCursor(term, {
Expand All @@ -202,6 +212,7 @@ public void refresh() {
refreshCodeMirror();
}

@CoverageIgnore("JSNI")
private native void refreshCodeMirror() /*-{
var editor = this.@org.zanata.webtrans.client.ui.CodeMirrorEditor::codeMirror;
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import org.zanata.util.CoverageIgnore;

public class CodeMirrorReadOnlyWidget extends Composite implements
SourceContentWrapper {
Expand All @@ -26,6 +27,7 @@ public CodeMirrorReadOnlyWidget() {
}

// see http://codemirror.net/doc/manual.html#usage
@CoverageIgnore("JSNI")
private native JavaScriptObject initCodeMirror(Element element) /*-{
var self = this;
var codeMirrorEditor = $wnd.CodeMirror.fromTextArea(element, {
Expand Down Expand Up @@ -53,6 +55,7 @@ public void setText(String text) {
content = text;
}

@CoverageIgnore("JSNI")
public native void refresh() /*-{
var codeMirror = this.@org.zanata.webtrans.client.ui.CodeMirrorReadOnlyWidget::codeMirror;
if (codeMirror) {
Expand All @@ -66,6 +69,7 @@ public void highlight(String term) {
}
}

@CoverageIgnore("JSNI")
private native void codeMirrorHighlight(String term) /*-{
var codeMirror = this.@org.zanata.webtrans.client.ui.CodeMirrorReadOnlyWidget::codeMirror;
var searchCursor = codeMirror.getSearchCursor(term, {
Expand Down
Expand Up @@ -29,6 +29,7 @@
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.*;
import org.zanata.util.CoverageIgnore;


/**
Expand Down Expand Up @@ -65,6 +66,7 @@ private void onValueChanged(String newValue, EditorSearchFieldListener listener)
listener.onSearchFieldValueChange(newValue);
}

@CoverageIgnore("JSNI")
private native void initTextBox(Element wrapper, EditorSearchFieldListener listener)/*-{
var valueChangeCallback = this.@org.zanata.webtrans.client.ui.EditorSearchField::onValueChanged(Ljava/lang/String;Lorg/zanata/webtrans/client/ui/EditorSearchFieldListener;);
$wnd.searchSuggestions.init(wrapper, function (newValue) {
Expand Down
Expand Up @@ -22,15 +22,18 @@

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import org.zanata.util.CoverageIgnore;

public class Highlighting {

@CoverageIgnore("JSNI")
public static native void syntaxHighlight(String text, Element elem)/*-{
elem.innerHTML = '';
$wnd.CodeMirror.runMode(text, "visibleSpace", elem);
}-*/;

// From JavaScript on http://www.nsftools.com/misc/SearchAndHighlight.htm
@CoverageIgnore("JSNI")
public static native void searchHighlight(String searchTerm, Element elem)/*-{
// the highlightStartTag and highlightEndTag parameters are optional
var bodyText = elem.innerHTML;
Expand Down Expand Up @@ -76,6 +79,7 @@ public static String diffAsHtml(String text1, String text2) {
return diffsToHtml(diffs);
}

@CoverageIgnore("JSNI")
private static native JavaScriptObject diff(String text1, String text2,
boolean cleanupSemantic)/*-{
if (!$wnd.diffMatchPatch) {
Expand All @@ -92,6 +96,7 @@ private static native JavaScriptObject diff(String text1, String text2,
}-*/;

// modified diff_prettyHtml() from diff_match_patch.js
@CoverageIgnore("JSNI")
private static native String diffsToHtml(JavaScriptObject diffs)/*-{
var html = [];
var pattern_amp = /&/g;
Expand Down Expand Up @@ -125,6 +130,7 @@ public static String diffAsHighlight(String text1, String text2) {

// DIFF_DELETE text is hidden, DIFF_EQUAL text is highlighted, and
// DIFF_INSERT text is shown plain
@CoverageIgnore("JSNI")
private static native String diffsHighlight(JavaScriptObject diffs)/*-{
var html = [];
var pattern_amp = /&/g;
Expand Down
Expand Up @@ -22,6 +22,7 @@

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.TextBox;
import org.zanata.util.CoverageIgnore;

/**
* @author damason@redhat.com
Expand Down Expand Up @@ -51,6 +52,7 @@ public boolean isFocused() {
return isElementFocused(getElement());
}

@CoverageIgnore("JSNI")
private native boolean isElementFocused(Element element)/*-{
return element.ownerDocument.activeElement === element;
}-*/;
Expand Down
Expand Up @@ -3,19 +3,25 @@
*/
package org.zanata.webtrans.client.util;

import java.util.Date;
import com.google.gwt.i18n.shared.DateTimeFormat;
import com.google.gwt.i18n.shared.DefaultDateTimeFormatInfo;

import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import javax.annotation.concurrent.NotThreadSafe;
import java.util.Date;

/**
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*/
@NotThreadSafe
public class DateUtil {
private static final DefaultDateTimeFormatInfo info =
new DefaultDateTimeFormatInfo();
private final static String DATE_TIME_SHORT_PATTERN = "dd/MM/yy HH:mm";
private static DateTimeFormat dtfShort = new DateTimeFormat(DATE_TIME_SHORT_PATTERN, info) {};
private final static String DATE_TIME_LONG_PATTERN = "dd/MM/yy HH:mm:ss";
private static DateTimeFormat dtfLong = new DateTimeFormat(DATE_TIME_LONG_PATTERN, info) {};

/**
* Format date to dd/MM/yy hh:mm a
Expand All @@ -25,22 +31,7 @@ public class DateUtil {
*/
public static String formatShortDate(Date date) {
if (date != null) {
return DateTimeFormat.getFormat(DATE_TIME_SHORT_PATTERN).format(
date);
}
return null;
}

/**
* Format date to hh:mm:ss
*
* @param date
* @return
*/
public static String formatTime(Date date) {
if (date != null) {
return DateTimeFormat.getFormat(
PredefinedFormat.HOUR24_MINUTE_SECOND).format(date);
return dtfShort.format(date);
}
return null;
}
Expand All @@ -53,8 +44,7 @@ public static String formatTime(Date date) {
*/
public static String formatLongDateTime(Date date) {
if (date != null) {
return DateTimeFormat.getFormat(DATE_TIME_LONG_PATTERN)
.format(date);
return dtfLong.format(date);
}
return null;
}
Expand Down
Expand Up @@ -20,6 +20,8 @@
*/
package org.zanata.webtrans.client.util;

import org.zanata.util.CoverageIgnore;

/**
* Utilities for dealing with javascript native code.
*
Expand All @@ -33,6 +35,7 @@ public class JavascriptUtil {
* @param varName Variable name.
* @return The value (as a string) assigned to varName.
*/
@CoverageIgnore("JSNI")
public static native String getJavascriptValue(String varName) /*-{
return $wnd[varName];
}-*/;
Expand Down
Expand Up @@ -21,6 +21,7 @@
package org.zanata.webtrans.client.view;

import org.zanata.rest.dto.stats.ContainerTranslationStatistics;
import org.zanata.util.CoverageIgnore;
import org.zanata.webtrans.client.Application;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.presenter.KeyShortcutPresenter;
Expand Down Expand Up @@ -399,9 +400,11 @@ private static String getMessageClass(NotificationEvent.Severity severity) {
}

// @formatter:off
@CoverageIgnore("JSNI")
private static native void activateNotification(Element element)/*-{
$wnd.zanata.messages.activate(element);
}-*/;
@CoverageIgnore("JSNI")
private static native void deactivateNotification(Element element)/*-{
$wnd.zanata.messages.deactivate(element);
}-*/;
Expand Down
Expand Up @@ -20,6 +20,7 @@
*/
package org.zanata.webtrans.client.view;

import org.zanata.util.CoverageIgnore;
import org.zanata.webtrans.client.presenter.UserConfigHolder.ConfigurationState;
import org.zanata.webtrans.client.resources.UiMessages;
import org.zanata.webtrans.client.ui.EditorSearchField;
Expand Down Expand Up @@ -186,6 +187,7 @@ private static void setPartiallyChecked(CheckBox checkbox,
setElementIndeterminate(checkbox.getElement(), partiallyChecked);
}

@CoverageIgnore("JSNI")
private static native void setElementIndeterminate(Element elem,
boolean indeterminate)/*-{
elem.getElementsByTagName('input')[0].indeterminate = indeterminate;
Expand Down
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import com.google.gwt.user.client.Element;
import org.zanata.util.CoverageIgnore;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.FilterViewConfirmationDisplay;
import org.zanata.webtrans.client.ui.LoadingPanel;
Expand Down Expand Up @@ -181,6 +182,7 @@ public void ensureVisible(TargetContentsDisplay currentDisplay) {
scrollToElement(root.getElement(), transUnitRow.getElement());
}

@CoverageIgnore("JSNI")
private native void scrollToElement(Element scroll, Element item) /*-{
if (!item || !scroll) {
return;
Expand Down

0 comments on commit b4b3c38

Please sign in to comment.