Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulling the latest into my repo #1

Merged
merged 17 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ mvnw*

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/**
00-framework-tool-introductions/04.Mockito-Introduction-In-5-Steps/mockito-demo.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target/

### IntelliJ IDEA ###
.idea
.idea
*.iws
*.iml
*.ipr
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M2</version>
<version>3.2.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<java.version>21</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<version>3.2.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>21</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.in28minutes.learning.maven.maveninfewsteps;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
// replaced @RunWith with @ExtendWith
// replaced SpringRunner.class with SpringExtension.class
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class MavenInFewStepsApplicationTests {

Expand Down

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
## First 5 Steps in JUnit

- Git Repository - https://github.com/in28minutes/getting-started-in-5-steps
- Pre-requisites - Java & Eclipse - https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3
- We will use embedded maven in Eclipse

### Step 1 : What is JUnit and Unit Testing?
- What is JUnit?
- What is Unit Testing?
Expand All @@ -26,6 +22,11 @@
- @Before @After annotations
- @BeforeClass @AfterClass annotations


<!---
Current Directory : /Users/rangakaranam/Ranga/git/00.courses/spring-boot-master-class/03.JUnit-Introduction-In-5-Steps-V2
-->

## Complete Code Example


Expand All @@ -35,90 +36,137 @@
package com.in28minutes.junit;

public class MyMath {
int sum(int[] numbers) {

//{1,2,3} => 1+2+3 = 6
public int calculateSum(int[] numbers) {

int sum = 0;
for (int i : numbers) {
sum += i;

for(int number:numbers) {
sum += number;
}

return sum;
}


}
```
---

### /test/com/in28minutes/junit/AssertTest.java
### /test/com/in28minutes/junit/MyAssertTest.java

```java
package com.in28minutes.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AssertTest {
class MyAssertTest {

List<String> todos = Arrays.asList("AWS", "Azure", "DevOps");

@Test
public void test() {
boolean condn = true;
assertEquals(true, condn);
assertTrue(condn);
// assertFalse(condn);
void testAsserts() {
boolean test = todos.contains("AWS");//Result
boolean test2 = todos.contains("GCP");//Result

//assertEquals(true, test);
assertTrue(test);
assertFalse(test2);
//assertNull,assertNotNull
assertArrayEquals(new int[] {1,2}, new int[] {2, 1});

assertEquals(3, todos.size());
}

}
```
---

### /test/com/in28minutes/junit/MyMathTest.java
### /test/com/in28minutes/junit/MyBeforeAfterTest.java

```java
package com.in28minutes.junit;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
class MyBeforeAfterTest {

public class MyMathTest {
MyMath myMath = new MyMath();

@BeforeAll
static void beforeAll() {
System.out.println("beforeAll");
}

@BeforeEach
void beforeEach() {
System.out.println("BeforeEach");
}

@Before
public void before() {
System.out.println("Before");
@Test
void test1() {
System.out.println("test1");
}

@After
public void after() {
System.out.println("After");
@Test
void test2() {
System.out.println("test2");
}

@Test
void test3() {
System.out.println("test3");
}

@BeforeClass
public static void beforeClass() {
System.out.println("Before Class");
@AfterEach
void afterEach() {
System.out.println("AfterEach");
}

@AfterClass
public static void afterClass() {
System.out.println("After Class");
@AfterAll
static void afterAll() {
System.out.println("afterAll");
}

// MyMath.sum
// 1,2,3 => 6
}
```
---

### /test/com/in28minutes/junit/MyMathTest.java

```java
package com.in28minutes.junit;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MyMathTest {

private MyMath math = new MyMath();

@Test
public void sum_with3numbers() {
System.out.println("Test1");
assertEquals(6, myMath.sum(new int[] { 1, 2, 3 }));
void calculateSum_ThreeMemberArray() {
assertEquals(6, math.calculateSum(new int[] {1,2,3}));
}

@Test
public void sum_with1number() {
System.out.println("Test2");
assertEquals(3, myMath.sum(new int[] { 3 }));
void calculateSum_ZeroLengthArray() {
assertEquals(0, math.calculateSum(new int[] {}));
}

}
```
---
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.in28minutes.junit;

public class MyMath {
int sum(int[] numbers) {

//{1,2,3} => 1+2+3 = 6
public int calculateSum(int[] numbers) {

int sum = 0;
for (int i : numbers) {
sum += i;

for(int number:numbers) {
sum += number;
}

return sum;
}


}
Loading