Trick to set a Maven property for a JMockit test case

1 view
Skip to first unread message

cmou...@redhat.com

unread,
Jul 20, 2017, 7:20:23 AM7/20/17
to fabric8
Hi,

I try without success to define a Maven property for a f-m-p test case using JMockit. I use Deencapsulation.invoke to call the method "addProperty" and set a value but when it is call later in my code, the ojbect is null


@RunWith(JMockit.class)
public class SpringBootGeneratorServerPortTest {

    @Mocked
    private GeneratorContext context;

    @Mocked
    private MavenProject project;

    @Mocked
    private Build build;

    @Mocked
    private ModelBase model;

    private GeneratorContext createGeneratorWithMavenPropertiesContext() throws Exception {
        new Expectations() {{
            context.getProject(); result = project;
            project.getBuild(); result = build;
            String tempDir = Files.createTempDirectory("springboot-test-project").toFile().getAbsolutePath();
            build.getDirectory(); result = tempDir;
            build.getOutputDirectory(); result = tempDir;

            // Pass the property to the maven model
            Deencapsulation.invoke(model,"addProperty","server.port","7777");
        }};
        return context;
    }

Is there a trick ?

Regards,

Charles
Reply all
Reply to author
Forward
0 new messages