Skip to content

Commit ccc77f5

Browse files
create vendor service factory
1 parent 57fb11a commit ccc77f5

File tree

5 files changed

+90
-10
lines changed

5 files changed

+90
-10
lines changed

app/build.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Build Properties
2-
#Thu Dec 28 08:32:26 EST 2017
2+
#Fri Dec 29 08:07:50 EST 2017
33
version_minor=8
4-
version_build=5
4+
version_build=6
55
version_patch=8
6-
version_major=1
76
version_store=34
7+
version_major=1

app/src/main/java/com/vrem/wifianalyzer/MainContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
import com.vrem.wifianalyzer.settings.Repository;
2929
import com.vrem.wifianalyzer.settings.Settings;
30-
import com.vrem.wifianalyzer.vendor.model.VendorDB;
3130
import com.vrem.wifianalyzer.vendor.model.VendorService;
31+
import com.vrem.wifianalyzer.vendor.model.VendorServiceFactory;
3232
import com.vrem.wifianalyzer.wifi.filter.adapter.FilterAdapter;
3333
import com.vrem.wifianalyzer.wifi.scanner.Scanner;
3434

@@ -112,7 +112,7 @@ void initialize(@NonNull MainActivity mainActivity, boolean largeScreen) {
112112
setMainActivity(mainActivity);
113113
setConfiguration(currentConfiguration);
114114
setSettings(currentSettings);
115-
setVendorService(new VendorDB(mainActivity.getResources()));
115+
setVendorService(VendorServiceFactory.makeVendorService(mainActivity.getResources()));
116116
setScanner(new Scanner(wifiManager, handler, currentSettings));
117117
setFilterAdapter(new FilterAdapter(currentSettings));
118118
}

app/src/main/java/com/vrem/wifianalyzer/vendor/model/VendorDB.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@
3434
import java.util.Map;
3535
import java.util.TreeMap;
3636

37-
public class VendorDB implements VendorService {
37+
class VendorDB implements VendorService {
3838
private final Resources resources;
39-
private final Map<String, List<String>> vendors = new TreeMap<>();
40-
private final Map<String, String> macs = new TreeMap<>();
39+
private final Map<String, List<String>> vendors;
40+
private final Map<String, String> macs;
41+
private boolean loaded;
4142

42-
public VendorDB(@NonNull Resources resources) {
43+
VendorDB(@NonNull Resources resources) {
4344
this.resources = resources;
45+
this.vendors = new TreeMap<>();
46+
this.macs = new TreeMap<>();
47+
this.loaded = false;
4448
}
4549

4650
@NonNull
@@ -87,7 +91,8 @@ Map<String, String> getMacs() {
8791
}
8892

8993
private void load(@NonNull Resources resources) {
90-
if (vendors.isEmpty()) {
94+
if (!loaded) {
95+
loaded = true;
9196
String[] lines = VendorUtils.readFile(resources, R.raw.data);
9297
for (String data : lines) {
9398
if (data != null) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2017 VREM Software Development <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
19+
package com.vrem.wifianalyzer.vendor.model;
20+
21+
import android.content.res.Resources;
22+
import android.support.annotation.NonNull;
23+
24+
public class VendorServiceFactory {
25+
private VendorServiceFactory() {
26+
throw new IllegalStateException("Factory class");
27+
}
28+
29+
public static VendorService makeVendorService(@NonNull Resources resources) {
30+
return new VendorDB(resources);
31+
}
32+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2017 VREM Software Development <[email protected]>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
19+
package com.vrem.wifianalyzer.vendor.model;
20+
21+
import android.content.res.Resources;
22+
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.mockito.Mock;
26+
import org.mockito.junit.MockitoJUnitRunner;
27+
28+
import static org.junit.Assert.assertTrue;
29+
30+
@RunWith(MockitoJUnitRunner.class)
31+
public class VendorServiceFactoryTest {
32+
33+
@Mock
34+
private Resources resources;
35+
36+
@Test
37+
public void testMakeVendorService() throws Exception {
38+
// execute
39+
VendorService actual = VendorServiceFactory.makeVendorService(resources);
40+
// validate
41+
assertTrue(actual instanceof VendorDB);
42+
}
43+
}

0 commit comments

Comments
 (0)