Test added

This commit is contained in:
Mirco 2024-06-13 12:57:52 +02:00
parent 781756756d
commit 6fc8878599
3 changed files with 25 additions and 5 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
build/ build/
.gradle/ .gradle/
.idea/ .idea/
frontend/generated/

View file

@ -38,11 +38,8 @@ public class MainView extends VerticalLayout {
Button electNow = new Button("Elect!", buttonClickEvent -> { Button electNow = new Button("Elect!", buttonClickEvent -> {
try { try {
ArrayList checkboxSelectedMembers = new ArrayList(checkboxGroup.getSelectedItems());
int sizeArrayListSelectedMembers = checkboxSelectedMembers.size();
int random = (int) (Math.random() * sizeArrayListSelectedMembers);
Notification moderatorNotification = new Notification() Notification moderatorNotification = new Notification()
.show("Nächster Moderator: " + checkboxSelectedMembers.get(random)); .show("Nächster Moderator: " + electMember(selectMemberItemsNameslist));
moderatorNotification.setPosition(Notification.Position.BOTTOM_CENTER); moderatorNotification.setPosition(Notification.Position.BOTTOM_CENTER);
} catch(Exception exceptionEvent) { } catch(Exception exceptionEvent) {
Notification errorNotification = new Notification(); Notification errorNotification = new Notification();
@ -73,4 +70,8 @@ public class MainView extends VerticalLayout {
add(electNow); add(electNow);
} }
private String electMember(List<String> members){
return members.get((int)(Math.random() * members.size()));
}
} }

View file

@ -0,0 +1,18 @@
package com.ModeratorElection;
import com.vaadin.flow.component.checkbox.CheckboxGroup;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
//@SpringBootTest
public class MainViewTest {
@Test
void mainViewConstructor() {
MainView sut = new MainView("Harry,Sven,Ida");
CheckboxGroup cgroupTest = (CheckboxGroup) sut.getChildren().filter(child -> child instanceof CheckboxGroup).findAny().orElse(null);
int cgroupTestSelectedItemsSize = cgroupTest.getSelectedItems().size();
Assertions.assertEquals(3,cgroupTestSelectedItemsSize);
}
}