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

Commit 48caba2b authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Adjust test style

parent 30e38d57
Loading
Loading
Loading
Loading
+31 −43
Original line number Diff line number Diff line
@@ -3,27 +3,26 @@ package it.niedermann.owncloud.notes.edit;
import org.junit.Assert;
import org.junit.Test;

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

public class SearchableBaseNoteFragmentTest {

    @SuppressWarnings("ConstantConditions")
    @Test
    public void testCountOccurrencesFixed() {
        try {
            Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
    public void testCountOccurrencesFixed() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        final Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
        method.setAccessible(true);

        for (int count = 0; count <= 15; ++count) {
                StringBuilder sb = new StringBuilder("Mike Chester Wang");
            final StringBuilder sb = new StringBuilder("Mike Chester Wang");
            for (int i = 0; i < count; ++i) {
                sb.append(sb);
            }

                long startTime = System.currentTimeMillis();
                int num = (int) method.invoke(null, sb.toString(), "Chester");
                long endTime = System.currentTimeMillis();
            final long startTime = System.currentTimeMillis();
            final int num = (int) method.invoke(null, sb.toString(), "Chester");
            final long endTime = System.currentTimeMillis();
            System.out.println("Fixed Version");
            System.out.println("Total Time: " + (endTime - startTime) + " ms");
            System.out.println("Total Times: " + num);
@@ -31,18 +30,12 @@ public class SearchableBaseNoteFragmentTest {
            Assert.assertEquals((int) Math.pow(2, count), num);
            System.out.println();
        }

        } catch (Exception e) {
            Assert.fail(Arrays.toString(e.getStackTrace()));
            System.out.println("Test Count Occurrences Fixed" + Arrays.toString(e.getStackTrace()));
        }
    }

    @SuppressWarnings("ConstantConditions")
    @Test
    public void testNullOrEmptyInput() {
        try {
            Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
    public void testNullOrEmptyInput() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        final Method method = SearchableBaseNoteFragment.class.getDeclaredMethod("countOccurrences", String.class, String.class);
        method.setAccessible(true);

        int num;
@@ -54,10 +47,5 @@ public class SearchableBaseNoteFragmentTest {
        Assert.assertEquals(0, num);
        num = (int) method.invoke(null, "Hi my name is Mike Chester Wang", "");
        Assert.assertEquals(0, num);

        } catch (Exception e) {
            Assert.fail(Arrays.toString(e.getStackTrace()));
            System.out.println("Test Null Or Empty Input" + Arrays.toString(e.getStackTrace()));
        }
    }
}
 No newline at end of file