public function testGetCustomAttributes()
 {
     $priceCode = 'price';
     $colorAttributeCode = 'color';
     $interfaceAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $interfaceAttribute->expects($this->once())->method('getAttributeCode')->willReturn($priceCode);
     $colorAttribute = $this->getMock('\\Magento\\Framework\\Api\\MetadataObjectInterface');
     $colorAttribute->expects($this->once())->method('getAttributeCode')->willReturn($colorAttributeCode);
     $customAttributesMetadata = [$interfaceAttribute, $colorAttribute];
     $this->metadataServiceMock->expects($this->once())->method('getCustomAttributesMetadata')->willReturn($customAttributesMetadata);
     $this->model->setData($priceCode, 10);
     //The color attribute is not set, expect empty custom attribute array
     $this->assertEquals([], $this->model->getCustomAttributes());
     //Set the color attribute;
     $this->model->setData($colorAttributeCode, "red");
     $attributeValue = new \Magento\Framework\Api\AttributeValue();
     $attributeValue2 = new \Magento\Framework\Api\AttributeValue();
     $this->attributeValueFactory->expects($this->exactly(2))->method('create')->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
     $this->assertEquals(1, count($this->model->getCustomAttributes()));
     $this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
     $this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
     //Change the attribute value, should reflect in getCustomAttribute
     $this->model->setData($colorAttributeCode, "blue");
     $this->assertEquals(1, count($this->model->getCustomAttributes()));
     $this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
     $this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
 }
 /**
  * {@inheritdoc}
  */
 public function getCustomAttributes()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getCustomAttributes');
     if (!$pluginInfo) {
         return parent::getCustomAttributes();
     } else {
         return $this->___callPlugins('getCustomAttributes', func_get_args(), $pluginInfo);
     }
 }