- Added code for JUnit 5 article
This commit is contained in:
		
							parent
							
								
									a875e25b18
								
							
						
					
					
						commit
						f7176e6255
					
				| @ -11,8 +11,8 @@ public class ExceptionTest { | |||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void shouldThrowException() { |     void shouldThrowException() { | ||||||
|         ArrayList list = null; |         Throwable exception = expectThrows(UnsupportedOperationException.class, | ||||||
|         Throwable exception = expectThrows(NullPointerException.class, list::clear); |                 () -> {throw new UnsupportedOperationException("Not supported");}); | ||||||
|         assertEquals(exception.getClass(), NullPointerException.class); |         assertEquals(exception.getMessage(), "Not supported"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -3,6 +3,10 @@ package com.baeldung; | |||||||
| import org.junit.gen5.api.Disabled; | import org.junit.gen5.api.Disabled; | ||||||
| import org.junit.gen5.api.Test; | import org.junit.gen5.api.Test; | ||||||
| 
 | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
| import static org.junit.gen5.api.Assertions.assertAll; | import static org.junit.gen5.api.Assertions.assertAll; | ||||||
| import static org.junit.gen5.api.Assertions.assertEquals; | import static org.junit.gen5.api.Assertions.assertEquals; | ||||||
| import static org.junit.gen5.api.Assertions.assertTrue; | import static org.junit.gen5.api.Assertions.assertTrue; | ||||||
| @ -11,13 +15,16 @@ class FirstTest { | |||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void lambdaExpressions() { |     void lambdaExpressions() { | ||||||
|         String string = ""; |         List<Integer> numbers = Arrays.asList(1, 2, 3); | ||||||
|         assertTrue(string::isEmpty, "String should be empty"); |         assertTrue(numbers | ||||||
|  |                 .stream() | ||||||
|  |                 .mapToInt(i -> i) | ||||||
|  |                 .sum() > 5, "Sum should be greater than 5"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |     @Test | ||||||
|     void groupAssertions() { |     void groupAssertions() { | ||||||
|         int[] numbers = {0,1,2,3,4}; |         int[] numbers = {0, 1, 2, 3, 4}; | ||||||
|         assertAll("numbers", () -> { |         assertAll("numbers", () -> { | ||||||
|             assertEquals(numbers[0], 1); |             assertEquals(numbers[0], 1); | ||||||
|             assertEquals(numbers[3], 3); |             assertEquals(numbers[3], 3); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user