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

Commit eb9cba14 authored by Christoph Loy's avatar Christoph Loy Committed by Niedermann IT-Dienstleistungen
Browse files

Move Tests from androidTests to tests

parent 6babdfa0
Loading
Loading
Loading
Loading
+55 −5
Original line number Original line Diff line number Diff line
package it.niedermann.owncloud.notes.util;
package it.niedermann.owncloud.notes.util;


import android.text.TextUtils;

import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;


import java.util.HashSet;
import java.util.HashSet;
@@ -20,7 +18,7 @@ public class NoteLinksUtils {
    /**
    /**
     * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)`
     * Replaces all links to other notes of the form `[<link-text>](<note-file-id>)`
     * in the markdown string with links to a dummy url.
     * in the markdown string with links to a dummy url.
     *
     * <p>
     * Why is this needed?
     * Why is this needed?
     * See discussion in issue #623
     * See discussion in issue #623
     *
     *
@@ -38,7 +36,8 @@ public class NoteLinksUtils {
            }
            }
        }
        }


        String noteRemoteIdsCondition = TextUtils.join("|", noteRemoteIdsToReplace);
        String noteRemoteIdsCondition = join("|", noteRemoteIdsToReplace);

        Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition));
        Pattern replacePattern = Pattern.compile(String.format(replaceNoteRemoteIdsRegEx, noteRemoteIdsCondition));
        Matcher replaceMatcher = replacePattern.matcher(markdown);
        Matcher replaceMatcher = replacePattern.matcher(markdown);
        return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX));
        return replaceMatcher.replaceAll(String.format("[$1](%s$2)", RELATIVE_LINK_WORKAROUND_PREFIX));
@@ -63,4 +62,55 @@ public class NoteLinksUtils {
    public static long extractNoteRemoteId(String link) {
    public static long extractNoteRemoteId(String link) {
        return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, ""));
        return Long.parseLong(link.replace(RELATIVE_LINK_WORKAROUND_PREFIX, ""));
    }
    }

    /**
     * Returns a new {@code String} composed of copies of the
     * {@code CharSequence elements} joined together with a copy of the
     * specified {@code delimiter}.
     *
     * <blockquote>For example,
     * <pre>{@code
     *     List<String> strings = new LinkedList<>();
     *     strings.add("Java");strings.add("is");
     *     strings.add("cool");
     *     String message = String.join(" ", strings);
     *     //message returned is: "Java is cool"
     *
     *     Set<String> strings = new LinkedHashSet<>();
     *     strings.add("Java"); strings.add("is");
     *     strings.add("very"); strings.add("cool");
     *     String message = String.join("-", strings);
     *     //message returned is: "Java-is-very-cool"
     * }</pre></blockquote>
     * <p>
     * Note that if an individual element is {@code null}, then {@code "null"} is added.
     *
     * @param delimiter a sequence of characters that is used to separate each
     *                  of the {@code elements} in the resulting {@code String}
     * @param elements  an {@code Iterable} that will have its {@code elements}
     *                  joined together.
     * @return a new {@code String} that is composed from the {@code elements}
     * argument
     * @throws NullPointerException If {@code delimiter} or {@code elements}
     *                              is {@code null}
     * @see String#join(CharSequence, Iterable)
     */
    private static String join(CharSequence delimiter, Iterable<String> elements) {
        if (delimiter == null) {
            throw new NullPointerException("Parameter delimiter must not be null");
        }
        if (elements == null) {
            throw new NullPointerException("Parameter elements must not be bull");
        }

        StringBuilder builder = new StringBuilder();
        for (String item : elements) {
            builder.append(item);
            builder.append(delimiter);
        }
        if (builder.length() > 0) {
            builder.deleteCharAt(builder.length() - 1);
        }
        return builder.toString();
    }
}
}
+0 −2
Original line number Original line Diff line number Diff line
package it.niedermann.owncloud.notes.util;
package it.niedermann.owncloud.notes.util;


import androidx.test.filters.SmallTest;


import org.junit.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Test;
@@ -12,7 +11,6 @@ import java.util.Set;
import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX;
import static it.niedermann.owncloud.notes.util.NoteLinksUtils.RELATIVE_LINK_WORKAROUND_PREFIX;




@SmallTest
public class NoteLinksUtilsTest {
public class NoteLinksUtilsTest {


    @Test
    @Test