forked from meissa/ModeratorElection
Test added
This commit is contained in:
parent
781756756d
commit
6fc8878599
3 changed files with 25 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
build/
|
build/
|
||||||
.gradle/
|
.gradle/
|
||||||
.idea/
|
.idea/
|
||||||
|
frontend/generated/
|
|
@ -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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/test/java/com/ModeratorElection/MainViewTest.java
Normal file
18
src/test/java/com/ModeratorElection/MainViewTest.java
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue