From dd2e5b768ccefe022ab156b87295cfbce26ba9a9 Mon Sep 17 00:00:00 2001 From: joethei Date: Mon, 13 May 2019 18:13:12 +0200 Subject: [PATCH] + timeouts for testcases #SPM-23: add work 30m testing --- .../spm/baudas/analysis/ShoppingCartTest.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java index fa28aa9..ea22ac1 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java @@ -4,12 +4,15 @@ import org.junit.jupiter.api.Test; import java.io.File; import java.net.URL; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTimeout; /** * Test class for shopping-cart analysis. @@ -25,12 +28,14 @@ class ShoppingCartTest { assert url != null; ShoppingCart cart = new ShoppingCart(new File(url.getFile())); - Map, List> result = cart.getResult(); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik"))); - assertEquals(Collections.singletonList("Elektromaterial"), result.get(Collections.singletonList("Leuchten"))); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Schliesstechnik", "Renovierung"))); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); + AtomicReference, List>> result = new AtomicReference<>(); + assertTimeout(Duration.ofSeconds(4), () -> result.set(cart.getResult())); + + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get().get(Collections.singletonList("Leuchten"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Schliesstechnik", "Renovierung"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); } @Test @@ -39,12 +44,14 @@ class ShoppingCartTest { assert url != null; ShoppingCart cart = new ShoppingCart(new File(url.getFile())); - Map, List> result = cart.getResult(); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); - assertEquals(Collections.singletonList("Elektromaterial"), result.get(Arrays.asList("Renovierung", "Leuchten"))); - assertEquals(Collections.singletonList("Sanitaermaterial"), result.get(Arrays.asList("Fliesen", "Armaturen"))); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Renovierung"))); + AtomicReference, List>> result = new AtomicReference<>(); + assertTimeout(Duration.ofSeconds(4), () -> result.set(cart.getResult())); + + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get().get(Arrays.asList("Renovierung", "Leuchten"))); + assertEquals(Collections.singletonList("Sanitaermaterial"), result.get().get(Arrays.asList("Fliesen", "Armaturen"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Renovierung"))); } @@ -54,12 +61,14 @@ class ShoppingCartTest { assert url != null; ShoppingCart cart = new ShoppingCart(new File(url.getFile())); - Map, List> result = cart.getResult(); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); - assertEquals(Collections.singletonList("Sanitaermaterial"), result.get(Arrays.asList("Eisenwaren", "Fliesen", "Armaturen"))); - assertEquals(Collections.singletonList("Elektromaterial"), result.get(Arrays.asList("Renovierung", "Leuchten"))); - assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); + AtomicReference, List>> result = new AtomicReference<>(); + assertTimeout(Duration.ofSeconds(5), () -> result.set(cart.getResult())); + + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); + assertEquals(Collections.singletonList("Sanitaermaterial"), result.get().get(Arrays.asList("Eisenwaren", "Fliesen", "Armaturen"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get().get(Arrays.asList("Renovierung", "Leuchten"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get().get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); }