When to use Value Formatter and when to use Value Resolver - automapper

I am still confused of when to use Value Formatter versus Value Resolver in automapper.
Say I have a nullable DateTime that I want to make into a specific date format(so the end result would be a string). Should I use Formatter in this case?
Thanks

I had the same question and chose Value Resolver based upon documentation from the author himself that Value Formatter is likely a design mistake:
https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-formatters
However, that same author provided a response to what to use when here:
Why does AutoMapper have an IValueFormatter when it has a seemingly much more powerful ValueResolver?

Related

How can I get the default value of a parameter (method) in groovy at runtime?

How can I get the default value of a parameter (method) in groovy at runtime?
Is there a possibility?
How can I get the default value of a parameter (method) in groovy at
runtime? Is there a possibility?
Aside from invoking the method without supplying the parameter and then inspecting the value that was passed in, not a practical one, no. You could write code that parses the .class file and the info is there, but I don't think there is anything in Groovy related that is going to help or be relevant.

How to match a possible null parameter in Mockito

I'm trying to verify that the class I'm testing calls the correct dependency class's method. So I'm trying to match the method parameters, but I don't really care about the actual values in this test, because I don't want to make my test brittle.
However, I'm running into trouble setting it up because Mockito has decided that the behaviour I'm expecting is a bug: https://github.com/mockito/mockito/issues/134
So what't the correct way to define an ArgumentMatcher for a parameter that might be null?
With issue #134 "fixed", this code fails because the matchers only match in the first case. How can I define a matcher to work in all 4 cases?
MyClass c = mock(MyClass.class);
c.foo("hello", "world");
c.foo("hello", null);
c.foo(null, "world");
c.foo(null, null);
verify(c, times(4)).foo(anyString(), anyString());
From the javadocs of any()
Since Mockito 2.1.0, only allow non-null String. As this
is a nullable reference, the suggested API to match
null wrapper would be isNull(). We felt this
change would make tests harness much safer that it was with Mockito
1.x.
So, the way to match nullable string arguments is explicit declaration:
nullable(String.class)
I got this to work by switching to any(String.class)
I find this a bit misleading, because the API seems to suggest that anyString() is just an alias for any(String.class) at least up till the 2.0 update. To be fair, the documentation does specify that anyString() only matches non-null strings. It just seems counter-intuitive to me.
How about:
verify(c, times(4)).foo(anyObject(), anyObject());
Does that work for you?
Matchers.anyObject() allows for nulls.
Reference in Mockito docs:

Is there an equivalent to anyInt(), anyString(), etc. for checking a parameter is of a particular (non-generic) type?

If a mocked method is passed a generic type as a parameter, it is easy to generate the same response regardless of its value by using methods such as anyInt(), anyChar(), anyString(), etc.
Is it possible to do this where the parameter must be a particular type of Object?
(For example, anyCar(), anyVehicle(), etc.)
The matcher isA(Class<T> clazz) provides this functionality.
For example -
isA(Car.class), isA(Vehicle.class)

How to use BigDecimal in Xpages?

I'm using stored numeric values in calculations and matching situations and javascript doubles are a big "NO-NO" when doing these kind of operations.
However I can't find a solution on how to use java BigDecimal in SSJS in Xpages.
Since one should construct a BigDecimal using a string I have tried different approaches i SSJS. Whatever test the result is the same, the call is ambiguous:
Ambiguity when calling new java.math.BigDecimal(long) and new
java.math.BigDecimal(int)
How do I use a BigDecimal in my SSJS when values are stored in documents as Numbers?
How do I use BigDecimal with a string argument when values are stored in documents as Numbers?
edit/amend:
After accepting Svens answer I got a bit further and to my second question.
The value retrieved from the document is 451368 but it will be stored in variable as 451367.99999999994
How do I recover from that when the user should match against original value?
Use Java-Objects instead:
var value = new java.lang.Integer(1);
new java.math.BigDecimal(value);

Groovy date formatting problem

I am developing a groovy application and I am having problems when showing a Date field.
If I use the following notation:
<g:formatDate format="dd.MM.yyyy" date="${fieldValue(bean: incidentTicketSLAInstance, field: "erstellungsDatum")}"/>
I am getting the actual date instead of what is saved at the DB.
When I use this notation it works properly.
<g:formatDate format="dd.MM.yyyy" date="${incidentTicketSLAInstance?.erstellungsDatum}" />
am I doing something wrong here?
Are not both notations equivalent?
(BTW, the instance DO exists and erstellungsDatum is NOT null)
Thanks in advance,
Luis
the fieldValue call will return a String, not a Date object, which the makes formatDate not work correctly
You have to use the second notation (as you spotted)

Resources