From 5d6c6afebad89b81d5f8e392e3038c92e4f9198d Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Tue, 21 Feb 2023 10:43:37 +0400 Subject: [PATCH] lab2: tests and fixes --- .../springip/controllers/TestController.java | 18 +++--- .../springip/SpringipApplicationTests.java | 61 +++++++++++++++++++ 2 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/example/springip/SpringipApplicationTests.java diff --git a/src/main/java/com/example/springip/controllers/TestController.java b/src/main/java/com/example/springip/controllers/TestController.java index 776daf9..1483007 100644 --- a/src/main/java/com/example/springip/controllers/TestController.java +++ b/src/main/java/com/example/springip/controllers/TestController.java @@ -15,11 +15,11 @@ public class TestController { return "Your number = " + random.nextInt(0,100); } - @GetMapping("/sum") - public String getSum(@RequestParam(name = "val1", defaultValue = "1") int val1, - @RequestParam(name="val2",defaultValue = "2") int val2) { - return "Your summa = " + (val1 + val2); - } +// @GetMapping("/sum") +// public String getSum(@RequestParam(name = "val1", defaultValue = "1") int val1, +// @RequestParam(name="val2",defaultValue = "2") int val2) { +// return "Your summa = " + (val1 + val2); +// } @GetMapping("/upperCase") public String toUpperCase(String word) { @@ -28,8 +28,8 @@ public class TestController { return "Incorrect word"; } - @GetMapping("/length") - public String length(String name) { - return "Length = " + name.length(); - } +// @GetMapping("/length") +// public String length(String name) { +// return "Length = " + name.length(); +// } } diff --git a/src/test/java/com/example/springip/SpringipApplicationTests.java b/src/test/java/com/example/springip/SpringipApplicationTests.java new file mode 100644 index 0000000..e63058c --- /dev/null +++ b/src/test/java/com/example/springip/SpringipApplicationTests.java @@ -0,0 +1,61 @@ +package com.example.springip; + +import com.example.springip.service.OperationService; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringipApplicationTests { + @Autowired + OperationService operationService; + + @Test + public void testSumString() { + final String res = (String) operationService.sum("Привет ", "Мир!"); + Assertions.assertEquals("Привет Мир!", res); + } + + @Test + public void testSumNum() { + final Integer res = (Integer) operationService.sum("1", "2"); + Assertions.assertEquals(3, res); + } + + @Test + public void testMulString() { + final String res = (String) operationService.mul("A", 4); + Assertions.assertEquals("AAAA", res); + } + + @Test + public void testMulNum() { + final Integer res = (Integer) operationService.mul("2", 4); + Assertions.assertEquals(8, res); + } + + @Test + public void testLengthString() { + final Integer res = (Integer) operationService.length("Hello"); + Assertions.assertEquals(5, res); + } + + @Test + public void testLengthNum() { + final Integer res = (Integer) operationService.length("777"); + Assertions.assertEquals(3, res); + } + @Test + public void testStWString() { + final boolean res = (boolean) operationService.startsWith("Orange","Or"); + Assertions.assertEquals(true, res); + } + + @Test + public void testStWNum() { + final boolean res = (boolean) operationService.startsWith("777","77"); + Assertions.assertEquals(true, res); + } + +}