Fix markwon-html tests

This commit is contained in:
Dimitry Ivanov 2018-12-22 17:39:29 +03:00
parent 4f02a793e7
commit ef15ee4bd2
7 changed files with 41 additions and 68 deletions

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.html.impl; package ru.noties.markwon.html;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -14,13 +14,9 @@ import java.util.Map;
import ix.Ix; import ix.Ix;
import ix.IxFunction; import ix.IxFunction;
import ru.noties.markwon.html.CssInlineStyleParser;
import ru.noties.markwon.html.CssProperty;
import ru.noties.markwon.test.TestUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static ru.noties.markwon.test.TestUtils.with;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
@ -42,7 +38,7 @@ public class CssInlineStyleParserTest {
assertEquals(1, list.size()); assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key()); assertEquals("key", cssProperty.key());
@ -60,7 +56,7 @@ public class CssInlineStyleParserTest {
assertEquals(2, list.size()); assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key()); assertEquals("key1", cssProperty.key());
@ -68,7 +64,7 @@ public class CssInlineStyleParserTest {
} }
}); });
with(list.get(1), new TestUtils.Action<CssProperty>() { with(list.get(1), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key2", cssProperty.key()); assertEquals("key2", cssProperty.key());
@ -84,7 +80,7 @@ public class CssInlineStyleParserTest {
final List<CssProperty> list = listProperties(input); final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size()); assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key()); assertEquals("key", cssProperty.key());
@ -100,7 +96,7 @@ public class CssInlineStyleParserTest {
final List<CssProperty> list = listProperties(input); final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size()); assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key", cssProperty.key()); assertEquals("key", cssProperty.key());
@ -116,7 +112,7 @@ public class CssInlineStyleParserTest {
final List<CssProperty> list = listProperties(input); final List<CssProperty> list = listProperties(input);
assertEquals(2, list.size()); assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key()); assertEquals("key1", cssProperty.key());
@ -124,7 +120,7 @@ public class CssInlineStyleParserTest {
} }
}); });
with(list.get(1), new TestUtils.Action<CssProperty>() { with(list.get(1), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key2", cssProperty.key()); assertEquals("key2", cssProperty.key());
@ -149,7 +145,7 @@ public class CssInlineStyleParserTest {
final List<CssProperty> list = listProperties(input); final List<CssProperty> list = listProperties(input);
assertEquals(1, list.size()); assertEquals(1, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key4", cssProperty.key()); assertEquals("key4", cssProperty.key());
@ -174,7 +170,7 @@ public class CssInlineStyleParserTest {
assertEquals(2, list.size()); assertEquals(2, list.size());
with(list.get(0), new TestUtils.Action<CssProperty>() { with(list.get(0), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key1", cssProperty.key()); assertEquals("key1", cssProperty.key());
@ -182,7 +178,7 @@ public class CssInlineStyleParserTest {
} }
}); });
with(list.get(1), new TestUtils.Action<CssProperty>() { with(list.get(1), new Action<CssProperty>() {
@Override @Override
public void apply(@NonNull CssProperty cssProperty) { public void apply(@NonNull CssProperty cssProperty) {
assertEquals("key3", cssProperty.key()); assertEquals("key3", cssProperty.key());
@ -238,4 +234,13 @@ public class CssInlineStyleParserTest {
}) })
.toList(); .toList();
} }
public interface Action<T> {
void apply(@NonNull T t);
}
private static <T> void with(@NonNull T t, @NonNull Action<T> action) {
action.apply(t);
}
} }

View File

@ -1,12 +1,10 @@
package ru.noties.markwon.html.impl; package ru.noties.markwon.html;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Collections; import java.util.Collections;
import ru.noties.markwon.html.HtmlEmptyTagReplacement;
import ru.noties.markwon.html.api.HtmlTag;
import ru.noties.markwon.html.HtmlTagImpl.InlineImpl; import ru.noties.markwon.html.HtmlTagImpl.InlineImpl;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.html.impl; package ru.noties.markwon.html;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -15,11 +15,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import ru.noties.markwon.html.HtmlEmptyTagReplacement;
import ru.noties.markwon.html.MarkwonHtmlParserImpl;
import ru.noties.markwon.html.api.HtmlTag;
import ru.noties.markwon.html.api.MarkwonHtmlParser;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

View File

@ -1,4 +1,4 @@
package ru.noties.markwon.html.impl; package ru.noties.markwon.html;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,24 +1,20 @@
package ru.noties.markwon.html.impl.jsoup.nodes; package ru.noties.markwon.html.jsoup.nodes;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import ru.noties.markwon.html.jsoup.nodes.CommonMarkEntities;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
public class CommonMarkEntitiesTest { public class CommonMarkEntitiesTest {
@Test @Test
public void can_access_field() { public void can_access_field() {
assertTrue("&", CommonMarkEntities.isNamedEntity("amp")); Assert.assertTrue("&", CommonMarkEntities.isNamedEntity("amp"));
final int[] codepoints = new int[1]; final int[] codepoints = new int[1];
CommonMarkEntities.codepointsForName("amp", codepoints); CommonMarkEntities.codepointsForName("amp", codepoints);
assertEquals('&', codepoints[0]); Assert.assertEquals('&', codepoints[0]);
} }
} }

View File

@ -1,8 +1,9 @@
package ru.noties.markwon.html.impl.tag; package ru.noties.markwon.html.tag;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -13,13 +14,8 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import ru.noties.markwon.html.tag.ImageSizeParserImpl; import ru.noties.markwon.html.CssInlineStyleParser;
import ru.noties.markwon.image.ImageSize; import ru.noties.markwon.image.ImageSize;
import ru.noties.markwon.renderer.html2.CssInlineStyleParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE) @Config(manifest = Config.NONE)
@ -36,7 +32,7 @@ public class ImageSizeParserImplTest {
@Test @Test
public void nothing() { public void nothing() {
assertNull(impl.parse(Collections.<String, String>emptyMap())); Assert.assertNull(impl.parse(Collections.<String, String>emptyMap()));
} }
@Test @Test
@ -153,15 +149,15 @@ public class ImageSizeParserImplTest {
}; };
for (String dimension : dimensions) { for (String dimension : dimensions) {
assertNull(dimension, impl.dimension(dimension)); Assert.assertNull(dimension, impl.dimension(dimension));
} }
} }
private static void assertImageSize(@Nullable ImageSize expected, @Nullable ImageSize actual) { private static void assertImageSize(@Nullable ImageSize expected, @Nullable ImageSize actual) {
if (expected == null) { if (expected == null) {
assertNull(actual); Assert.assertNull(actual);
} else { } else {
assertNotNull(actual); Assert.assertNotNull(actual);
assertDimension("width", expected.width, actual.width); assertDimension("width", expected.width, actual.width);
assertDimension("height", expected.height, actual.height); assertDimension("height", expected.height, actual.height);
} }
@ -172,11 +168,11 @@ public class ImageSizeParserImplTest {
@Nullable ImageSize.Dimension expected, @Nullable ImageSize.Dimension expected,
@Nullable ImageSize.Dimension actual) { @Nullable ImageSize.Dimension actual) {
if (expected == null) { if (expected == null) {
assertNull(name, actual); Assert.assertNull(name, actual);
} else { } else {
assertNotNull(name, actual); Assert.assertNotNull(name, actual);
assertEquals(name, expected.value, actual.value, DELTA); Assert.assertEquals(name, expected.value, actual.value, DELTA);
assertEquals(name, expected.unit, actual.unit); Assert.assertEquals(name, expected.unit, actual.unit);
} }
} }

View File

@ -1,17 +0,0 @@
package ru.noties.markwon.test;
import android.support.annotation.NonNull;
public abstract class TestUtils {
public interface Action<T> {
void apply(@NonNull T t);
}
public static <T> void with(@NonNull T t, @NonNull Action<T> action) {
action.apply(t);
}
private TestUtils() {
}
}