Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8848b73d authored by stefan-niedermann's avatar stefan-niedermann
Browse files

Adjust some old unit tests

parent 95658a6d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ public class NoteLinksUtilsTest {

    @Test
    public void doNotChangeOtherMarkdownElements() {
        //language=TEXT
        //language=md
        String markdown = "\n" +
                "# heading  \n" +
                "  \n" +
+10 −33
Original line number Diff line number Diff line
@@ -2,9 +2,6 @@ package it.niedermann.owncloud.notes.util;

import junit.framework.TestCase;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Tests the NoteUtil
 * Created by stefan on 06.10.15.
@@ -42,39 +39,19 @@ public class NoteUtilTest extends TestCase {
    }

    public void testIsEmptyLine() {
        try {
            Method m = NoteUtil.class.getDeclaredMethod("isEmptyLine");
            m.setAccessible(true);
            assertTrue((Boolean) m.invoke(null, " "));
            assertTrue((Boolean) m.invoke(null, "\n"));
            assertTrue((Boolean) m.invoke(null, "\n "));
            assertTrue((Boolean) m.invoke(null, " \n"));
            assertTrue((Boolean) m.invoke(null, " \n "));
            assertFalse((Boolean) m.invoke(null, "a \n "));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        assertTrue(NoteUtil.isEmptyLine(" "));
        assertTrue(NoteUtil.isEmptyLine("\n"));
        assertTrue(NoteUtil.isEmptyLine("\n "));
        assertTrue(NoteUtil.isEmptyLine(" \n"));
        assertTrue(NoteUtil.isEmptyLine(" \n "));
        assertFalse(NoteUtil.isEmptyLine("a \n "));
    }

    public void testGetLineWithoutMarkDown() {
        try {
            Method m = NoteUtil.class.getDeclaredMethod("isEmptyLine");
            m.setAccessible(true);
            assertEquals("Test", (String) m.invoke(null, "Test", 0));
            assertEquals("Test", (String) m.invoke(null, "\nTest", 0));
            assertEquals("Foo", (String) m.invoke(null, "Foo\nBar", 0));
            assertEquals("Bar", (String) m.invoke(null, "Foo\nBar", 1));
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        assertEquals("Test", NoteUtil.getLineWithoutMarkDown("Test", 0));
        assertEquals("Test", NoteUtil.getLineWithoutMarkDown("\nTest", 0));
        assertEquals("Foo", NoteUtil.getLineWithoutMarkDown("Foo\nBar", 0));
        assertEquals("Bar", NoteUtil.getLineWithoutMarkDown("Foo\nBar", 1));
    }

    public void testGenerateNoteTitle() {
+3 −2
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import it.niedermann.owncloud.notes.R;
 * Provides basic functionality for Note operations.
 * Created by stefan on 06.10.15.
 */
@SuppressWarnings("WeakerAccess")
public class NoteUtil {

    private static final Pattern pLists = Pattern.compile("^\\s*[*+-]\\s+", Pattern.MULTILINE);
@@ -58,7 +59,7 @@ public class NoteUtil {
     * @param line String - a single Line which ends with \n
     * @return boolean isEmpty
     */
    private static boolean isEmptyLine(@Nullable String line) {
    public static boolean isEmptyLine(@Nullable String line) {
        return removeMarkDown(line).trim().length() == 0;
    }

@@ -117,7 +118,7 @@ public class NoteUtil {
     * @return lineContent String
     */
    @NonNull
    private static String getLineWithoutMarkDown(@NonNull String content, int lineNumber) {
    public static String getLineWithoutMarkDown(@NonNull String content, int lineNumber) {
        String line = "";
        if (content.contains("\n")) {
            String[] lines = content.split("\n");