Skip to content

Commit

Permalink
Added test cases for azure
Browse files Browse the repository at this point in the history
  • Loading branch information
SurajOberoi15 committed Jan 13, 2024
1 parent 5bd71f2 commit 6945d33
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.knoldus.function.trigger;

import com.knoldus.function.model.Car;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.OutputBinding;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;

public class EventHubTriggerJavaTest {

@Mock
private ExecutionContext context;
@Mock
private OutputBinding<List<Car>> outputBinding;

@InjectMocks
private EventHubTriggerJava eventHubTriggerJava;

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testRun() {
// Prepare test data
List<Car> testCarDetails = new ArrayList<>();
testCarDetails.add(new Car(1,"Toyota","Sedan", 1996L, "white", 20.0,2000.0,2,5.0 )); // Add more cars as needed

// Mock context and logger
ExecutionContext context = mock(ExecutionContext.class);
Logger mockLogger = mock(Logger.class);
when(context.getLogger()).thenReturn(mockLogger);

// Call the method under test
eventHubTriggerJava.run(testCarDetails, outputBinding, context);

// Assertions and verifications
ArgumentCaptor<List<Car>> argumentCaptor = ArgumentCaptor.forClass(List.class);
verify(outputBinding).setValue(argumentCaptor.capture());
List<Car> capturedCars = argumentCaptor.getValue();

assertNotNull(capturedCars);
assertFalse(capturedCars.isEmpty());

}
}

0 comments on commit 6945d33

Please sign in to comment.