Does CMAKE_BUILD_TYPE=Release imply -DNDEBUG?

Yes, it is set by CMake. Grepping through the CMake code reveals, that for a host of compilers it is set. Probably they set it only for these compilers, which accepts this flag. Here one of the lines concerning GCC: Modules/Compiler/GNU.cmake: set(CMAKE_${lang}_FLAGS_RELEASE_INIT “-O3 -DNDEBUG”) But be aware that many projects overwrite release/debug flags without preserving … Read more

How to guide GCC optimizations based on assertions without runtime cost?

Is there a way to express that the condition in the contract has no side effect, so that it is always optimized out? Not likely. It’s known that you cannot take a big collection of assertions, turn them into assumptions (via __builtin_unreachable) and expect good results (e.g. Assertions Are Pessimistic, Assumptions Are Optimistic by John … Read more

How to check if method has an attribute

The issue with your code is the signature of public bool MethodHasAuthorizeAttribute(Func<int, ActionResult> function). MethodHasAuthorizeAttribute can only be used with arguments matching the signature of the delegate you specified. In this case a method returning an ActionResult with a parameter of type int. When you call this method like MethodHasAuthorizeAttribute(controller.Method3), the Compiler will do a … Read more

Is there a way of having something like jUnit Assert message argument in Mockito’s verify method?

This question is ancient, but Mockito v2.1.0+ now has a built-in feature for this. verify(mock, description(“This will print on failure”)).someMethod(“some arg”); More examples included from @Lambart’s comment below: verify(mock, times(10).description(“This will print if the method isn’t called 10 times”)).someMethod(“some arg”); verify(mock, never().description(“This will print if someMethod is ever called”)).someMethod(“some arg”); verify(mock, atLeastOnce().description(“This will print if … Read more

Why assertEquals and assertSame in junit return the same result for two instances same class?

Since you didn’t override equals in your class, assertEquals behaves the same as assertSame since the default equals implementation compare references. 150 public boolean equals(Object obj) { 151 return (this == obj); 152 } If you provide a dumb overriding of equals: class SomeClass { @Override public boolean equals(Object o) { return true; } } … Read more

Should you assert not null with the assert statement in production code? [closed]

Use Objects.requireNonNull(Object) for that. Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, […] In your case that would be: public void useObject(CustomObject customObject) { object = customObject.getObject(); Objects.requireNonNull(object); // throws NPE if object is null // do stuff with object } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)