-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SurajOberoi15
committed
Jan 13, 2024
1 parent
5bd71f2
commit 6945d33
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
...ion/azurefunction/src/test/java/com/knoldus/function/trigger/EventHubTriggerJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
} |