Spock Mock internal Date object - testing

I am returning a string from the groovy utility class. The method is
return "${new SimpleDateFormate("dd_MM_yyyy").format(new Date())}"
I want to test this method with my date. Can I mock the new Date() as 2016-01-14.
If it is possible, how to implement it.

Why not change the method to take a date as a parameter, then it's easily testable?
Though you appear to be testing that simple date format works. I believe oracle have you covered

Related

Mockito - Is it possible to deep mock a void method call to do nothing?

I wanted to know if it is possible to "deep mock" a void method call without breaking out the call chain, using Mockito.
This is an example for the original call I want to mock:
obj.getSomething().add(3);
where "add"'s return type is void.
I tried:
doNothing().when(obj).getSomething().add(3)
and:
doNothing().when(obj.getSomething()).add(3) //wont work since "when" expects a mock.
I also failed using Mockito.when(...) since it does not work with void methods.
I do not want to break the call up since it will be very cumbersome for fluent API calls that are much longer.
Is there an official solution / workaround for this scenario?
Thanks :)
If the value returned by getSomething is not a mock, it won't work.
Return value of getSomething should be a mock and it will allow to assign mock behavior for that value.
Something someMock = mock(Something.class);
when(obj.getSomething()).thenReturn(someMock);
doNothing().when(someMock).add(3);

Rhino Mocks WhenCalled - Delegate 'System.Action' does not take 1 arguments

WhenCalled is well documented all over the place & I'm not going into why I'm using it but I just can't get it to work in the same way as it's detailed inpractically every post I've seen on the topic.
Basically you should be able to do something like:
mock.Expect(x => x. SingleOrDefault(null))
.IgnoreArguments()
.WhenCalled(invocation => ((Action)invocation.Arguments[0]).Invoke());
But this doesn't compile for me - I just get an error saying Delegate 'System.Action' does not take 1 arguments.
I'm using V 4.0 of Rhino Mocks - has this method changed? I want to use
WhenCalled to grab the arguments passed to SingleOrDefault (in this case a lambda expression).
All answered in this blog post:
Rhino Mocks 4.0.0
Previously, WhenCalled allowed you to execute an Action that took, as a single parameter, a data structure encapsulating the method invocation. Since an Action was being invoked the return value of the expectation could not be changed.
In the current version, WhenCalled has been modified slightly to simply execute an Action
In order to provide a similar feature as the original “WhenCalled”, a new method “Intercept” has been added which expects an Action that takes, as a single parameter, a data structure encapsulating the method invocation
tl;dr: Use Intercept instead of WhenCalled

How can i set current date using expression builder in oracle adf?

How can i set current date using expression builder in oracle adf?
i am using jdeveloper 11.1.1.3.0 and using Input Date(ADF faces.common.component)
The expression builder is used to build EL expressions that reference a method or a value property. Its not meant to set a value but to make it available for editing. One option would be to use a method expression to invoke an action on a manage bean that then sets the value. However, in JSF 1.2 you cannot pass arguments to an EL method and for this reason you would need a work around for setting a date. The work around is that the method expression (and thus the press of a button) invokes a method, which then creates the current date (or whatever date you want to pass in) and sets it on the component directly (though setting it on the component model works much better IMO).
Frank
Another option is to have your datasource field have a default value defined for it in the business service layer. So for example if you are using ADF BC then your field can have a default of adf.currentDate.

LINQ to Entities does not recognize the method [Type] GetValue[Type]

I've a simple class like this:
Public Class CalculationParameter{
public Long TariffId{get;set;}
}
In a workflow activity, I've an Assign like this:
(From tariffDetail In db.Context.TariffDetails
Where tariffDetial.TariffId = calculationParameter.TariffId).FirstOrDefault()
Dto is passed to Activity as an Input Argument.
It raise following error and I'm wondering how to assign Id. Any Idea?
LINQ to Entities does not recognize the method 'Int64
GetValue[Int64](System.Activities.LocationReference)' method, and this
method cannot be translated into a store expression.
How can I assign the calculationParameter.TariffId to tariffDetial.TariffId?!
UPDATE:
Screen shot attached shows that how I'm trying to assign calculationParameter.TariffId to tariffDetail.TariffId (car.Id = Dto.Id) and the query result should assign to CurrentTrafficDetail object.
Here's your problem. I don't know if there is a solution to it.
As you said in a (now deleted, unfortunately necessitating that I answer) comment, the exception you're getting is
LINQ to Entities does not recognize the method Int64 GetValue[Int64](System.Activities.LocationReference) method, and this method cannot be translated into a store expression.
in your Linq query, calculationParameter is a Variable defined on the workflow. That Variable is actually an instance that extends the type System.Activities.LocationReference and NOT CalculationParameter.
Normally, when the workflow executes, the LocationReference holds all the information it needs to find the value which is assigned to it. That value isn't retrieved until the last possible moment. At runtime, the process of retrieval (getting the executing context, getting the value, converting it to the expected type) is managed by the workflow.
However, when you introduce Linq into the mix, we have the issue you are experiencing. As you may or may not know, your expression gets compiled into the extension method version of the same.
(From tariffDetail In db.Context.TariffDetails
Where tariffDetial.TariffId = calculationParameter.TariffId)
.FirstOrDefault()
is compiled to
db.Context.TariffDetails
.Where(x => x.TariffId = calculationParameter.TariffId)
.FirstOrDefault();
When this executes, L2E doesn't actually execute this code. It gets interpreted and converted into a SQL query which is executed against the database.
As the interpreter isn't omniscient, there are a well defined set of limitations on what methods you can use in a L2S query.
Unfortunately for you, getting the current value of a LocationReference is not one of them.
TL:DR You cannot do this.
As for workarounds, the only thing I think you can do is create a series of extension methods on your data context type or add methods to your CalculationParameter class that you can call from within the Expression Editor. You can create your Linq to Entities queries within these methods, as all types will already have been dereferenced by the workflow runtime, which means you won't have to worry about the L2E interpreter choking on LocationReferences.
*Edit: A workaround can be found here (thanks to Slauma who mentioned this in a comment on the question)

Custom Parameters in a Manual Test Case

I have a question regarding a manual Test Case in Microsoft Test Manager. Is there a way to define 'custom' parameters?
Normally, you can define whatever parameter you want, like #FirstName. This parameter will automatically be added to the list of parameters of your testcase.
But I was wondering if there is something like '#Date'.. which replaces itself in a -DateTime.Now- equivalent?
Unfortunately that is not supported out of the box. The parameter parser does not understand special parameters. So, #date will not give you DateTime.Now
You can however, convert the test to a coded UI test and overwrite the parameter value to pass DateTime.Now when #date is passed.
However, i like your suggestion and would recommend that you raise it on the user voice site here => http://visualstudio.uservoice.com/forums/121579-visual-studio