Address review comments

This commit is contained in:
goapunk
2018-04-24 16:05:46 +02:00
parent ac1bfcae60
commit fe213d46e3
2 changed files with 41 additions and 46 deletions

View File

@@ -21,8 +21,8 @@ public class TestDataActivity extends BriarActivity {
@Inject @Inject
TestDataCreator testDataCreator; TestDataCreator testDataCreator;
private TextView[] textviews = new TextView[5]; private TextView[] textViews = new TextView[5];
private SeekBar[] seekbars = new SeekBar[5]; private SeekBar[] seekBars = new SeekBar[5];
@Override @Override
public void onCreate(Bundle bundle) { public void onCreate(Bundle bundle) {
@@ -35,20 +35,20 @@ public class TestDataActivity extends BriarActivity {
} }
setContentView(R.layout.activity_test_data); setContentView(R.layout.activity_test_data);
textviews[0] = findViewById(R.id.textViewContactsSb); textViews[0] = findViewById(R.id.textViewContactsSb);
textviews[1] = findViewById(R.id.textViewMessagesSb); textViews[1] = findViewById(R.id.textViewMessagesSb);
textviews[2] = findViewById(R.id.TextViewBlogPostsSb); textViews[2] = findViewById(R.id.TextViewBlogPostsSb);
textviews[3] = findViewById(R.id.TextViewForumsSb); textViews[3] = findViewById(R.id.TextViewForumsSb);
textviews[4] = findViewById(R.id.TextViewForumMessagesSb); textViews[4] = findViewById(R.id.TextViewForumMessagesSb);
seekbars[0] = findViewById(R.id.seekBarContacts); seekBars[0] = findViewById(R.id.seekBarContacts);
seekbars[1] = findViewById(R.id.seekBarMessages); seekBars[1] = findViewById(R.id.seekBarMessages);
seekbars[2] = findViewById(R.id.seekBarBlogPosts); seekBars[2] = findViewById(R.id.seekBarBlogPosts);
seekbars[3] = findViewById(R.id.seekBarForums); seekBars[3] = findViewById(R.id.seekBarForums);
seekbars[4] = findViewById(R.id.seekBarForumMessages); seekBars[4] = findViewById(R.id.seekBarForumMessages);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
final TextView textView = textviews[i]; final TextView textView = textViews[i];
seekbars[i].setOnSeekBarChangeListener( seekBars[i].setOnSeekBarChangeListener(
new OnSeekBarChangeListener() { new OnSeekBarChangeListener() {
@Override @Override
public void onProgressChanged(SeekBar seekBar, public void onProgressChanged(SeekBar seekBar,
@@ -75,9 +75,9 @@ public class TestDataActivity extends BriarActivity {
} }
private void createTestData() { private void createTestData() {
testDataCreator.createTestData(seekbars[0].getProgress(), testDataCreator.createTestData(seekBars[0].getProgress(),
seekbars[1].getProgress(), seekbars[2].getProgress(), seekBars[1].getProgress(), seekBars[2].getProgress(),
seekbars[3].getProgress(), seekbars[4].getProgress()); seekBars[3].getProgress(), seekBars[4].getProgress());
Intent intent = new Intent(this, NavDrawerActivity.class); Intent intent = new Intent(this, NavDrawerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent); startActivity(intent);

View File

@@ -86,12 +86,6 @@ public class TestDataCreatorImpl implements TestDataCreator {
private final Random random = new Random(); private final Random random = new Random();
private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>(); private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>();
private int numContacts = 20;
private int numPrivateMsgs = 15;
private int numBlogPosts = 30;
private int numForums = 3;
private int numForumPosts = 30;
@Inject @Inject
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock, TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
PrivateMessageFactory privateMessageFactory, PrivateMessageFactory privateMessageFactory,
@@ -119,20 +113,12 @@ public class TestDataCreatorImpl implements TestDataCreator {
this.ioExecutor = ioExecutor; this.ioExecutor = ioExecutor;
} }
public void createTestData(int numContacts, int numPrivateMsgs, int numBlogPosts, int numForums, public void createTestData(int numContacts, int numPrivateMsgs,
int numForumPosts){ int numBlogPosts, int numForums, int numForumPosts) {
this.numContacts = numContacts;
this.numPrivateMsgs = numPrivateMsgs;
this.numBlogPosts = numBlogPosts;
this.numForums = numForums;
this.numForumPosts = numForumPosts;
createTestData();
}
public void createTestData() {
ioExecutor.execute(() -> { ioExecutor.execute(() -> {
try { try {
createTestDataOnDbExecutor(); createTestDataOnDbExecutor(numContacts, numPrivateMsgs,
numBlogPosts, numForums, numForumPosts);
} catch (DbException e) { } catch (DbException e) {
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, "Creating test data failed", e); LOG.log(WARNING, "Creating test data failed", e);
@@ -140,19 +126,25 @@ public class TestDataCreatorImpl implements TestDataCreator {
}); });
} }
public void createTestData() {
createTestData(20, 15, 30, 3, 30);
}
@IoExecutor @IoExecutor
private void createTestDataOnDbExecutor() throws DbException { private void createTestDataOnDbExecutor(int numContacts, int numPrivateMsgs,
List<Contact> contacts = createContacts(); int numBlogPosts, int numForums, int numForumPosts)
createPrivateMessages(contacts); throws DbException {
createBlogPosts(contacts); List<Contact> contacts = createContacts(numContacts);
List<Forum> forums = createForums(contacts); createPrivateMessages(contacts, numPrivateMsgs);
createBlogPosts(contacts, numBlogPosts);
List<Forum> forums = createForums(contacts, numForums, numForumPosts);
for (Forum forum : forums) { for (Forum forum : forums) {
createRandomForumPosts(forum, contacts); createRandomForumPosts(forum, contacts, numForumPosts);
} }
} }
private List<Contact> createContacts() throws DbException { private List<Contact> createContacts(int numContacts) throws DbException {
List<Contact> contacts = new ArrayList<>(numContacts); List<Contact> contacts = new ArrayList<>(numContacts);
LocalAuthor localAuthor = identityManager.getLocalAuthor(); LocalAuthor localAuthor = identityManager.getLocalAuthor();
for (int i = 0; i < numContacts; i++) { for (int i = 0; i < numContacts; i++) {
@@ -281,7 +273,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
return sb.toString(); return sb.toString();
} }
private void createPrivateMessages(List<Contact> contacts) private void createPrivateMessages(List<Contact> contacts,
int numPrivateMsgs)
throws DbException { throws DbException {
for (Contact contact : contacts) { for (Contact contact : contacts) {
Group group = messagingManager.getContactGroup(contact); Group group = messagingManager.getContactGroup(contact);
@@ -323,7 +316,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
} }
private void createBlogPosts(List<Contact> contacts) private void createBlogPosts(List<Contact> contacts, int numBlogPosts)
throws DbException { throws DbException {
for (int i = 0; i < numBlogPosts; i++) { for (int i = 0; i < numBlogPosts; i++) {
Contact contact = contacts.get(random.nextInt(contacts.size())); Contact contact = contacts.get(random.nextInt(contacts.size()));
@@ -349,7 +342,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
} }
private List<Forum> createForums(List<Contact> contacts) private List<Forum> createForums(List<Contact> contacts, int numForums,
int numForumPosts)
throws DbException { throws DbException {
List<Forum> forums = new ArrayList<>(numForums); List<Forum> forums = new ArrayList<>(numForums);
for (int i = 0; i < numForums; i++) { for (int i = 0; i < numForums; i++) {
@@ -377,7 +371,8 @@ public class TestDataCreatorImpl implements TestDataCreator {
return forums; return forums;
} }
private void createRandomForumPosts(Forum forum, List<Contact> contacts) private void createRandomForumPosts(Forum forum, List<Contact> contacts,
int numForumPosts)
throws DbException { throws DbException {
List<ForumPost> posts = new ArrayList<>(); List<ForumPost> posts = new ArrayList<>();
for (int i = 0; i < numForumPosts; i++) { for (int i = 0; i < numForumPosts; i++) {