@Test public void matchDevice_onlyManf_matches_returnsTrue() { Device device = new Device("xiaomi", null); PowerMockito.spy(RuleMatcher.class); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("xiaomi"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isTrue(); }
@Test public void matchDevice_onlyModel_matches_returnsTrue() { Device device = new Device(null, "mi3"); PowerMockito.spy(RuleMatcher.class); Mockito.when(RuleMatcher.getModel()).thenReturn("mi3"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isTrue(); }
@Test public void matchDevice_onlyModel_doesNotMatch_returnsFalse() { Device device = new Device(null, "mi3"); PowerMockito.spy(RuleMatcher.class); Mockito.when(RuleMatcher.getModel()).thenReturn("galaxys4"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isFalse(); }
@Test public void matchDevice_onlyManf_doesNotMatch_returnsFalse() { Device device = new Device("xiaomi", null); PowerMockito.spy(RuleMatcher.class); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("samsung"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isFalse(); }
@Test public void matchDevice_both_manfDoesNotMatch_returnsFalse() { Device device = new Device("xiaomi", "mi3"); PowerMockito.spy(RuleMatcher.class); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("samsung"); Mockito.when(RuleMatcher.getModel()).thenReturn("mi3"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isFalse(); }
@Test public void matchDevice_both_modelDoesNotMatch_returnsFalse() { Device device = new Device("xiaomi", "mi3"); PowerMockito.spy(RuleMatcher.class); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("xiaomi"); Mockito.when(RuleMatcher.getModel()).thenReturn("mi4"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isFalse(); }
@Test public void matchDevice_both_matches_returnsTrue() { Device device = new Device("xiaomi", "mi3"); PowerMockito.spy(RuleMatcher.class); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("xiaomi"); Mockito.when(RuleMatcher.getModel()).thenReturn("mi3"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isTrue(); }
@Test public void matchDevice_both_bothDoNotMatch_returnsFalse() { Device device = new Device("xiaomi", "mi3"); PowerMockito.spy(RuleMatcher.class); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("samsung"); Mockito.when(RuleMatcher.getModel()).thenReturn("galaxys4"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); boolean result = RuleMatcher.matchDevice(new ArrayList<Device>(deviceList)); assertThat(result).isFalse(); }
@Test public void matchRule_allCheck_incorrect_returnsFalse() { PowerMockito.spy(RuleMatcher.class); PowerMockito.spy(System.class); initializeCurrentTimeBasic(); intializeBuildVersion18AndVersionCode100(); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("samsung"); Mockito.when(RuleMatcher.getModel()).thenReturn("galaxys4"); Device device = new Device("xiaomi", "mi3"); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); Mockito.when(RuleMatcher.getBuildType()).thenReturn("release"); Rule rule = new Rule(Toggle.DISABLED, null, new Value(14, 22, 90, 110, 1450000000000L, 1459990000000L, "release", deviceList)); boolean result = RuleMatcher.matchRule(rule); assertThat(result).isFalse(); }
@Test public void matchRule_allCheck_correct_returnsTrue() { PowerMockito.spy(RuleMatcher.class); PowerMockito.spy(System.class); initializeCurrentTimeBasic(); intializeBuildVersion18AndVersionCode100(); PowerMockito.mockStatic(TextUtils.class); Mockito.when(TextUtils.isEmpty(Mockito.anyString())).thenReturn(false); Mockito.when(RuleMatcher.getManufacturer()).thenReturn("xiaomi"); Mockito.when(RuleMatcher.getModel()).thenReturn("mi3"); // just for xiaomi devices Device device = new Device("xiaomi", null); List<Device> deviceList = new ArrayList<>(); deviceList.add(device); Mockito.when(RuleMatcher.getBuildType()).thenReturn("release"); Rule rule = new Rule(Toggle.DISABLED, null, new Value(14, 22, 90, 110, 1450000000000L, 1459990000000L, "release", deviceList)); boolean result = RuleMatcher.matchRule(rule); assertThat(result).isTrue(); }