/** Setup tasks */
  @Before
  public void setUp() {
    context = new Mockery();
    assetRepository = context.mock(AssetRepository.class);
    errors = context.mock(Errors.class);
    fixture = new FixtureRequestModel();

    rule = new InventoryNumberValidationRule();
    rule.setAssetRepository(assetRepository);
  }
 /** Validate that no errors appear when no conflict occurs */
 @Test
 public void testGoodInventoryNumber() {
   final String invNumber = "INV-12345";
   fixture.setInventoryNumber(invNumber);
   context.checking(
       new Expectations() {
         {
           oneOf(assetRepository).findAssetByInventoryNumber(invNumber);
           will(returnValue(null));
         }
       });
   rule.validate(fixture, errors);
   context.assertIsSatisfied();
 }
  /** Validate that a rejection occurs if a conflict occurs */
  @Test
  public void testConflictingInventoryNumber() {
    final Asset asset = new Asset();
    final String invNumber = "INV-12345";
    fixture.setInventoryNumber(invNumber);

    context.checking(
        new Expectations() {
          {
            oneOf(assetRepository).findAssetByInventoryNumber(invNumber);
            will(returnValue(asset));
            oneOf(errors).rejectValue("inventoryNumber", MSG_PREFIX + "inventoryNumber.conflict");
          }
        });

    rule.validate(fixture, errors);
    context.assertIsSatisfied();
  }
 /** Validate that nothing happens if an empty inventory number is provided */
 @Test
 public void testAllowsEmptyInventoryNumber() {
   rule.validate(fixture, errors);
 }
 /** Validate that the rule supports the expected ActionType value(s) */
 @Test
 public void testAcceptsExpectedActionTypes() {
   assertTrue(rule.supports(ActionType.ADD));
   assertFalse(rule.supports(ActionType.EDIT));
 }