@Test void cpuUsageIsSetForMinAndMaxOnTheFirstRun() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(10f)); assertThat(collector.getMaxCpuUsage(), is(10f)); assertThat(collector.getTotalCpuUsage(), is(10f)); }
@Test void getNewCpuInformationData() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(1)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(4L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(5f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(6f)); assertThat(cpuInformationData.getMinCpuUsage(), is(7f)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(8L)); } }
@Test void collectorClassIsResetted() throws Exception { CpuInformationData collector = (CpuInformationData) this.cut.getSystemSensorData(); collector.setCount(1); collector.setPlatformIdent(2L); collector.setSensorTypeIdent(3L); collector.setProcessCpuTime(4L); collector.setTotalCpuUsage(5f); collector.setMaxCpuUsage(6f); collector.setMinCpuUsage(7f); collector.setTimeStamp(new Timestamp(8L)); this.cut.reset(); CpuInformationData cpuInformationData = (CpuInformationData) this.cut.get(); assertThat(cpuInformationData.getCount(), is(0)); assertThat(cpuInformationData.getPlatformIdent(), is(2L)); assertThat(cpuInformationData.getSensorTypeIdent(), is(3L)); assertThat(cpuInformationData.getProcessCpuTime(), is(0L)); assertThat(cpuInformationData.getTotalCpuUsage(), is(0f)); assertThat(cpuInformationData.getMaxCpuUsage(), is(0f)); assertThat(cpuInformationData.getMinCpuUsage(), is(Float.MAX_VALUE)); assertThat(cpuInformationData.getTimeStamp().getTime(), is(not(8L))); } }
@Test void countIsIncremented() { this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getCount(), is(2)); } }
@Test void cpuUsageIsCalculated() { when(this.osBean.retrieveCpuUsage()).thenReturn(10f).thenReturn(9f).thenReturn(11f).thenReturn(10f); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getMinCpuUsage(), is(9f)); assertThat(collector.getMaxCpuUsage(), is(11f)); assertThat(collector.getTotalCpuUsage(), is(40f)); }
@Test void updateProcessCpuTime() { when(this.osBean.getProcessCpuTime()).thenReturn(10L).thenReturn(9L).thenReturn(11L).thenReturn(10L); this.cut.gather(); this.cut.gather(); this.cut.gather(); this.cut.gather(); CpuInformationData collector = (CpuInformationData) this.cut.get(); assertThat(collector.getProcessCpuTime(), is(11L)); }