Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracles should used the new name of the test classes #539

Closed
vmassol opened this issue Sep 4, 2018 · 2 comments
Closed

Oracles should used the new name of the test classes #539

vmassol opened this issue Sep 4, 2018 · 2 comments
Assignees
Labels

Comments

@vmassol
Copy link
Contributor

vmassol commented Sep 4, 2018

Generated test:

package org.xwiki.context;


import java.lang.reflect.Field;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.xwiki.context.internal.ExecutionContextProperty;


public class AmplExecutionContextPropertyTest {
    @SuppressWarnings("unchecked")
    private ExecutionContextProperty fetch(ExecutionContext context, String key) throws Exception {
        Field propertiesField = ExecutionContext.class.getDeclaredField("properties");
        propertiesField.setAccessible(true);
        Map<String, ExecutionContextProperty> properties = ((Map<String, ExecutionContextProperty>) (propertiesField.get(context)));
        return properties.get(key);
    }

    @Test(timeout = 10000)
    public void cloningNonPublicCloneMethod_failAssert0() throws Exception {
        try {
            ExecutionContext context = new ExecutionContext();
            final String key = "test";
            AmplExecutionContextPropertyTest.TestNonpublicClone value = new AmplExecutionContextPropertyTest.TestNonpublicClone();
            context.newProperty(key).cloneValue().initial(new AmplExecutionContextPropertyTest.TestNonpublicClone()).declare();
            fetch(context, key).clone();
            org.junit.Assert.fail("cloningNonPublicCloneMethod should have thrown IllegalStateException");
        } catch (IllegalStateException expected) {
            Assert.assertEquals("cloneValue attribute was set on property [test], but the value had class [org.xwiki.context.ExecutionContextPropertyTest$TestNonpublicClone] which has no public clone method", expected.getMessage());
        }
    }

    @Test(timeout = 10000)
    public void nonNullCheck_failAssert1() throws Exception {
        try {
            ExecutionContext context = new ExecutionContext();
            final String key = "test";
            new ExecutionContext().newProperty("test").nonNull().initial(null).declare();
            org.junit.Assert.fail("nonNullCheck should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            Assert.assertEquals("The property [test] may not be null!", expected.getMessage());
        }
    }

    @Test(timeout = 10000)
    public void typeCheckingMismatch_failAssert2() throws Exception {
        try {
            ExecutionContext context = new ExecutionContext();
            final String key = "test";
            context.newProperty(key).type(AmplExecutionContextPropertyTest.SomeSubClass.class).declare();
            context.setProperty(key, new AmplExecutionContextPropertyTest.SomeClass());
            org.junit.Assert.fail("typeCheckingMismatch should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
            Assert.assertEquals("The value of property [test] must be of type [class org.xwiki.context.ExecutionContextPropertyTest$SomeSubClass], but was [class org.xwiki.context.ExecutionContextPropertyTest$SomeClass]", expected.getMessage());
        }
    }

    public static class TestCloneable implements Cloneable {
        public String value = "original";

        @Override
        public Object clone() throws CloneNotSupportedException {
            AmplExecutionContextPropertyTest.TestCloneable clone = ((AmplExecutionContextPropertyTest.TestCloneable) (super.clone()));
            clone.value = "clone";
            return clone;
        }
    }

    public static class TestNonpublicClone implements Cloneable {
        @Override
        protected Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }

    public static class SomeClass {}

    public static class SomeSubClass extends AmplExecutionContextPropertyTest.SomeClass {}
}

Results in:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.xwiki.context.ExecutionContextTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.263 s - in org.xwiki.context.ExecutionContextTest
[INFO] Running org.xwiki.context.internal.DefaultExecutionContextManagerTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in org.xwiki.context.internal.DefaultExecutionContextManagerTest
[INFO] Running org.xwiki.context.internal.DefaultExecutionTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in org.xwiki.context.internal.DefaultExecutionTest
[INFO] Running org.xwiki.context.AmplExecutionContextPropertyTest
[ERROR] Tests run: 3, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 0.002 s <<< FAILURE! - in org.xwiki.context.AmplExecutionContextPropertyTest
[ERROR] typeCheckingMismatch_failAssert2  Time elapsed: 0.001 s  <<< FAILURE!
org.junit.ComparisonFailure: expected:<...s org.xwiki.context.[ExecutionContextPropertyTest$SomeSubClass], but was [class org.xwiki.context.]ExecutionContextProp...> but was:<...s org.xwiki.context.[AmplExecutionContextPropertyTest$SomeSubClass], but was [class org.xwiki.context.Ampl]ExecutionContextProp...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.xwiki.context.AmplExecutionContextPropertyTest.typeCheckingMismatch_failAssert2(AmplExecutionContextPropertyTest.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

[ERROR] cloningNonPublicCloneMethod_failAssert0  Time elapsed: 0 s  <<< FAILURE!
org.junit.ComparisonFailure: expected:<... [org.xwiki.context.[]ExecutionContextProp...> but was:<... [org.xwiki.context.[Ampl]ExecutionContextProp...>
	at org.junit.Assert.assertEquals(Assert.java:115)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.xwiki.context.AmplExecutionContextPropertyTest.cloningNonPublicCloneMethod_failAssert0(AmplExecutionContextPropertyTest.java:30)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)

[INFO] Running org.xwiki.context.concurrent.ExecutionContextRunnableTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.844 s - in org.xwiki.context.concurrent.ExecutionContextRunnableTest
[INFO] Running org.xwiki.context.AmplExecutionContextTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 s - in org.xwiki.context.AmplExecutionContextTest
[INFO] Running org.xwiki.context.ExecutionContextPropertyTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 s - in org.xwiki.context.ExecutionContextPropertyTest
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   AmplExecutionContextPropertyTest.cloningNonPublicCloneMethod_failAssert0:30 expected:<... [org.xwiki.context.[]ExecutionContextProp...> but was:<... [org.xwiki.context.[Ampl]ExecutionContextProp...>
[ERROR]   AmplExecutionContextPropertyTest.typeCheckingMismatch_failAssert2:55 expected:<...s org.xwiki.context.[ExecutionContextPropertyTest$SomeSubClass], but was [class org.xwiki.context.]ExecutionContextProp...> but was:<...s org.xwiki.context.[AmplExecutionContextPropertyTest$SomeSubClass], but was [class org.xwiki.context.Ampl]ExecutionContextProp...>
[INFO] 
[ERROR] Tests run: 20, Failures: 2, Errors: 0, Skipped: 0
@danglotb
Copy link
Member

danglotb commented Sep 5, 2018

Hi.

I identified the problem, it came from the oracle. Since the renaming to Ampl is done at the end of the process, the expected values in the message of exceptions are using the original names, i.e. ExecutionContextProp not AmplExecutionContextProp.

In case of the generation of a new test class, we have to find out every use of the name and replace it with the new name.

Thank.

@danglotb danglotb self-assigned this Sep 5, 2018
@danglotb danglotb added the bug label Sep 5, 2018
@danglotb danglotb changed the title Amplified test doesn't execute for AmplExecutionContextPropertyTest Oracles should used the new name of the test classes Sep 5, 2018
@vmassol
Copy link
Contributor Author

vmassol commented Sep 5, 2018

cool that you identified the problem!

spookyvale added a commit to spookyvale/dspot that referenced this issue Sep 12, 2018
feat: FIX STAMP-project#539 replace all occurences of original name (STAMP-project#540)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants