Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*******************************************************************************
* Copyright (c) 2016 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Evolution AG - initial API and implementation
*******************************************************************************/

package com.avaloq.tools.ddk.check.jvmmodel;

/**
* A class to avoid multi-line strings in Xtend which can be constant strings: See https://github.com/eclipse/xtext/issues/3091.
*/
public final class CheckJvmModelInferrerUtil {

private CheckJvmModelInferrerUtil() {
// empty
}

/**
* The documentation for the Get Message Method.
*/
public static final String GET_MESSAGE_DOCUMENTATION = """
Gets the message associated with a violation of this check.

@param bindings
the message bindings
@return the message associated with a violation of this check"""; //$NON-NLS-1$
}
/*******************************************************************************
* Copyright (c) 2016 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Evolution AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.check.jvmmodel;
/**
* A class to avoid multi-line strings in Xtend which can be constant strings: See https://github.com/eclipse/xtext/issues/3091.
*/
public final class CheckJvmModelInferrerUtil {
private CheckJvmModelInferrerUtil() {
// empty
}
/**
* The documentation for the Get Message Method.
*/
public static final String GET_MESSAGE_DOCUMENTATION = """
Gets the message associated with a violation of this check.
@param bindings
the message bindings
@return the message associated with a violation of this check"""; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
/*******************************************************************************
* Copyright (c) 2025 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.test.core.jupiter;

import java.lang.reflect.Method;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;

import com.avaloq.tools.ddk.test.core.BugTest;


/**
* This {@link InvocationInterceptor} implementation changes the behavior for unresolved bug tests.
* <p>
* The behavior for at test that is annotated with {@link BugTest(unresolved=true)} is the following:
* <ul>
* <li>Test evaluation <code>OK</code> results in <code>FAIL</code> ({@link AssertionError})</li>
* <li>Test evaluation <code>FAIL</code> results in <code>OK</code></li>
* <li>Test evaluation <code>ERROR</code> results in <code>ERROR</code></li>
* </ul>
* </p>
* <p>
* Example for a bug test:
*
* <pre>
* public class TestClass {
*
* &#064;Rule
* public BugTestAwareRule rule = BugTestAwareRule.getInstance();
*
* &#064;org.junit.Test
* &#064;com.avaloq.tools.ddk.test.core.BugTest(value = &quot;BUG-42&quot;, unresolved = true)
* public void testMethod() {
* org.junit.Assert.fail();
* }
* }
* </pre>
* </p>
*
* @see BugTest
*/
public final class BugTestAwareRule implements InvocationInterceptor {

private static final String ERROR_TEST_MUST_FAIL = "The unresolved bug test must fail:"; //$NON-NLS-1$
/** The singleton instance, or {@code null} if not cached. */
private static BugTestAwareRule instance;
private static final Object LOCK = new Object();

/**
* Creates a new instance of {@link BugTestAwareRule}.
*/
private BugTestAwareRule() {
// prevent instantiation
}

/**
* Returns a shared singleton instance.
*
* @return a shared instance, never {@code null}
*/
public static BugTestAwareRule getInstance() {
synchronized (LOCK) {
if (instance == null) {
instance = new BugTestAwareRule();
}
return instance;
}
}

@SuppressWarnings("nls")
@Override
public void interceptTestMethod(final Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
BugTest bugTestAnnotation = extensionContext.getRequiredTestMethod().getAnnotation(BugTest.class);
if (bugTestAnnotation == null && extensionContext.getRequiredTestClass() != null) {
bugTestAnnotation = extensionContext.getRequiredTestClass().getAnnotation(BugTest.class);
}
if (bugTestAnnotation != null && bugTestAnnotation.unresolved()) {
try {
invocation.proceed();
} catch (AssertionError exception) {
return;
}
String testCase = extensionContext.getRequiredTestClass().getSimpleName() + "." + extensionContext.getRequiredTestMethod().getName();
throw new AssertionError(ERROR_TEST_MUST_FAIL + " " + testCase);
} else {
invocation.proceed();
}
}

}
/*******************************************************************************
* Copyright (c) 2025 Avaloq Group AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
package com.avaloq.tools.ddk.test.core.jupiter;
import java.lang.reflect.Method;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import com.avaloq.tools.ddk.test.core.BugTest;
/**
* This {@link InvocationInterceptor} implementation changes the behavior for unresolved bug tests.
* <p>
* The behavior for at test that is annotated with {@link BugTest(unresolved=true)} is the following:
* <ul>
* <li>Test evaluation <code>OK</code> results in <code>FAIL</code> ({@link AssertionError})</li>
* <li>Test evaluation <code>FAIL</code> results in <code>OK</code></li>
* <li>Test evaluation <code>ERROR</code> results in <code>ERROR</code></li>
* </ul>
* </p>
* <p>
* Example for a bug test:
*
* <pre>
* public class TestClass {
*
* &#064;Rule
* public BugTestAwareRule rule = BugTestAwareRule.getInstance();
*
* &#064;org.junit.Test
* &#064;com.avaloq.tools.ddk.test.core.BugTest(value = &quot;BUG-42&quot;, unresolved = true)
* public void testMethod() {
* org.junit.Assert.fail();
* }
* }
* </pre>
* </p>
*
* @see BugTest
*/
public final class BugTestAwareRule implements InvocationInterceptor {
private static final String ERROR_TEST_MUST_FAIL = "The unresolved bug test must fail:"; //$NON-NLS-1$
/** The singleton instance, or {@code null} if not cached. */
private static BugTestAwareRule instance;
private static final Object LOCK = new Object();
/**
* Creates a new instance of {@link BugTestAwareRule}.
*/
private BugTestAwareRule() {
// prevent instantiation
}
/**
* Returns a shared singleton instance.
*
* @return a shared instance, never {@code null}
*/
public static BugTestAwareRule getInstance() {
synchronized (LOCK) {
if (instance == null) {
instance = new BugTestAwareRule();
}
return instance;
}
}
@SuppressWarnings("nls")
@Override
public void interceptTestMethod(final Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
BugTest bugTestAnnotation = extensionContext.getRequiredTestMethod().getAnnotation(BugTest.class);
if (bugTestAnnotation == null && extensionContext.getRequiredTestClass() != null) {
bugTestAnnotation = extensionContext.getRequiredTestClass().getAnnotation(BugTest.class);
}
if (bugTestAnnotation != null && bugTestAnnotation.unresolved()) {
try {
invocation.proceed();
} catch (AssertionError exception) {
return;
}
String testCase = extensionContext.getRequiredTestClass().getSimpleName() + "." + extensionContext.getRequiredTestMethod().getName();
throw new AssertionError(ERROR_TEST_MUST_FAIL + " " + testCase);
} else {
invocation.proceed();
}
}
}
Loading