Junit VerificationModeFactory.times() vs mockito.times() - junit

What is the difference between VerificationModeFactory.times() and mockito.times()?

I thought it would be faster to ask rather than go check by myself :) I was lazy and wrong so I did the check by myself and here is the answer. It is the same thing, Mockito.Times() is internally calling the VerificationModeFactory.times()
From Mockito.class
/**
* Allows verifying exact number of invocations. E.g:
* <pre>
* verify(mock, times(2)).someMethod("some arg");
* </pre>
*
* See examples in javadoc for {#link Mockito} class
*
* #param wantedNumberOfInvocations wanted number of invocations
*
* #return verification mode
*/
public static VerificationMode times(int wantedNumberOfInvocations) {
return VerificationModeFactory.times(wantedNumberOfInvocations);
}

Related

Magento Attribute-Codes with Uppercase Letters need to work

Hello Guys,
is there any possibility to make the Magento 2 Import-Module uppercase insensitive?
I have attribute-codes like "ColorName" or "BaseColor" and I need them to be working. Right now the data in CSV-File is ignored by Magento for those attributes. The Problem is: I can not change them. There is too much code already written. So i really need magento to recognize uppercase attribute-codes. There is no other solution.
But, is this even possible?
Thanks!
Not sure if this helps, but the attribute code is comverted to lowercase in Magento\CatalogImportExport\Model\Import\Product::retrieveAttributeByCode.
the method looks like this
/**
* Retrieve attribute by code
*
* #param string $attrCode
* #return mixed
*/
public function retrieveAttributeByCode($attrCode)
{
/** #var string $attrCode */
$attrCode = mb_strtolower($attrCode);
if (!isset($this->_attributeCache[$attrCode])) {
$this->_attributeCache[$attrCode] = $this->getResource()->getAttribute($attrCode);
}
return $this->_attributeCache[$attrCode];
}
you can try to override the method and remove the $attrCode = mb_strtolower($attrCode); line or create an around plugin for it.

Laravel AssertJsonCount on a nested array

