Add some basic JUnit Tests

This commit is contained in:
Stefan Niedermann 2015-10-06 21:10:23 +02:00
parent 9db8e1ce40
commit 9097f0050a
5 changed files with 54 additions and 19 deletions

View file

@ -0,0 +1,25 @@
package it.niedermann.owncloud.notes.model;
import junit.framework.TestCase;
import java.util.Calendar;
/**
* Tests the Note Model
* Created by stefan on 06.10.15.
*/
public class NoteTest extends TestCase {
public void testMarkDownStrip() {
Note note = new Note(0, Calendar.getInstance(), "#Title", "");
assertTrue("Title".equals(note.getTitle()));
note.setTitle("* Aufzählung");
assertTrue("Aufzählung".equals(note.getTitle()));
}
public void testMarkDownRendering() {
Note note = new Note(0, Calendar.getInstance(), "", "**bold**");
System.out.println(note.getHtmlContent());
assertTrue(note.getHtmlContent().contains("<strong>bold</strong>"));
}
}

View file

@ -0,0 +1,23 @@
package it.niedermann.owncloud.notes.util;
import junit.framework.TestCase;
/**
* Tests the NotesClientUtil
* Created by stefan on 24.09.15.
*/
public class NotesClientUtilTest extends TestCase {
public void testIsHttp() {
assertTrue(NotesClientUtil.isHttp("http://example.com"));
assertTrue(NotesClientUtil.isHttp("http://www.example.com/"));
assertFalse(NotesClientUtil.isHttp("https://www.example.com/"));
assertFalse(NotesClientUtil.isHttp(null));
}
public void testIsValidURLTest() {
assertTrue(NotesClientUtil.isValidURL("http://www.example.com/"));
assertTrue(NotesClientUtil.isValidURL("https://www.example.com"));
assertFalse(NotesClientUtil.isValidURL("htp://www.example.com/"));
assertFalse(NotesClientUtil.isValidURL(null));
}
}

View file

@ -1,14 +0,0 @@
package it.niedermann.owncloud.notes.util;
import junit.framework.TestCase;
/**
* Tests the URLValidatorAsyncTask
* Created by stefan on 24.09.15.
*/
public class URLValidatorAsyncTaskTest extends TestCase {
public void testIsHttp() {
assertTrue(URLValidatorAsyncTask.isHttp("http://www.example.com/"));
assertFalse(URLValidatorAsyncTask.isHttp("https://www.example.com/"));
}
}

View file

@ -25,8 +25,9 @@ public class Note implements Serializable {
this.id = id;
if(title != null)
this.title = Html.fromHtml(and_down.markdownToHtml(title)).toString().trim();
setTitle(title);
setContent(content);
this.modified = modified;
this.content = content;
}
public long getId() {
@ -38,7 +39,7 @@ public class Note implements Serializable {
}
public void setTitle(String title) {
this.title = title;
this.title = Html.fromHtml(and_down.markdownToHtml(title)).toString().trim();
}
@SuppressWarnings("WeakerAccess")

View file

@ -21,7 +21,7 @@ public class NotesClientUtil {
* @return true, if the given String is only http
*/
public static boolean isHttp(String url) {
return url.length() > 4 && url.startsWith("http") && url.charAt(4) != 's';
return url != null && url.length() > 4 && url.startsWith("http") && url.charAt(4) != 's';
}
/**