java - JMockit - "Missing invocation to mocked type" when mocking System.getProperties() -
I'm definitely new to JMKit, but I'm getting the system due to some reason. GetProperties (). Thanks for the help of the following posts:
I can successfully mock System.getProperty () using JMokit 1.12:
@Test Public Zero Testing Systemproperty_string () {last string property name = "foo"; Last string property value = "bar"; New Requirements (System.class) {{System.getProperty (propertyName); Return (propertyValue); }}; AssertEquals (propertyValue, System.getProperty (propertyName)); }
but getProperties () eerily similar code for junk jokes:
@Test public void testAddSystemProperty_String () {last string propertyName = "foo"; Last string property value = "bar"; End Properties Property = New Property (); Properties.setProperty (propertyName, propertyValue); New Requirements (System.class) {{System.getProperties (); Return (attributes); }}; AssertEquals (1, System.getProperties (.) Size ()); }
I get the following exception which indicates the "return" method:
At this point the invitation to type the mock is unavailable; Please make sure that such anocations appear only after declaration of a suitable duplicate field or parameter
Besides, how do I duplicate both methods at the same time? If I put them in the same hope block (with getProperty (first)), then I do not see the exception, but the system .getProperties () returns the real system properties, not the intended ones; Although getProperty (propertyName) returns neglected values, I think that is completely scary behavior.
I see from this post that some methods can not be joke, but System.getProperties () is not in the list:
I am also aware that a lot of solutions are completely unorganized on the SO that worked with JMokit 2-3 years ago, so things seem to change very much.
System.getProperties ()
Really joke in JMockit 1.12 Is one of them. The exact set of such deprecated methods can turn into new versions because new problematic JRE methods are found.
System <<<
There is no need to copy System.getProperties ()
, though. System
class setProperty
and setProperties
can be used instead.
Comments
Post a Comment