Loading app/src/test/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragmentTest.java +31 −43 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; Loading @@ -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 Loading
app/src/test/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragmentTest.java +31 −43 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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; Loading @@ -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