@Test public void isSeLinuxEnforced_yes() throws Exception { IDevice device = Mockito.mock(IDevice.class); AndroidDeviceImpl androidDeviceImpl = (AndroidDeviceImpl) context.getBean(IAndroidDevice.class); ShellOutputReceiver shellOutputReceiver = Mockito.spy( new ShellOutputReceiver()); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { isSeLinux = true; return null; } }).when(device).executeShellCommand("getenforce", shellOutputReceiver); Mockito.when(shellOutputReceiver.isSELinuxEnforce()).thenReturn(isSeLinux); boolean enforcement = androidDeviceImpl.isSeLinuxEnforced(device); assertTrue(enforcement == false); }
@Override public boolean isSeLinuxEnforced(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } ShellOutputReceiver shSELinux = new ShellOutputReceiver(); device.executeShellCommand("getenforce", shSELinux); boolean seLinuxEnforced = shSELinux.isSELinuxEnforce(); LOGGER.info("--->seLinuxEnforced:" + seLinuxEnforced); return seLinuxEnforced; }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isSeLinuxEnforced(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } ShellOutputReceiver shSELinux = new ShellOutputReceiver(); device.executeShellCommand("getenforce", shSELinux); boolean seLinuxEnforced = shSELinux.isSELinuxEnforce(); LOGGER.info("--->seLinuxEnforced:" + seLinuxEnforced); return seLinuxEnforced; } }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isSeLinuxEnforced(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } ShellOutputReceiver shSELinux = new ShellOutputReceiver(); device.executeShellCommand("getenforce", shSELinux); boolean seLinuxEnforced = shSELinux.isSELinuxEnforce(); LOGGER.info("--->seLinuxEnforced:" + seLinuxEnforced); return seLinuxEnforced; }  }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isSeLinuxEnforced(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } ShellOutputReceiver shSELinux = new ShellOutputReceiver(); device.executeShellCommand("getenforce", shSELinux); boolean seLinuxEnforced = shSELinux.isSELinuxEnforce(); LOGGER.info("--->seLinuxEnforced:" + seLinuxEnforced); return seLinuxEnforced; }  @Autowired void setAndroid(IAndroid android); RootCheckOutputReceiver makeRootCheckOutputReceiver(); @Override boolean isSeLinuxEnforced(IDevice device); @Override boolean isAndroidRooted(IDevice device); }
AndroidDeviceImpl implements IAndroidDevice { @Override public boolean isSeLinuxEnforced(IDevice device) throws Exception { if (device == null) { throw new Exception("device is null"); } ShellOutputReceiver shSELinux = new ShellOutputReceiver(); device.executeShellCommand("getenforce", shSELinux); boolean seLinuxEnforced = shSELinux.isSELinuxEnforce(); LOGGER.info("--->seLinuxEnforced:" + seLinuxEnforced); return seLinuxEnforced; }  @Autowired void setAndroid(IAndroid android); RootCheckOutputReceiver makeRootCheckOutputReceiver(); @Override boolean isSeLinuxEnforced(IDevice device); @Override boolean isAndroidRooted(IDevice device);  }