ResourceCheck { public Boolean isEnough(List<Protos.Resource> resourcesList, double requiredValue) { Protos.Resource resource = getResource(resourcesList); return resource != null && resource.getScalar() != null && resource.getScalar().getValue() >= requiredValue; } ResourceCheck(String resourceName); Boolean isEnough(List<Protos.Resource> resourcesList, double requiredValue);  }
@Test public void givenExactResourceShouldAccept() { ResourceCheck resourceCheck = new ResourceCheck(Resources.RESOURCE_CPUS); List<Protos.Resource> resourceList = new ArrayList<>(); resourceList.add(Resources.cpus(1, "*")); assertTrue(resourceCheck.isEnough(resourceList, 1)); }
@Test public void givenMoreResourceShouldAccept() { ResourceCheck resourceCheck = new ResourceCheck(Resources.RESOURCE_CPUS); List<Protos.Resource> resourceList = new ArrayList<>(); resourceList.add(Resources.cpus(10, "*")); assertTrue(resourceCheck.isEnough(resourceList, 1)); }
@Test public void givenMultipleResourceShouldAccept() { ResourceCheck resourceCheck = new ResourceCheck(Resources.RESOURCE_CPUS); List<Protos.Resource> resourceList = new ArrayList<>(); resourceList.add(Resources.mem(10, "*")); resourceList.add(Resources.disk(10, "*")); resourceList.add(Resources.cpus(10, "*")); assertTrue(resourceCheck.isEnough(resourceList, 1)); }
@Test public void givenTooLittleResourceShouldDeny() { ResourceCheck resourceCheck = new ResourceCheck(Resources.RESOURCE_CPUS); List<Protos.Resource> resourceList = new ArrayList<>(); resourceList.add(Resources.cpus(0.1, "*")); assertFalse(resourceCheck.isEnough(resourceList, 1)); }
@Test public void shouldNotCrashWhenThereIsNoResource() { ResourceCheck resourceCheck = new ResourceCheck(Resources.RESOURCE_CPUS); List<Protos.Resource> resourceList = new ArrayList<>(); assertFalse(resourceCheck.isEnough(resourceList, 1)); }