How can I call assertJsonCount using an indexed, nested array?
In my test, the following JSON is returned:
[[{"sku":"P09250"},{"sku":"P03293"}]]
But attempting to use assertJsonCount returns the following error:
$response->assertJsonCount(2);
// Failed asserting that actual size 1 matches expected size 2.
This may or may not be specific to Laravel. Although a Laravel helper is involved, this issue may occur elsewhere.
assertJsonCount utilises the PHPUnit function PHPUnit::assertCount which uses a laravel helper data_get, which has the following signature:
/**
* Get an item from an array or object using "dot" notation.
*
* #param mixed $target
* #param string|array|int $key
* #param mixed $default
* #return mixed
*/
function data_get($target, $key, $default = null)
{
if (is_null($key)) {
return $target;
}
...
We can see that the JSON returned is a nested array, so logically we should pass in a key of 0.
$response->assertJsonCount($expectedProducts->count(), '0');
However this will be ignored as assertCount function checks if a key has been passed using is_null.
To overcome this, we can count all children of 0:
$response->assertJsonCount($expectedProducts->count(), '0.*');
This will produce the desired result.

yii2 phpDoc- word order

Why in yii2 phpDoc annotation in views we can see such word order
* #var $width integer
and in class's methods such word order
* #param integer $width
Why doesn't the second example have such form
* #param $width integer
The correct syntax for this tag is
#param [Type] [name] [<description>]
So declaration where type declared after parameter name is incorrect, but as you see it works the same so i guess that it has no difference but better to use syntax.

How JPA or Hibernate generate UUID as key?

I am trying to use UUID as key with Mybatis. There are usually two ways:
Generate user keys in code.
Use uuid() method in mysql.
The first soluation should be a better choice for me, my question is how to implement a method to generate UUID as keys as JPA or Hibernate does? Their UUID keys is not a standard UUID.
with no dash.
rearrange the sequence for better performance.
I used`UUIDHexGenerator` from Hibernate to generate UUID now.
UUIDHexGenerator.java
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the #author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
import java.io.Serializable;
/**
* <b>uuid</b><br>
* <br>
* A <tt>UUIDGenerator</tt> that returns a string of length 32,
* This string will consist of only hex digits. Optionally,
* the string may be generated with separators between each
* component of the UUID.
*
* Mapping parameters supported: separator.
*
* #author Gavin King
*/
public class UUIDHexGenerator extends AbstractUUIDGenerator {
private String sep = "";
protected String format(int intval) {
String formatted = Integer.toHexString(intval);
StringBuffer buf = new StringBuffer("00000000");
buf.replace( 8-formatted.length(), 8, formatted );
return buf.toString();
}
protected String format(short shortval) {
String formatted = Integer.toHexString(shortval);
StringBuffer buf = new StringBuffer("0000");
buf.replace( 4-formatted.length(), 4, formatted );
return buf.toString();
}
public Serializable generate() {
return new StringBuffer(36)
.append( format( getIP() ) ).append(sep)
.append( format( getJVM() ) ).append(sep)
.append( format( getHiTime() ) ).append(sep)
.append( format( getLoTime() ) ).append(sep)
.append( format( getCount() ) )
.toString();
}
public static void main( String[] args ) throws Exception {
UUIDHexGenerator gen = new UUIDHexGenerator();
UUIDHexGenerator gen2 = new UUIDHexGenerator();
for ( int i=0; i<100; i++) {
String id = (String) gen.generate();
System.out.println(id);
String id2 = (String) gen2.generate();
System.out.println(id2);
String id3 = (String) gen2.generate();
System.out.println(id3);
}
}
}
BytesHelper.java
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the #author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
public final class BytesHelper {
private BytesHelper() {}
public static int toInt( byte[] bytes ) {
int result = 0;
for (int i=0; i<4; i++) {
result = ( result << 8 ) - Byte.MIN_VALUE + (int) bytes[i];
}
return result;
}
}
AbstractUUIDGenerator.java
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the #author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
import java.net.InetAddress;
/**
* The base class for identifier generators that use a UUID algorithm. This
* class implements the algorithm, subclasses define the identifier
* format.
*
* #see UUIDHexGenerator
* #author Gavin King
*/
public abstract class AbstractUUIDGenerator {
private static final int IP;
static {
int ipadd;
try {
ipadd = BytesHelper.toInt( InetAddress.getLocalHost().getAddress() );
}
catch (Exception e) {
ipadd = 0;
}
IP = ipadd;
}
private static short counter = (short) 0;
private static final int JVM = (int) ( System.currentTimeMillis() >>> 8 );
public AbstractUUIDGenerator() {
}
/**
* Unique across JVMs on this machine (unless they load this class
* in the same quater second - very unlikely)
*/
protected int getJVM() {
return JVM;
}
/**
* Unique in a millisecond for this JVM instance (unless there
* are > Short.MAX_VALUE instances created in a millisecond)
*/
protected short getCount() {
synchronized(AbstractUUIDGenerator.class) {
if (counter<0) counter=0;
return counter++;
}
}
/**
* Unique in a local network
*/
protected int getIP() {
return IP;
}
/**
* Unique down to millisecond
*/
protected short getHiTime() {
return (short) ( System.currentTimeMillis() >>> 32 );
}
protected int getLoTime() {
return (int) System.currentTimeMillis();
}
}

yii2 App Starting With An Error

I am experiencing a strange error when I start my Yii2 app! Please need your help on this. Here is the what I get:
PHP Warning – yii\base\ErrorException
mb_strlen() expects parameter 1 to be string, array given
1. in /var/www/yii2/basic/vendor/yiisoft/yii2/helpers/BaseStringHelper.php at line 31
22232425262728293031323334353637383940
{
/**
* Returns the number of bytes in the given string.
* This method ensures the string is treated as a byte array by using `mb_strlen()`.
* #param string $string the string being measured for length
* #return integer the number of bytes in the given string.
*/
public static function byteLength($string)
{
return mb_strlen($string, '8bit');
}
/**
* Returns the portion of string specified by the start and length parameters.
* This method ensures the string is treated as a byte array by using `mb_substr()`.
* #param string $string the input string. Must be one character or longer.
* #param integer $start the starting position
* #param integer $length the desired portion length. If not specified or `null`, there will be
* no limit on length i.e. the output will be until the end of the strin
I happened an the same error message copying an external component in my project in my case I solved the problem by running
composer update