mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
revert "Converted core libraries to KMP"
commit_hash:6e8db1a20289a48dd6498fc3226f525d4db69da8
This commit is contained in:
+11
-11
@@ -557,11 +557,12 @@
|
||||
"client/android/api-generator-test/src/test/java/com/yandex/generator/TestApplication.kt":"divkit/public/client/android/api-generator-test/src/test/java/com/yandex/generator/TestApplication.kt",
|
||||
"client/android/api-generator-test/src/test/resources/robolectric.properties":"divkit/public/client/android/api-generator-test/src/test/resources/robolectric.properties",
|
||||
"client/android/api-generator-test/testing-generator-config.json":"divkit/public/client/android/api-generator-test/testing-generator-config.json",
|
||||
"client/android/assertion/build.gradle.kts":"divkit/public/client/android/assertion/build.gradle.kts",
|
||||
"client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/Assert.kt":"divkit/public/client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/Assert.kt",
|
||||
"client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/AssertionErrorHandler.kt":"divkit/public/client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/AssertionErrorHandler.kt",
|
||||
"client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/ComparisonFailure.kt":"divkit/public/client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/ComparisonFailure.kt",
|
||||
"client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/KAssert.kt":"divkit/public/client/android/assertion/src/commonMain/kotlin/com/yandex/div/internal/KAssert.kt",
|
||||
"client/android/assertion/build.gradle":"divkit/public/client/android/assertion/build.gradle",
|
||||
"client/android/assertion/proguard-rules.pro":"divkit/public/client/android/assertion/proguard-rules.pro",
|
||||
"client/android/assertion/src/main/java/com/yandex/div/internal/Assert.java":"divkit/public/client/android/assertion/src/main/java/com/yandex/div/internal/Assert.java",
|
||||
"client/android/assertion/src/main/java/com/yandex/div/internal/AssertionErrorHandler.kt":"divkit/public/client/android/assertion/src/main/java/com/yandex/div/internal/AssertionErrorHandler.kt",
|
||||
"client/android/assertion/src/main/java/com/yandex/div/internal/ComparisonFailure.kt":"divkit/public/client/android/assertion/src/main/java/com/yandex/div/internal/ComparisonFailure.kt",
|
||||
"client/android/assertion/src/main/java/com/yandex/div/internal/KAssert.kt":"divkit/public/client/android/assertion/src/main/java/com/yandex/div/internal/KAssert.kt",
|
||||
"client/android/beacon/build.gradle":"divkit/public/client/android/beacon/build.gradle",
|
||||
"client/android/beacon/proguard-rules.pro":"divkit/public/client/android/beacon/proguard-rules.pro",
|
||||
"client/android/beacon/src/main/java/com/yandex/android/beacon/BeaconItem.kt":"divkit/public/client/android/beacon/src/main/java/com/yandex/android/beacon/BeaconItem.kt",
|
||||
@@ -15064,24 +15065,23 @@
|
||||
"client/android/gradle/wrapper/gradle-wrapper.properties":"divkit/public/client/android/gradle/wrapper/gradle-wrapper.properties",
|
||||
"client/android/gradlew":"divkit/public/client/android/gradlew",
|
||||
"client/android/gradlew.bat":"divkit/public/client/android/gradlew.bat",
|
||||
"client/android/kmp-library.gradle":"divkit/public/client/android/kmp-library.gradle",
|
||||
"client/android/lint-rules/build.gradle":"divkit/public/client/android/lint-rules/build.gradle",
|
||||
"client/android/lint-rules/src/main/java/com/yandex/div/lint/DivKitIssueRegistry.kt":"divkit/public/client/android/lint-rules/src/main/java/com/yandex/div/lint/DivKitIssueRegistry.kt",
|
||||
"client/android/lint-rules/src/main/java/com/yandex/div/lint/OnPreDrawListenerDetector.kt":"divkit/public/client/android/lint-rules/src/main/java/com/yandex/div/lint/OnPreDrawListenerDetector.kt",
|
||||
"client/android/lint-rules/src/main/java/com/yandex/div/lint/OnPreDrawListenerIssue.kt":"divkit/public/client/android/lint-rules/src/main/java/com/yandex/div/lint/OnPreDrawListenerIssue.kt",
|
||||
"client/android/lint-rules/src/main/resources/META-INF/services/com.android.tools.lint.client.api.IssueRegistry":"divkit/public/client/android/lint-rules/src/main/resources/META-INF/services/com.android.tools.lint.client.api.IssueRegistry",
|
||||
"client/android/lint-rules/src/test/java/com/yandex/div/lint/OnPreDrawListenerDetectorTest.kt":"divkit/public/client/android/lint-rules/src/test/java/com/yandex/div/lint/OnPreDrawListenerDetectorTest.kt",
|
||||
"client/android/logging/build.gradle.kts":"divkit/public/client/android/logging/build.gradle.kts",
|
||||
"client/android/logging/src/androidMain/kotlin/com/yandex/div/internal/KLog.kt":"divkit/public/client/android/logging/src/androidMain/kotlin/com/yandex/div/internal/KLog.kt",
|
||||
"client/android/logging/src/androidMain/kotlin/com/yandex/div/internal/Log.kt":"divkit/public/client/android/logging/src/androidMain/kotlin/com/yandex/div/internal/Log.kt",
|
||||
"client/android/logging/src/androidMain/kotlin/com/yandex/div/logging/Severity.kt":"divkit/public/client/android/logging/src/androidMain/kotlin/com/yandex/div/logging/Severity.kt",
|
||||
"client/android/logging/build.gradle":"divkit/public/client/android/logging/build.gradle",
|
||||
"client/android/logging/proguard-rules.pro":"divkit/public/client/android/logging/proguard-rules.pro",
|
||||
"client/android/logging/src/main/java/com/yandex/div/internal/KLog.kt":"divkit/public/client/android/logging/src/main/java/com/yandex/div/internal/KLog.kt",
|
||||
"client/android/logging/src/main/java/com/yandex/div/internal/Log.java":"divkit/public/client/android/logging/src/main/java/com/yandex/div/internal/Log.java",
|
||||
"client/android/logging/src/main/java/com/yandex/div/logging/Severity.kt":"divkit/public/client/android/logging/src/main/java/com/yandex/div/logging/Severity.kt",
|
||||
"client/android/picasso/build.gradle":"divkit/public/client/android/picasso/build.gradle",
|
||||
"client/android/picasso/proguard-rules.pro":"divkit/public/client/android/picasso/proguard-rules.pro",
|
||||
"client/android/picasso/src/main/java/com/yandex/div/picasso/PicassoDivImageLoader.kt":"divkit/public/client/android/picasso/src/main/java/com/yandex/div/picasso/PicassoDivImageLoader.kt",
|
||||
"client/android/publish-android.gradle":"divkit/public/client/android/publish-android.gradle",
|
||||
"client/android/publish-common.gradle":"divkit/public/client/android/publish-common.gradle",
|
||||
"client/android/publish-java.gradle":"divkit/public/client/android/publish-java.gradle",
|
||||
"client/android/publish-kmp.gradle":"divkit/public/client/android/publish-kmp.gradle",
|
||||
"client/android/sample/README.md":"divkit/public/client/android/sample/README.md",
|
||||
"client/android/sample/build.gradle":"divkit/public/client/android/sample/build.gradle",
|
||||
"client/android/sample/lint-baseline.xml":"divkit/public/client/android/sample/lint-baseline.xml",
|
||||
|
||||
+1
-1
@@ -6,6 +6,6 @@ import com.yandex.div.internal.Assert
|
||||
class TestApplication : Application() {
|
||||
|
||||
init {
|
||||
Assert.isEnabled = true
|
||||
Assert.setEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
apply from: "${project.projectDir}/../div-library.gradle"
|
||||
apply from: "${project.projectDir}/../div-tests.gradle"
|
||||
apply from: "${project.projectDir}/../publish-android.gradle"
|
||||
|
||||
android {
|
||||
namespace 'com.yandex.div.assertion'
|
||||
|
||||
buildFeatures { buildConfig = true }
|
||||
|
||||
defaultConfig {
|
||||
buildConfigField "boolean", "DISABLE_ASSERTS", "${providers.gradleProperty("disableAssertsInBuild").map(Boolean::parseBoolean).get()}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.androidx.core
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN
|
||||
import java.lang.Boolean.parseBoolean
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.kotlin.multiplatform.library)
|
||||
alias(libs.plugins.buildkonfig)
|
||||
alias(libs.plugins.kotlin.multiplatform)
|
||||
}
|
||||
|
||||
apply(from = "../kmp-library.gradle")
|
||||
apply(from = "../publish-kmp.gradle")
|
||||
|
||||
kotlin {
|
||||
androidLibrary {
|
||||
namespace = "com.yandex.div.assertion"
|
||||
}
|
||||
}
|
||||
|
||||
buildkonfig {
|
||||
packageName = "com.yandex.div.internal"
|
||||
|
||||
defaultConfigs {
|
||||
buildConfigField(BOOLEAN, "DISABLE_ASSERTS", "${providers.gradleProperty("disableAssertsInBuild").map(::parseBoolean).get()}")
|
||||
}
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
package com.yandex.div.internal
|
||||
|
||||
/**
|
||||
* Contains methods to make assertions that help capture programming errors. Should be disabled in the production environment.
|
||||
* Disabled by default.
|
||||
*/
|
||||
object Assert {
|
||||
|
||||
private var _assertionErrorHandler = AssertionErrorHandler { throw it }
|
||||
|
||||
@Volatile
|
||||
private var _isEnabled = false
|
||||
|
||||
/**
|
||||
* Returns value indicating if assertions are enabled. This class won't throw any [AssertionError], if disabled.
|
||||
*/
|
||||
@JvmStatic
|
||||
var isEnabled: Boolean
|
||||
get() {
|
||||
if (BuildKonfig.DISABLE_ASSERTS) {
|
||||
return false
|
||||
}
|
||||
return _isEnabled
|
||||
}
|
||||
set(value) {
|
||||
_isEnabled = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true. If it isn't it throws an [AssertionError] with the given message.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun assertTrue(message: String?, condition: Boolean) {
|
||||
if (!condition) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true. If it isn't it throws an [AssertionError] without a message.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun assertTrue(condition: Boolean) {
|
||||
assertTrue(null, condition)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is false. If it isn't it throws an [AssertionError] without a message.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun assertFalse(condition: Boolean) {
|
||||
assertTrue(null, !condition)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails with the given message.
|
||||
*/
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun fail(message: String? = null) {
|
||||
if (isEnabled) {
|
||||
performFail(AssertionError(message ?: ""))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails with the given message and throwable that caused the failure.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun fail(message: String?, cause: Throwable?) {
|
||||
if (isEnabled) {
|
||||
val assertionError: java.lang.AssertionError = java.lang.AssertionError(message)
|
||||
assertionError.initCause(cause)
|
||||
performFail(assertionError)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom [AssertionErrorHandler] to override on fail behavior
|
||||
*/
|
||||
fun setAssertPerformer(assertionErrorHandler: AssertionErrorHandler) {
|
||||
_assertionErrorHandler = assertionErrorHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects are equal. If they are not, an [AssertionError] is thrown with the given message.
|
||||
* If `expected` and `actual` are `null`, they are considered equal.
|
||||
*
|
||||
* @param message the identifying message for the [AssertionError] (`null` okay)
|
||||
* @param expected expected value
|
||||
* @param actual actual value
|
||||
*/
|
||||
fun assertEquals(message: String?, expected: Any?, actual: Any?) {
|
||||
if (expected == null && actual == null) {
|
||||
return
|
||||
}
|
||||
if (expected != null && expected == actual) {
|
||||
return
|
||||
}
|
||||
if (expected is String && actual is String) {
|
||||
performFail(ComparisonFailure(message ?: "", expected, actual))
|
||||
} else {
|
||||
failNotEquals(message, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two ints are equal. If they are not, an [AssertionError] is thrown.
|
||||
*
|
||||
* @param expected expected long value.
|
||||
* @param actual actual long value
|
||||
*/
|
||||
fun assertEquals(expected: Int, actual: Int) {
|
||||
Assert.assertEquals(null, expected.toLong(), actual.toLong())
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two longs are equal. If they are not, an [AssertionError] is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the [AssertionError] (`null` okay)
|
||||
* @param expected long expected value.
|
||||
* @param actual long actual value
|
||||
*/
|
||||
fun assertEquals(message: String?, expected: Long, actual: Long) {
|
||||
assertEquals(message, expected as Long?, actual as Long?)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object isn't null. If it is an [AssertionError] is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the [AssertionError]
|
||||
* @param obj Object to check or `null`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun assertNotNull(message: String?, obj: Any?) {
|
||||
assertTrue(message, obj != null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object isn't null. If it is an [AssertionError] is thrown.
|
||||
*
|
||||
* @param obj Object to check or `null`
|
||||
*/
|
||||
fun assertNotNull(obj: Any?) {
|
||||
assertNotNull(null, obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object is null. If it isn't an [AssertionError] is thrown.
|
||||
*
|
||||
* @param obj Object to check or `null`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun assertNull(obj: Any?) {
|
||||
assertTrue(null, obj == null)
|
||||
}
|
||||
|
||||
private fun failNotEquals(message: String?, expected: Any?, actual: Any?) {
|
||||
fail(format(message, expected, actual))
|
||||
}
|
||||
|
||||
internal fun format(message: String?, expected: Any?, actual: Any?): String {
|
||||
var formatted = ""
|
||||
if (message != null && message != "") {
|
||||
formatted = "$message "
|
||||
}
|
||||
val expectedString = expected.toString()
|
||||
val actualString = actual.toString()
|
||||
return if (expectedString == actualString) {
|
||||
formatted + "expected: " + formatClassAndValue(expected, expectedString) +
|
||||
" but was: " + formatClassAndValue(actual, actualString)
|
||||
} else {
|
||||
formatted + "expected:<" + expectedString + "> but was:<" + actualString + ">"
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatClassAndValue(value: Any?, valueString: String?): String {
|
||||
val className = if (value == null) "null" else value.javaClass.name
|
||||
return "$className<$valueString>"
|
||||
}
|
||||
|
||||
private fun performFail(assertionError: java.lang.AssertionError) {
|
||||
if (!isEnabled) {
|
||||
return
|
||||
}
|
||||
_assertionErrorHandler.handleError(assertionError)
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.yandex.div.internal
|
||||
|
||||
/**
|
||||
* Kotlin wrapper for [Assert] using inline [Assert.isEnabled] checks.
|
||||
*/
|
||||
object KAssert {
|
||||
|
||||
/**
|
||||
* @see [Assert.fail]
|
||||
*/
|
||||
inline fun fail(message: () -> String) {
|
||||
if (Assert.isEnabled) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.fail]
|
||||
*/
|
||||
inline fun fail(cause: Throwable?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled) {
|
||||
Assert.fail(message(), cause)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertEquals]
|
||||
*/
|
||||
inline fun assertEquals(expected: Any?, actual: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled) {
|
||||
Assert.assertEquals(message(), expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
package com.yandex.div.internal;
|
||||
|
||||
import android.os.Looper;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.yandex.div.assertion.BuildConfig;
|
||||
|
||||
/**
|
||||
* Contains methods to make assertions that help capture programming errors. Should be disabled in the production environment.
|
||||
* Disabled by default.
|
||||
*/
|
||||
public class Assert {
|
||||
|
||||
@NonNull
|
||||
private static AssertionErrorHandler sAssertionErrorHandler = assertionError -> {
|
||||
throw assertionError;
|
||||
};
|
||||
|
||||
private static volatile boolean sEnabled = false;
|
||||
|
||||
private Assert() {
|
||||
// prevent instantiation
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value indicating if assertions are enabled. This class won't throw any {@link AssertionError}, if disabled.
|
||||
*/
|
||||
public static boolean isEnabled() {
|
||||
if (BuildConfig.DISABLE_ASSERTS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sEnabled;
|
||||
}
|
||||
|
||||
public static void setEnabled(boolean enabled) {
|
||||
sEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true. If it isn't it throws an {@link AssertionError} with the given message.
|
||||
*/
|
||||
public static void assertTrue(@Nullable String message, boolean condition) {
|
||||
if (!condition) {
|
||||
fail(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is true. If it isn't it throws an {@link AssertionError} without a message.
|
||||
*/
|
||||
public static void assertTrue(boolean condition) {
|
||||
assertTrue(null, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is false. If it isn't it throws an {@link AssertionError} with the given message.
|
||||
*/
|
||||
public static void assertFalse(@Nullable String message, boolean condition) {
|
||||
assertTrue(message, !condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a condition is false. If it isn't it throws an {@link AssertionError} without a message.
|
||||
*/
|
||||
public static void assertFalse(boolean condition) {
|
||||
assertFalse(null, condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails with no message.
|
||||
*/
|
||||
public static void fail() {
|
||||
fail(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails with the given message.
|
||||
*/
|
||||
public static void fail(@Nullable String message) {
|
||||
if (BuildConfig.DISABLE_ASSERTS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sEnabled) {
|
||||
performFail(new AssertionError(message == null ? "" : message));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fails with the given message and throwable that caused the failure..
|
||||
*/
|
||||
public static void fail(@Nullable String message, @Nullable Throwable cause) {
|
||||
if (BuildConfig.DISABLE_ASSERTS) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sEnabled) {
|
||||
AssertionError assertionError = new AssertionError(message);
|
||||
assertionError.initCause(cause);
|
||||
performFail(assertionError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom {@link AssertionErrorHandler} to override on fail behavior
|
||||
*/
|
||||
public static void setAssertPerformer(@NonNull AssertionErrorHandler assertionErrorHandler) {
|
||||
sAssertionErrorHandler = assertionErrorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects are equal. If they are not, an {@link AssertionError} without a message is thrown.
|
||||
* If <code>expected</code> and <code>actual</code> are <code>null</code>, they are considered equal.
|
||||
*
|
||||
* @param expected expected value
|
||||
* @param actual the value to check against <code>expected</code>
|
||||
*/
|
||||
public static void assertEquals(@Nullable Object expected, @Nullable Object actual) {
|
||||
assertEquals(null, expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects are equal. If they are not, an {@link AssertionError} is thrown with the given message.
|
||||
* If <code>expected</code> and <code>actual</code> are <code>null</code>, they are considered equal.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError} (<code>null</code> okay)
|
||||
* @param expected expected value
|
||||
* @param actual actual value
|
||||
*/
|
||||
public static void assertEquals(@Nullable String message, @Nullable Object expected, @Nullable Object actual) {
|
||||
if (expected == null && actual == null) {
|
||||
return;
|
||||
}
|
||||
if (expected != null && expected.equals(actual)) {
|
||||
return;
|
||||
}
|
||||
if (expected instanceof String && actual instanceof String) {
|
||||
String cleanMessage = message == null ? "" : message;
|
||||
performFail(new ComparisonFailure(cleanMessage, (String) expected, (String) actual));
|
||||
} else {
|
||||
failNotEquals(message, expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two longs are equal. If they are not, an {@link AssertionError} is thrown.
|
||||
*
|
||||
* @param expected expected long value.
|
||||
* @param actual actual long value
|
||||
*/
|
||||
public static void assertEquals(long expected, long actual) {
|
||||
assertEquals(null, expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two ints are equal. If they are not, an {@link AssertionError} is thrown.
|
||||
*
|
||||
* @param expected expected long value.
|
||||
* @param actual actual long value
|
||||
*/
|
||||
public static void assertEquals(int expected, int actual) {
|
||||
assertEquals(null, expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two longs are equal. If they are not, an {@link AssertionError} is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError} (<code>null</code> okay)
|
||||
* @param expected long expected value.
|
||||
* @param actual long actual value
|
||||
*/
|
||||
public static void assertEquals(@Nullable String message, long expected, long actual) {
|
||||
assertEquals(message, (Long) expected, (Long) actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object isn't null. If it is an {@link AssertionError} is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError}
|
||||
* @param object Object to check or <code>null</code>
|
||||
*/
|
||||
public static void assertNotNull(@Nullable String message, @Nullable Object object) {
|
||||
assertTrue(message, object != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object isn't null. If it is an {@link AssertionError} is thrown.
|
||||
*
|
||||
* @param object Object to check or <code>null</code>
|
||||
*/
|
||||
public static void assertNotNull(@Nullable Object object) {
|
||||
assertNotNull(null, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object is null. If it is not, an {@link AssertionError} is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError}
|
||||
* @param object Object to check or <code>null</code>
|
||||
*/
|
||||
public static void assertNull(@Nullable String message, @Nullable Object object) {
|
||||
assertTrue(message, object == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that an object is null. If it isn't an {@link AssertionError} is thrown.
|
||||
*
|
||||
* @param object Object to check or <code>null</code>
|
||||
*/
|
||||
public static void assertNull(@Nullable Object object) {
|
||||
assertNull(null, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects refer to the same object. If they are not, an {@link AssertionError} is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError}
|
||||
* @param expected the expected object
|
||||
* @param actual the object to compare to <code>expected</code>
|
||||
*/
|
||||
public static void assertSame(@Nullable String message, @Nullable Object expected, @Nullable Object actual) {
|
||||
if (expected == actual) {
|
||||
return;
|
||||
}
|
||||
failNotSame(message, expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects refer to the same object. If they are not the same, an {@link AssertionError} without a message is thrown.
|
||||
*
|
||||
* @param expected the expected object
|
||||
* @param actual the object to compare to <code>expected</code>
|
||||
*/
|
||||
public static void assertSame(@Nullable Object expected, @Nullable Object actual) {
|
||||
assertSame(null, expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects do not refer to the same object. If they do refer to the same object,
|
||||
* an {@link AssertionError} is thrown with the given message.
|
||||
*
|
||||
* @param message the identifying message for the {@link AssertionError}
|
||||
* @param unexpected the object you don't expect
|
||||
* @param actual the object to compare to <code>unexpected</code>
|
||||
*/
|
||||
public static void assertNotSame(@Nullable String message, @Nullable Object unexpected, @Nullable Object actual) {
|
||||
if (unexpected == actual) {
|
||||
failSame(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two objects do not refer to the same object. If they do refer to the same object,
|
||||
* an {@link AssertionError} without a message is thrown.
|
||||
*
|
||||
* @param unexpected the object you don't expect
|
||||
* @param actual the object to compare to <code>unexpected</code>
|
||||
*/
|
||||
public static void assertNotSame(@Nullable Object unexpected, @Nullable Object actual) {
|
||||
assertNotSame(null, unexpected, actual);
|
||||
}
|
||||
|
||||
public static void assertMainThread() {
|
||||
if (!isEnabled()) return;
|
||||
assertSame("Code run not in main thread!", Looper.getMainLooper(), Looper.myLooper());
|
||||
}
|
||||
|
||||
public static void assertNotMainThread() {
|
||||
if (!isEnabled()) return;
|
||||
assertNotSame("Code run in main thread!", Looper.getMainLooper(), Looper.myLooper());
|
||||
}
|
||||
|
||||
private static void failSame(@Nullable String message) {
|
||||
String formatted = "";
|
||||
if (message != null) {
|
||||
formatted = message + " ";
|
||||
}
|
||||
fail(formatted + "expected not same");
|
||||
}
|
||||
|
||||
private static void failNotSame(@Nullable String message, @Nullable Object expected, @Nullable Object actual) {
|
||||
String formatted = "";
|
||||
if (message != null) {
|
||||
formatted = message + " ";
|
||||
}
|
||||
fail(formatted + "expected same:<" + expected + "> was not:<" + actual + ">");
|
||||
}
|
||||
|
||||
private static void failNotEquals(@Nullable String message, @Nullable Object expected, @Nullable Object actual) {
|
||||
fail(format(message, expected, actual));
|
||||
}
|
||||
|
||||
static String format(@Nullable String message, @Nullable Object expected, @Nullable Object actual) {
|
||||
String formatted = "";
|
||||
if (message != null && !message.equals("")) {
|
||||
formatted = message + " ";
|
||||
}
|
||||
String expectedString = String.valueOf(expected);
|
||||
String actualString = String.valueOf(actual);
|
||||
if (expectedString.equals(actualString)) {
|
||||
return formatted + "expected: "
|
||||
+ formatClassAndValue(expected, expectedString)
|
||||
+ " but was: " + formatClassAndValue(actual, actualString);
|
||||
} else {
|
||||
return formatted + "expected:<" + expectedString + "> but was:<" + actualString + ">";
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatClassAndValue(@Nullable Object value, @Nullable String valueString) {
|
||||
String className = value == null ? "null" : value.getClass().getName();
|
||||
return className + "<" + valueString + ">";
|
||||
}
|
||||
|
||||
private static void performFail(@NonNull AssertionError assertionError) {
|
||||
if (!isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sAssertionErrorHandler.handleError(assertionError);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -7,7 +7,7 @@ import kotlin.math.min
|
||||
* Thrown when an [Assert.assertEquals] fails.
|
||||
*/
|
||||
internal class ComparisonFailure(
|
||||
message: String,
|
||||
message: String?,
|
||||
val expected: String,
|
||||
val actual: String
|
||||
) : AssertionError(message) {
|
||||
@@ -16,7 +16,7 @@ internal class ComparisonFailure(
|
||||
* Returns "..." in place of common prefix and "..." in
|
||||
* place of common suffix between expected and actual.
|
||||
*
|
||||
* @see Throwable.message
|
||||
* @see Throwable.getMessage
|
||||
*/
|
||||
override val message: String
|
||||
get() = ComparisonCompactor(MAX_CONTEXT_LENGTH, expected, actual).compact(super.message)
|
||||
@@ -0,0 +1,126 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
package com.yandex.div.internal
|
||||
|
||||
/**
|
||||
* Kotlin wrapper for [Assert] using inline [Assert.isEnabled] checks.
|
||||
*/
|
||||
object KAssert {
|
||||
|
||||
/**
|
||||
* @see [Assert.fail]
|
||||
*/
|
||||
inline fun fail(message: () -> String) {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.fail]
|
||||
*/
|
||||
inline fun fail(cause: Throwable?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.fail(message(), cause)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertTrue]
|
||||
*/
|
||||
inline fun assertTrue(condition: Boolean, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && !condition) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertFalse]
|
||||
*/
|
||||
inline fun assertFalse(condition: Boolean, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && condition) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertTrue]
|
||||
*/
|
||||
inline fun assertTrue(condition: () -> Boolean, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && !condition()) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertFalse]
|
||||
*/
|
||||
inline fun assertFalse(condition: () -> Boolean, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && condition()) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertEquals]
|
||||
*/
|
||||
inline fun assertEquals(expected: Any?, actual: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.assertEquals(message(), expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertNotNull]
|
||||
*/
|
||||
inline fun assertNotNull(nullable: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && nullable == null) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertNull]
|
||||
*/
|
||||
inline fun assertNull(nullable: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled() && nullable != null) {
|
||||
Assert.fail(message())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertSame]
|
||||
*/
|
||||
inline fun assertSame(expected: Any?, actual: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.assertSame(message(), expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertNotSame]
|
||||
*/
|
||||
inline fun assertNotSame(expected: Any?, actual: Any?, message: () -> String = { "" }) {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.assertNotSame(message(), expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertMainThread]
|
||||
*/
|
||||
inline fun assertMainThread() {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.assertMainThread()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see [Assert.assertNotMainThread]
|
||||
*/
|
||||
inline fun assertNotMainThread() {
|
||||
if (Assert.isEnabled()) {
|
||||
Assert.assertNotMainThread()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,15 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
apply from: "$projectDir/version.gradle"
|
||||
|
||||
ext {
|
||||
minSdkVersion = 21
|
||||
compileSdkVersion = 35
|
||||
targetSdkVersion = 35
|
||||
buildToolsVersion = "35.0.0"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
FileExtensions.ifExists("${project.projectDir}/bootstrap.internal.gradle") {
|
||||
apply from: it
|
||||
@@ -28,23 +37,9 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.kotlin.multiplatform.library) apply false
|
||||
alias(libs.plugins.kotlin.multiplatform) apply false
|
||||
}
|
||||
|
||||
apply plugin: "org.jetbrains.kotlinx.binary-compatibility-validator"
|
||||
apply plugin: "com.asarkar.gradle.build-time-tracker"
|
||||
|
||||
apply from: "$projectDir/version.gradle"
|
||||
|
||||
ext {
|
||||
minSdkVersion = 21
|
||||
compileSdkVersion = 35
|
||||
targetSdkVersion = 35
|
||||
buildToolsVersion = "35.0.0"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
|
||||
@@ -6,6 +6,6 @@ import com.yandex.div.internal.Assert
|
||||
class TestApplication : Application() {
|
||||
|
||||
init {
|
||||
Assert.isEnabled = true
|
||||
Assert.setEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import androidx.annotation.AnyThread
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.core.database.getBlobOrNull
|
||||
import com.yandex.div.core.annotations.Mockable
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.KAssert
|
||||
import com.yandex.div.storage.DivDataRepository.ActionOnError
|
||||
import com.yandex.div.storage.DivStorage.LoadDataResult
|
||||
@@ -99,7 +98,7 @@ internal class DivStorageImpl(
|
||||
|
||||
@VisibleForTesting
|
||||
fun onUpgrade(db: DatabaseOpenHelper.Database, oldVersion: Int, newVersion: Int) {
|
||||
Assert.assertEquals(newVersion, DB_VERSION)
|
||||
KAssert.assertEquals(newVersion, DB_VERSION)
|
||||
if (oldVersion == DB_VERSION) return
|
||||
|
||||
val migration = migrations[oldVersion to newVersion] ?: defaultDropAllMigration
|
||||
|
||||
@@ -86,32 +86,33 @@ class DivKit private constructor(
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun isLoggingEnabled(): Boolean = Log.isEnabled
|
||||
fun isLoggingEnabled(): Boolean = Log.isEnabled()
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun enableLogging(enabled: Boolean) {
|
||||
Log.isEnabled = enabled
|
||||
Log.setEnabled(enabled)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun getLoggingSeverity(): Severity = Log.severity
|
||||
fun getLoggingSeverity(): Severity = Log.getSeverity()
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun setLoggingSeverity(severity: Severity) {
|
||||
Log.severity = severity
|
||||
Log.setSeverity(severity)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun isAssertionsEnabled(): Boolean = Assert.isEnabled
|
||||
fun isAssertionsEnabled(): Boolean = Assert.isEnabled()
|
||||
|
||||
@JvmStatic
|
||||
@AnyThread
|
||||
fun enableAssertions(enabled: Boolean) {
|
||||
Assert.isEnabled = enabled
|
||||
Assert.setEnabled(enabled)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ internal class BindingEventReporterProvider(
|
||||
private val div2View: Div2View,
|
||||
) {
|
||||
fun get(oldData: DivData?, newData: DivData?): BindingEventReporter {
|
||||
return if (Log.isEnabled) {
|
||||
return if (Log.isEnabled()) {
|
||||
BindingEventReporterImpl(div2View, oldData, newData)
|
||||
} else {
|
||||
BindingEventReporter.STUB
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ internal class PatchEventReporterProvider(
|
||||
private val div2View: Div2View,
|
||||
) {
|
||||
fun get(patch: DivPatch): PatchEventReporter {
|
||||
return if (Log.isEnabled) {
|
||||
return if (Log.isEnabled()) {
|
||||
PatchEventReporterImpl(div2View, patch)
|
||||
} else {
|
||||
PatchEventReporter.STUB
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import com.yandex.div.core.util.getIndices
|
||||
import com.yandex.div.core.util.isLayoutRtl
|
||||
import com.yandex.div.core.widget.AspectView.Companion.DEFAULT_ASPECT_RATIO
|
||||
import com.yandex.div.core.widget.AspectView.Companion.aspectRatioProperty
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.KAssert
|
||||
import com.yandex.div.internal.widget.DivLayoutParams
|
||||
import com.yandex.div.internal.widget.DivLayoutParams.Companion.DEFAULT_MAX_SIZE
|
||||
import com.yandex.div.internal.widget.DivLayoutParams.Companion.WRAP_CONTENT_CONSTRAINED
|
||||
@@ -570,7 +570,7 @@ internal open class LinearContainerLayout @JvmOverloads constructor(
|
||||
}
|
||||
maxCrossSize = max(initialMaxWidth, maxCrossSize + horizontalPaddings)
|
||||
|
||||
Assert.assertEquals("Width of vertical container changed after remeasuring", oldMaxWidth, maxCrossSize)
|
||||
KAssert.assertEquals(oldMaxWidth, maxCrossSize) { "Width of vertical container changed after remeasuring" }
|
||||
}
|
||||
|
||||
private fun getFreeSpace(delta: Int, spec: Int) = when {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ object ViewPreCreationProfileOptimizer {
|
||||
): ViewPreCreationProfile = withContext(Dispatchers.Default) {
|
||||
val newProfile = profile.optimize(session.viewObtainmentStatistics, convergenceRate)
|
||||
|
||||
if (Log.isEnabled) {
|
||||
if (Log.isEnabled()) {
|
||||
session.log(oldProfile = profile, newProfile = newProfile)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,30 @@ import com.yandex.div.core.view2.Div2View
|
||||
import com.yandex.div.core.view2.DivBinder
|
||||
import com.yandex.div.core.view2.divs.widgets.ReleaseViewVisitor
|
||||
import com.yandex.div.core.view2.state.DivStateSwitcher
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.util.textString
|
||||
import com.yandex.div.json.expressions.Expression
|
||||
import org.junit.Assert
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
|
||||
internal fun runAsync(action: () -> Unit) {
|
||||
val executor = Executors.newSingleThreadExecutor()
|
||||
var error: Throwable? = null
|
||||
executor.execute {
|
||||
try {
|
||||
action.invoke()
|
||||
} catch (e: Throwable) {
|
||||
error = e
|
||||
}
|
||||
}
|
||||
|
||||
executor.shutdown()
|
||||
val finished = executor.awaitTermination(10, TimeUnit.SECONDS)
|
||||
if (!finished) throw TimeoutException("Test execution takes more than 10 seconds.")
|
||||
|
||||
error?.let { throw it }
|
||||
}
|
||||
|
||||
internal fun View.viewEquals(other: View): Boolean {
|
||||
if (this::class.java != other::class.java) return false
|
||||
|
||||
@@ -6,6 +6,6 @@ import com.yandex.div.internal.Assert
|
||||
class TestApplication : Application() {
|
||||
|
||||
init {
|
||||
Assert.isEnabled = true
|
||||
Assert.setEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -3,12 +3,12 @@ package com.yandex.div.core.expression.local
|
||||
import com.yandex.div.core.expression.ExpressionResolverImpl
|
||||
import com.yandex.div.core.expression.ExpressionsRuntime
|
||||
import com.yandex.div.core.state.DivStatePath
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.json.expressions.Expression
|
||||
import com.yandex.div2.Div
|
||||
import com.yandex.div2.DivBase
|
||||
import com.yandex.div2.DivVariable
|
||||
import com.yandex.div2.IntegerVariable
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
@@ -82,6 +82,7 @@ class RuntimeStoreImplTest {
|
||||
val runtime = underTest.getOrCreateRuntime(path, div, mock<ExpressionResolverImpl>())
|
||||
|
||||
Assert.assertEquals(rootRuntime, runtime)
|
||||
Assert.assertNotNull(underTest.getRuntimeWithOrNull(resolver))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package com.yandex.div.core.resources
|
||||
|
||||
import android.content.res.Resources
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
+1
-1
@@ -19,13 +19,13 @@ import com.yandex.div.core.view2.Div2View
|
||||
import com.yandex.div.core.view2.DivVisibilityActionTracker
|
||||
import com.yandex.div.core.view2.errors.ErrorCollector
|
||||
import com.yandex.div.core.view2.errors.ErrorCollectors
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.json.expressions.ExpressionResolver
|
||||
import com.yandex.div2.Div
|
||||
import com.yandex.div2.DivPoint
|
||||
import com.yandex.div2.DivText
|
||||
import com.yandex.div2.DivTooltip
|
||||
import com.yandex.div2.DivVisibilityAction
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.yandex.div.core.util
|
||||
|
||||
import com.yandex.div.core.view2.PATCH_DIR
|
||||
import com.yandex.div.core.view2.divs.UnitTestData
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@@ -6,11 +6,11 @@ import com.yandex.div.core.Div2Context
|
||||
import com.yandex.div.core.DivConfiguration
|
||||
import com.yandex.div.core.images.DivImageLoader
|
||||
import com.yandex.div.data.DivParsingEnvironment
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div2.Div
|
||||
import com.yandex.div2.DivData
|
||||
import com.yandex.div2.DivPatch
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
@@ -23,7 +23,7 @@ class DivPatchApplyItemsTest {
|
||||
private val controller = Robolectric.buildActivity(Activity::class.java)
|
||||
private val activity = controller.get()
|
||||
private val env = DivParsingEnvironment(
|
||||
logger = { Assert.fail("Parsing error: $it") }
|
||||
logger = { Assert.fail("Unepected parsing error!", it) }
|
||||
)
|
||||
|
||||
private val div2Context = Div2Context(
|
||||
@@ -58,7 +58,9 @@ class DivPatchApplyItemsTest {
|
||||
val initialData = DivData(env, JSONObject(createInitialDataWith(containerType)))
|
||||
div2View.setData(initialData, tag)
|
||||
Assert.assertNull(div2View.rootDivContainerItems())
|
||||
|
||||
Assert.assertTrue(div2View.applyPatch(DivPatch(env, JSONObject(DIV_PATCH))))
|
||||
|
||||
Assert.assertNull(div2View.rootDivContainerItems())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import org.junit.runners.model.Statement
|
||||
class EnableAssertsRule(val enable: Boolean = true) : TestRule {
|
||||
override fun apply(base: Statement?, description: Description?) = object : Statement() {
|
||||
override fun evaluate() {
|
||||
val savedValue = Assert.isEnabled
|
||||
Assert.isEnabled = enable
|
||||
val savedValue = Assert.isEnabled()
|
||||
Assert.setEnabled(enable)
|
||||
|
||||
try {
|
||||
base?.evaluate()
|
||||
} finally {
|
||||
Assert.isEnabled = savedValue
|
||||
Assert.setEnabled(savedValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.yandex.div.core.DivConfiguration
|
||||
import com.yandex.div.core.images.DivImageLoader
|
||||
import com.yandex.div.core.view2.divs.UnitTestData
|
||||
import com.yandex.div.core.viewEquals
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
|
||||
@@ -12,8 +12,8 @@ import com.yandex.div.core.view2.divs.CONTAINER_DIR
|
||||
import com.yandex.div.core.view2.divs.UnitTestData
|
||||
import com.yandex.div.core.view2.divs.widgets.DivStateLayout
|
||||
import com.yandex.div.core.viewEquals
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div2.DivData
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertNull
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ import com.yandex.div.core.state.DivStatePath
|
||||
import com.yandex.div.core.view2.animations.DIV_STATE_DIR
|
||||
import com.yandex.div.core.view2.divs.UnitTestData
|
||||
import com.yandex.div.core.view2.divs.widgets.ReleaseViewVisitor
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.any
|
||||
|
||||
@@ -3,10 +3,10 @@ package com.yandex.div.core.view2
|
||||
import com.yandex.div.internal.Assert
|
||||
|
||||
inline fun disableAssertions(crossinline block: () -> Unit) {
|
||||
Assert.isEnabled = false
|
||||
Assert.setEnabled(false)
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
Assert.isEnabled = true
|
||||
Assert.setEnabled(true)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,11 +8,11 @@ import com.yandex.div.core.view2.Div2View
|
||||
import com.yandex.div.core.view2.errors.ErrorCollectors
|
||||
import com.yandex.div.data.Variable
|
||||
import com.yandex.div.data.VariableMutationException
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.core.VariableMutationHandler
|
||||
import com.yandex.div.json.expressions.ExpressionResolver
|
||||
import com.yandex.div2.DivData
|
||||
import com.yandex.div2.DivLayoutProvider
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.any
|
||||
|
||||
+1
-1
@@ -13,10 +13,10 @@ import com.yandex.div.core.view2.DivBinder
|
||||
import com.yandex.div.core.view2.DivVisibilityActionTracker
|
||||
import com.yandex.div.core.view2.divs.widgets.DivStateLayout
|
||||
import com.yandex.div.core.view2.errors.ErrorCollectors
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.json.expressions.ExpressionResolver
|
||||
import com.yandex.div.state.InMemoryDivStateCache
|
||||
import com.yandex.div2.Div
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.any
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import android.os.Looper.getMainLooper
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.test.core.view.MotionEventBuilder
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
|
||||
+2
-2
@@ -37,14 +37,14 @@ class DivItemChangeActionHandlerTest {
|
||||
|
||||
@Before
|
||||
fun `setup mock`() {
|
||||
DivKitAssert.isEnabled = false
|
||||
DivKitAssert.setEnabled(false)
|
||||
DivViewWithItems.viewForTests = divItemsView
|
||||
}
|
||||
|
||||
@After
|
||||
fun `cleanup mock`() {
|
||||
DivViewWithItems.viewForTests = null
|
||||
DivKitAssert.isEnabled = true
|
||||
DivKitAssert.setEnabled(true)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.yandex.div.core.view2.disableAssertions
|
||||
import com.yandex.div.core.view2.divs.widgets.DivPagerView
|
||||
import org.junit.Assert
|
||||
import com.yandex.div.internal.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.*
|
||||
|
||||
+1
-1
@@ -3,8 +3,8 @@ package com.yandex.div.core.view2.items
|
||||
import androidx.viewpager.widget.PagerAdapter
|
||||
import com.yandex.div.core.view2.disableAssertions
|
||||
import com.yandex.div.core.view2.divs.widgets.DivTabsLayout
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.widget.tabs.ScrollableViewPager
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
|
||||
+1
-2
@@ -9,12 +9,12 @@ import com.yandex.div.core.DivConfiguration
|
||||
import com.yandex.div.core.view2.Div2View
|
||||
import com.yandex.div.core.view2.divs.widgets.DivLinearLayout
|
||||
import com.yandex.div.data.DivParsingEnvironment
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.util.textString
|
||||
import com.yandex.div.json.expressions.Expression
|
||||
import com.yandex.div2.DivAction
|
||||
import com.yandex.div2.DivData
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
@@ -137,7 +137,6 @@ class LocalTriggersTest {
|
||||
Assert.assertEquals(expected, view.textString)
|
||||
}
|
||||
}
|
||||
|
||||
private val testJsonWithTwoStates = """
|
||||
{
|
||||
"log_id": "sample_card",
|
||||
|
||||
+1
-2
@@ -12,6 +12,7 @@ import com.yandex.div.core.view2.Div2View
|
||||
import com.yandex.div.core.view2.divs.widgets.DivLinearLayout
|
||||
import com.yandex.div.core.view2.divs.widgets.DivStateLayout
|
||||
import com.yandex.div.data.DivParsingEnvironment
|
||||
import com.yandex.div.internal.Assert
|
||||
import com.yandex.div.internal.util.textString
|
||||
import com.yandex.div.json.expressions.Expression
|
||||
import com.yandex.div2.Div
|
||||
@@ -19,7 +20,6 @@ import com.yandex.div2.DivAction
|
||||
import com.yandex.div2.DivBase
|
||||
import com.yandex.div2.DivData
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.doReturn
|
||||
@@ -136,7 +136,6 @@ class LocalVariablesTest {
|
||||
Assert.assertEquals(expected, view.textString)
|
||||
}
|
||||
}
|
||||
|
||||
private val testJsonWithTwoStates = """
|
||||
{
|
||||
"log_id": "local_variables",
|
||||
|
||||
+1
-1
@@ -1,9 +1,9 @@
|
||||
package com.yandex.div.internal.widget.indicator
|
||||
|
||||
import com.yandex.div.core.view2.divs.DivIndicatorBinder.Companion.createRoundedRectangle
|
||||
import com.yandex.div.internal.KAssert.assertEquals
|
||||
import com.yandex.div.internal.widget.indicator.animations.ScaleIndicatorAnimator
|
||||
import com.yandex.div.internal.widget.indicator.forms.RoundedRect
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.mock
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ class LogCountSteps(
|
||||
}
|
||||
|
||||
init {
|
||||
KLog.addListener(logListener)
|
||||
KLog.listeners.add(logListener)
|
||||
}
|
||||
|
||||
fun assert(f: LogCountAssertions.() -> Unit) = f(LogCountAssertions(logCount, logListener))
|
||||
@@ -38,13 +38,13 @@ class LogCountAssertions(
|
||||
) {
|
||||
|
||||
fun logCountLessOrEquals(max: Int) {
|
||||
KLog.removeListener(logListener)
|
||||
KLog.listeners.remove(logListener)
|
||||
|
||||
assert(logCount <= max) { "$MESSAGE_TOO_MANY_FAILS: $logCount" }
|
||||
}
|
||||
|
||||
fun logCountEquals(expected: Int) {
|
||||
KLog.removeListener(logListener)
|
||||
KLog.listeners.remove(logListener)
|
||||
|
||||
assert(logCount == expected) { "$MESSAGE_TOO_MANY_FAILS: $logCount" }
|
||||
}
|
||||
|
||||
@@ -193,10 +193,7 @@ zxing-embedded = { module = "com.journeyapps:zxing-android-embedded", version =
|
||||
|
||||
[plugins]
|
||||
apiGenerator = { id = "com.yandex.divkit.api-generator", version = "unspecified" }
|
||||
android-kotlin-multiplatform-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
|
||||
buildkonfig = { id = "com.codingfeline.buildkonfig", version = "0.17.1" }
|
||||
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
kotlin-ksp = { id = "com.google.devtools.ksp", version.ref = "kotlin-ksp" }
|
||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
screenshotTestPlugin = { id = "com.yandex.test.screenshot-test-plugin", version = "unspecified" }
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
apply plugin: "com.android.kotlin.multiplatform.library"
|
||||
apply plugin: "org.jetbrains.kotlin.multiplatform"
|
||||
|
||||
version = divkitVersion.baseVersionName
|
||||
|
||||
kotlin {
|
||||
androidLibrary {
|
||||
compileSdk = rootProject.ext.compileSdkVersion
|
||||
minSdk = rootProject.ext.minSdkVersion
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
lintChecks project(path: ':lint-rules')
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
apply from: "${project.projectDir}/../div-library.gradle"
|
||||
apply from: "${project.projectDir}/../div-tests.gradle"
|
||||
apply from: "${project.projectDir}/../publish-android.gradle"
|
||||
|
||||
android {
|
||||
namespace 'com.yandex.div.logging'
|
||||
|
||||
buildFeatures { buildConfig = true }
|
||||
|
||||
defaultConfig {
|
||||
buildConfigField "boolean", "DISABLE_LOGS", "${project.property("disableLogsInBuild").toBoolean()}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.androidx.core
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN
|
||||
import java.lang.Boolean.parseBoolean
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.kotlin.multiplatform.library)
|
||||
alias(libs.plugins.buildkonfig)
|
||||
alias(libs.plugins.kotlin.multiplatform)
|
||||
}
|
||||
|
||||
apply(from = "../kmp-library.gradle")
|
||||
apply(from = "../publish-kmp.gradle")
|
||||
|
||||
kotlin {
|
||||
androidLibrary {
|
||||
namespace = "com.yandex.div.logging"
|
||||
}
|
||||
}
|
||||
|
||||
buildkonfig {
|
||||
packageName = "com.yandex.div.logging"
|
||||
|
||||
defaultConfigs {
|
||||
buildConfigField(BOOLEAN, "DISABLE_LOGS", "${providers.gradleProperty("disableLogsInBuild").map(::parseBoolean).get()}")
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.yandex.div.internal;
|
||||
|
||||
import com.yandex.div.logging.BuildKonfig
|
||||
import com.yandex.div.logging.Severity
|
||||
|
||||
object Log {
|
||||
|
||||
@Volatile
|
||||
private var _isEnabled = false
|
||||
|
||||
@Volatile
|
||||
private var _severity = Severity.VERBOSE
|
||||
|
||||
@JvmStatic
|
||||
var isEnabled: Boolean
|
||||
get() {
|
||||
if (BuildKonfig.DISABLE_LOGS) {
|
||||
return false
|
||||
}
|
||||
return _isEnabled
|
||||
}
|
||||
set(value) {
|
||||
_isEnabled = value
|
||||
}
|
||||
|
||||
var severity: Severity
|
||||
get() = _severity
|
||||
set(value) {
|
||||
_severity = value
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun d(tag: String, message: String) {
|
||||
if (isAtLeast(Severity.DEBUG)) {
|
||||
android.util.Log.d(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
fun w(tag: String, message: String) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
fun w(tag: String, th: Throwable) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, th);
|
||||
}
|
||||
}
|
||||
|
||||
fun w(tag: String, message: String, th: Throwable) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
fun i(tag: String, message: String) {
|
||||
if (isAtLeast(Severity.INFO)) {
|
||||
android.util.Log.i(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun e(tag: String, message: String) {
|
||||
if (isAtLeast(Severity.ERROR)) {
|
||||
android.util.Log.e(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun e(tag: String, message: String, th: Throwable) {
|
||||
if (isAtLeast(Severity.ERROR)) {
|
||||
android.util.Log.e(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
internal fun isAtLeast(minLevel: Severity): Boolean {
|
||||
if (!isEnabled) {
|
||||
return false
|
||||
}
|
||||
return _severity.isAtLeast(minLevel)
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -7,7 +7,19 @@ import com.yandex.div.logging.Severity
|
||||
*/
|
||||
object KLog {
|
||||
|
||||
private val listeners = mutableListOf<LogListener>()
|
||||
val listeners = mutableListOf<LogListener>()
|
||||
|
||||
inline fun v(tag: String, message: () -> String) {
|
||||
if (isAtLeast(Severity.VERBOSE)) {
|
||||
print(android.util.Log.VERBOSE, tag, message())
|
||||
}
|
||||
}
|
||||
|
||||
inline fun v(tag: String, th: Throwable, message: () -> String) {
|
||||
if (isAtLeast(Severity.VERBOSE)) {
|
||||
android.util.Log.v(tag, message(), th)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun d(tag: String, message: () -> String) {
|
||||
if (isAtLeast(Severity.DEBUG)) {
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.yandex.div.internal;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.yandex.div.logging.BuildConfig;
|
||||
import com.yandex.div.logging.Severity;
|
||||
|
||||
public class Log {
|
||||
|
||||
private static volatile boolean sEnabled = false;
|
||||
private static volatile Severity sSeverity = Severity.VERBOSE;
|
||||
|
||||
private Log() {
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
if (BuildConfig.DISABLE_LOGS) {
|
||||
return false;
|
||||
}
|
||||
return sEnabled;
|
||||
}
|
||||
|
||||
public static void setEnabled(Boolean enabled) {
|
||||
sEnabled = enabled;
|
||||
}
|
||||
|
||||
public static Severity getSeverity() {
|
||||
return sSeverity;
|
||||
}
|
||||
|
||||
public static void setSeverity(@NonNull Severity severity) {
|
||||
sSeverity = severity;
|
||||
}
|
||||
|
||||
public static void v(@NonNull String tag, @NonNull String message) {
|
||||
if (isAtLeast(Severity.VERBOSE)) {
|
||||
android.util.Log.v(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void v(@NonNull String tag, @NonNull String message, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.VERBOSE)) {
|
||||
android.util.Log.v(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(@NonNull String tag, @NonNull String message) {
|
||||
if (isAtLeast(Severity.DEBUG)) {
|
||||
android.util.Log.d(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(@NonNull String tag, @NonNull String message, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.DEBUG)) {
|
||||
android.util.Log.d(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(@NonNull String tag, @NonNull String message) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(@NonNull String tag, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, th);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(@NonNull String tag, @NonNull String message, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.WARNING)) {
|
||||
android.util.Log.w(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
public static void i(@NonNull String tag, @NonNull String message) {
|
||||
if (isAtLeast(Severity.INFO)) {
|
||||
android.util.Log.i(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void i(@NonNull String tag, @NonNull String message, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.INFO)) {
|
||||
android.util.Log.i(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
public static void e(@NonNull String tag, @NonNull String message) {
|
||||
if (isAtLeast(Severity.ERROR)) {
|
||||
android.util.Log.e(tag, message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void e(@NonNull String tag, @NonNull String message, @NonNull Throwable th) {
|
||||
if (isAtLeast(Severity.ERROR)) {
|
||||
android.util.Log.e(tag, message, th);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isAtLeast(Severity minLevel) {
|
||||
if (!isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return sSeverity.isAtLeast(minLevel);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
apply from: "${buildscript.sourceFile.parent}/publish-common.gradle"
|
||||
|
||||
afterEvaluate {
|
||||
kotlin {
|
||||
publishing {
|
||||
version = divkitVersion.releaseLibraryVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user