@Test public void create_Test(){ Date date = new Date(); Profile profile = Mockito.mock(Profile.class); Mockito.when(profile.getPowerGpsActive()).thenReturn(1.0); GpsInfo gpsInfo01 = Mockito.mock(GpsInfo.class); Mockito.when(gpsInfo01.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(gpsInfo01.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(gpsInfo01.getGpsState()).thenReturn(GpsState.GPS_ACTIVE); GpsInfo gpsInfo02 = Mockito.mock(GpsInfo.class); Mockito.when(profile.getPowerGpsStandby()).thenReturn(0.5); Mockito.when(gpsInfo02.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(gpsInfo02.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(gpsInfo02.getGpsState()).thenReturn(GpsState.GPS_STANDBY); List<GpsInfo> gpsList = new ArrayList<GpsInfo>(); gpsList.add(gpsInfo01); gpsList.add(gpsInfo02); CameraInfo cameraInfo01 = Mockito.mock(CameraInfo.class); Mockito.when(cameraInfo01.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(cameraInfo01.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(cameraInfo01.getCameraState()).thenReturn(CameraState.CAMERA_ON); Mockito.when(profile.getPowerCameraOn()).thenReturn(0.3); List<CameraInfo> cameraList = new ArrayList<CameraInfo>(); cameraList.add(cameraInfo01); BluetoothInfo bluetoothInfo01 = Mockito.mock(BluetoothInfo.class); Mockito.when(bluetoothInfo01.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(bluetoothInfo01.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(bluetoothInfo01.getBluetoothState()).thenReturn(BluetoothState.BLUETOOTH_CONNECTED); BluetoothInfo bluetoothInfo02 = Mockito.mock(BluetoothInfo.class); Mockito.when(bluetoothInfo02.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(bluetoothInfo02.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(bluetoothInfo02.getBluetoothState()).thenReturn(BluetoothState.BLUETOOTH_DISCONNECTED); List<BluetoothInfo> bluetoothList = new ArrayList<BluetoothInfo>(); bluetoothList.add(bluetoothInfo01); bluetoothList.add(bluetoothInfo02); Mockito.when(profile.getPowerBluetoothActive()).thenReturn(1.0); Mockito.when(profile.getPowerBluetoothStandby()).thenReturn(0.5); ScreenStateInfo screenStateInfo01 = Mockito.mock(ScreenStateInfo.class); Mockito.when(screenStateInfo01.getBeginTimeStamp()).thenReturn(date.getTime()+0.0); Mockito.when(screenStateInfo01.getEndTimeStamp()).thenReturn(date.getTime()+1000.0); Mockito.when(screenStateInfo01.getScreenState()).thenReturn(ScreenState.SCREEN_ON); List<ScreenStateInfo> screenStateList = new ArrayList<ScreenStateInfo>(); screenStateList.add(screenStateInfo01); Mockito.when(profile.getPowerScreenOn()).thenReturn(0.3); EnergyModel model = eMdlFctr.create(profile, 0.0, gpsList, cameraList, bluetoothList, screenStateList); assertEquals(1000.0,model.getGpsActiveEnergy(),0.0); assertEquals(500.0,model.getGpsStandbyEnergy(),0.0); assertEquals(1500.0,model.getTotalGpsEnergy(),0.0); assertEquals(300.0,model.getTotalCameraEnergy(),0.0); assertEquals(1000.0,model.getBluetoothActiveEnergy(),0.0); assertEquals(500.0,model.getBluetoothStandbyEnergy(),0.0); assertEquals(1500.0,model.getTotalBluetoothEnergy(),0.0); assertEquals(300.0,model.getTotalScreenEnergy(),0.0); }
@Override public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) { double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0; double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy =0; double totalScreenEnergy = 0; EnergyModel model = new EnergyModel(); model.setTotalRrcEnergy(totalRrcEnergy); Iterator<GpsInfo> gpsIter = gpsinfos.iterator(); if (gpsIter.hasNext()) { while (gpsIter.hasNext()) { GpsInfo gps = gpsIter.next(); GpsState gpsState = gps.getGpsState(); switch (gpsState) { case GPS_ACTIVE: gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; case GPS_STANDBY: gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; default: break; } } } totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy; Iterator<CameraInfo> cameraIter = camerainfos.iterator(); if (cameraIter.hasNext()) { while (cameraIter.hasNext()) { CameraInfo camera = cameraIter.next(); CameraInfo.CameraState cameraState = camera.getCameraState(); if (cameraState == CameraInfo.CameraState.CAMERA_ON) { totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp()); } } } Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator(); if (bluetoothIter.hasNext()) { while (bluetoothIter.hasNext()) { BluetoothInfo btInfo = bluetoothIter.next(); if(btInfo == null || btInfo.getBluetoothState() == null) { continue; } switch (btInfo.getBluetoothState()) { case BLUETOOTH_CONNECTED: bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; case BLUETOOTH_DISCONNECTED: bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; default: break; } } } totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy; Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator(); if (screenIter.hasNext()) { while (screenIter.hasNext()) { ScreenStateInfo screenInfo = screenIter.next(); if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) { totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp()); } } } model.setBluetoothActiveEnergy(bluetoothActiveEnergy); model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy); model.setGpsActiveEnergy(gpsActiveEnergy); model.setGpsStandbyEnergy(gpsStandbyEnergy); model.setTotalBluetoothEnergy(totalBluetoothEnergy); model.setTotalCameraEnergy(totalCameraEnergy); model.setTotalGpsEnergy(totalGpsEnergy); model.setTotalRrcEnergy(totalRrcEnergy); model.setTotalScreenEnergy(totalScreenEnergy); return model; }
EnergyModelFactoryImpl implements IEnergyModelFactory { @Override public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) { double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0; double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy =0; double totalScreenEnergy = 0; EnergyModel model = new EnergyModel(); model.setTotalRrcEnergy(totalRrcEnergy); Iterator<GpsInfo> gpsIter = gpsinfos.iterator(); if (gpsIter.hasNext()) { while (gpsIter.hasNext()) { GpsInfo gps = gpsIter.next(); GpsState gpsState = gps.getGpsState(); switch (gpsState) { case GPS_ACTIVE: gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; case GPS_STANDBY: gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; default: break; } } } totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy; Iterator<CameraInfo> cameraIter = camerainfos.iterator(); if (cameraIter.hasNext()) { while (cameraIter.hasNext()) { CameraInfo camera = cameraIter.next(); CameraInfo.CameraState cameraState = camera.getCameraState(); if (cameraState == CameraInfo.CameraState.CAMERA_ON) { totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp()); } } } Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator(); if (bluetoothIter.hasNext()) { while (bluetoothIter.hasNext()) { BluetoothInfo btInfo = bluetoothIter.next(); if(btInfo == null || btInfo.getBluetoothState() == null) { continue; } switch (btInfo.getBluetoothState()) { case BLUETOOTH_CONNECTED: bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; case BLUETOOTH_DISCONNECTED: bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; default: break; } } } totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy; Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator(); if (screenIter.hasNext()) { while (screenIter.hasNext()) { ScreenStateInfo screenInfo = screenIter.next(); if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) { totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp()); } } } model.setBluetoothActiveEnergy(bluetoothActiveEnergy); model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy); model.setGpsActiveEnergy(gpsActiveEnergy); model.setGpsStandbyEnergy(gpsStandbyEnergy); model.setTotalBluetoothEnergy(totalBluetoothEnergy); model.setTotalCameraEnergy(totalCameraEnergy); model.setTotalGpsEnergy(totalGpsEnergy); model.setTotalRrcEnergy(totalRrcEnergy); model.setTotalScreenEnergy(totalScreenEnergy); return model; } }
EnergyModelFactoryImpl implements IEnergyModelFactory { @Override public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) { double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0; double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy =0; double totalScreenEnergy = 0; EnergyModel model = new EnergyModel(); model.setTotalRrcEnergy(totalRrcEnergy); Iterator<GpsInfo> gpsIter = gpsinfos.iterator(); if (gpsIter.hasNext()) { while (gpsIter.hasNext()) { GpsInfo gps = gpsIter.next(); GpsState gpsState = gps.getGpsState(); switch (gpsState) { case GPS_ACTIVE: gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; case GPS_STANDBY: gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; default: break; } } } totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy; Iterator<CameraInfo> cameraIter = camerainfos.iterator(); if (cameraIter.hasNext()) { while (cameraIter.hasNext()) { CameraInfo camera = cameraIter.next(); CameraInfo.CameraState cameraState = camera.getCameraState(); if (cameraState == CameraInfo.CameraState.CAMERA_ON) { totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp()); } } } Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator(); if (bluetoothIter.hasNext()) { while (bluetoothIter.hasNext()) { BluetoothInfo btInfo = bluetoothIter.next(); if(btInfo == null || btInfo.getBluetoothState() == null) { continue; } switch (btInfo.getBluetoothState()) { case BLUETOOTH_CONNECTED: bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; case BLUETOOTH_DISCONNECTED: bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; default: break; } } } totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy; Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator(); if (screenIter.hasNext()) { while (screenIter.hasNext()) { ScreenStateInfo screenInfo = screenIter.next(); if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) { totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp()); } } } model.setBluetoothActiveEnergy(bluetoothActiveEnergy); model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy); model.setGpsActiveEnergy(gpsActiveEnergy); model.setGpsStandbyEnergy(gpsStandbyEnergy); model.setTotalBluetoothEnergy(totalBluetoothEnergy); model.setTotalCameraEnergy(totalCameraEnergy); model.setTotalGpsEnergy(totalGpsEnergy); model.setTotalRrcEnergy(totalRrcEnergy); model.setTotalScreenEnergy(totalScreenEnergy); return model; }  }
EnergyModelFactoryImpl implements IEnergyModelFactory { @Override public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) { double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0; double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy =0; double totalScreenEnergy = 0; EnergyModel model = new EnergyModel(); model.setTotalRrcEnergy(totalRrcEnergy); Iterator<GpsInfo> gpsIter = gpsinfos.iterator(); if (gpsIter.hasNext()) { while (gpsIter.hasNext()) { GpsInfo gps = gpsIter.next(); GpsState gpsState = gps.getGpsState(); switch (gpsState) { case GPS_ACTIVE: gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; case GPS_STANDBY: gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; default: break; } } } totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy; Iterator<CameraInfo> cameraIter = camerainfos.iterator(); if (cameraIter.hasNext()) { while (cameraIter.hasNext()) { CameraInfo camera = cameraIter.next(); CameraInfo.CameraState cameraState = camera.getCameraState(); if (cameraState == CameraInfo.CameraState.CAMERA_ON) { totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp()); } } } Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator(); if (bluetoothIter.hasNext()) { while (bluetoothIter.hasNext()) { BluetoothInfo btInfo = bluetoothIter.next(); if(btInfo == null || btInfo.getBluetoothState() == null) { continue; } switch (btInfo.getBluetoothState()) { case BLUETOOTH_CONNECTED: bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; case BLUETOOTH_DISCONNECTED: bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; default: break; } } } totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy; Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator(); if (screenIter.hasNext()) { while (screenIter.hasNext()) { ScreenStateInfo screenInfo = screenIter.next(); if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) { totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp()); } } } model.setBluetoothActiveEnergy(bluetoothActiveEnergy); model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy); model.setGpsActiveEnergy(gpsActiveEnergy); model.setGpsStandbyEnergy(gpsStandbyEnergy); model.setTotalBluetoothEnergy(totalBluetoothEnergy); model.setTotalCameraEnergy(totalCameraEnergy); model.setTotalGpsEnergy(totalGpsEnergy); model.setTotalRrcEnergy(totalRrcEnergy); model.setTotalScreenEnergy(totalScreenEnergy); return model; }  @Override EnergyModel create(Profile profile, double totalRrcEnergy,
			List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos,
			List<BluetoothInfo> bluetoothinfos,
			List<ScreenStateInfo> screenstateinfos); }
