/*
 * Copyright (c) 2015 Inocybe inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.nic.mapping.mdsal.impl;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;

import com.google.common.util.concurrent.CheckedFuture;

public class MappingMdsalProviderTests {

    @Test
    public void delete() throws Exception {
        DataBroker databroker = mock(DataBroker.class);
        final WriteTransaction transaction = mock(WriteTransaction.class);
        @SuppressWarnings("unchecked")
        CheckedFuture<Void, TransactionCommitFailedException> value = mock(CheckedFuture.class);
        when(transaction.submit()).thenReturn(value);
        when(databroker.newWriteOnlyTransaction()).thenReturn(transaction);

        MappingMdsalProvider provider = new MappingMdsalProvider();

        String key = "key";
        try {
            provider.delete(key);
        } finally {
            provider.close();
        }
    }
}

@@ -677,16 +677,103 @@
 ception;
+%0Aimport org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 %0A%0Aimport
@@ -923,64 +923,8 @@
 n %7B%0A
-        DataBroker databroker = mock(DataBroker.class);%0A
     
@@ -986,32 +986,33 @@
 saction.class);%0A
+%0A
         @Suppres
@@ -1109,16 +1109,33 @@
  = mock(
+%0A                
 CheckedF
@@ -1201,16 +1201,73 @@
 (value);
+%0A%0A        DataBroker databroker = mock(DataBroker.class);
 %0A       
@@ -1332,24 +1332,166 @@
 nsaction);%0A%0A
+        ProviderContext session = mock(ProviderContext.class);%0A        when(session.getSALService(DataBroker.class)).thenReturn(databroker);%0A%0A
         Mapp
@@ -1545,16 +1545,62 @@
 vider();
+%0A        provider.onSessionInitiated(session);
 %0A%0A      
@@ -1621,16 +1621,17 @@
  %22key%22;%0A
+%0A
         

Fix the the NPE which was occuring on "delete" test.