EnergyModelFactoryImpl implements IEnergyModelFactory { @Override public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) { double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0; double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy =0; double totalScreenEnergy = 0; EnergyModel model = new EnergyModel(); model.setTotalRrcEnergy(totalRrcEnergy); Iterator<GpsInfo> gpsIter = gpsinfos.iterator(); if (gpsIter.hasNext()) { while (gpsIter.hasNext()) { GpsInfo gps = gpsIter.next(); GpsState gpsState = gps.getGpsState(); switch (gpsState) { case GPS_ACTIVE: gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; case GPS_STANDBY: gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp()); break; default: break; } } } totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy; Iterator<CameraInfo> cameraIter = camerainfos.iterator(); if (cameraIter.hasNext()) { while (cameraIter.hasNext()) { CameraInfo camera = cameraIter.next(); CameraInfo.CameraState cameraState = camera.getCameraState(); if (cameraState == CameraInfo.CameraState.CAMERA_ON) { totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp()); } } } Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator(); if (bluetoothIter.hasNext()) { while (bluetoothIter.hasNext()) { BluetoothInfo btInfo = bluetoothIter.next(); if(btInfo == null || btInfo.getBluetoothState() == null) { continue; } switch (btInfo.getBluetoothState()) { case BLUETOOTH_CONNECTED: bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; case BLUETOOTH_DISCONNECTED: bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp()); break; default: break; } } } totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy; Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator(); if (screenIter.hasNext()) { while (screenIter.hasNext()) { ScreenStateInfo screenInfo = screenIter.next(); if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) { totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp()); } } } model.setBluetoothActiveEnergy(bluetoothActiveEnergy); model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy); model.setGpsActiveEnergy(gpsActiveEnergy); model.setGpsStandbyEnergy(gpsStandbyEnergy); model.setTotalBluetoothEnergy(totalBluetoothEnergy); model.setTotalCameraEnergy(totalCameraEnergy); model.setTotalGpsEnergy(totalGpsEnergy); model.setTotalRrcEnergy(totalRrcEnergy); model.setTotalScreenEnergy(totalScreenEnergy); return model; }  @Override EnergyModel create(Profile profile, double totalRrcEnergy,
			List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos,
			List<BluetoothInfo> bluetoothinfos,
			List<ScreenStateInfo> screenstateinfos);  }