QuickWizard cleanup, -> kotlin
This commit is contained in:
parent
20a2d84a0a
commit
c1109a5b41
|
@ -1,86 +0,0 @@
|
||||||
package info.nightscout.androidaps.data;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 12.10.2016.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class QuickWizard {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(QuickWizard.class);
|
|
||||||
|
|
||||||
private JSONArray storage = new JSONArray();
|
|
||||||
|
|
||||||
public void setData(JSONArray newData) {
|
|
||||||
storage = newData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
SP.putString("QuickWizard", storage.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
return storage.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
public QuickWizardEntry get(int position) {
|
|
||||||
try {
|
|
||||||
return new QuickWizardEntry((JSONObject) storage.get(position), position);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isActive() {
|
|
||||||
for (int i = 0; i < storage.length(); i++) {
|
|
||||||
try {
|
|
||||||
if (new QuickWizardEntry((JSONObject) storage.get(i), i).isActive()) return true;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QuickWizardEntry getActive() {
|
|
||||||
for (int i = 0; i < storage.length(); i++) {
|
|
||||||
QuickWizardEntry entry;
|
|
||||||
try {
|
|
||||||
entry = new QuickWizardEntry((JSONObject) storage.get(i), i);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (entry.isActive()) return entry;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public QuickWizardEntry newEmptyItem() {
|
|
||||||
return new QuickWizardEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOrUpdate(QuickWizardEntry newItem) {
|
|
||||||
if (newItem.position == -1)
|
|
||||||
storage.put(newItem.storage);
|
|
||||||
else {
|
|
||||||
try {
|
|
||||||
storage.put(newItem.position, newItem.storage);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(int position) {
|
|
||||||
storage.remove(position);
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package info.nightscout.androidaps.data
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import org.json.JSONArray
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
object QuickWizard {
|
||||||
|
private var storage = JSONArray()
|
||||||
|
|
||||||
|
init {
|
||||||
|
setData(JSONArray(SP.getString("QuickWizard", "[]")))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getActive(): QuickWizardEntry? {
|
||||||
|
for (i in 0 until storage.length()) {
|
||||||
|
val entry = QuickWizardEntry(storage.get(i) as JSONObject, i)
|
||||||
|
if (entry.isActive) return entry
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setData(newData: JSONArray) {
|
||||||
|
storage = newData
|
||||||
|
}
|
||||||
|
|
||||||
|
fun save() {
|
||||||
|
SP.putString("QuickWizard", storage.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun size(): Int = storage.length()
|
||||||
|
|
||||||
|
operator fun get(position: Int): QuickWizardEntry =
|
||||||
|
QuickWizardEntry(storage.get(position) as JSONObject, position)
|
||||||
|
|
||||||
|
|
||||||
|
fun newEmptyItem(): QuickWizardEntry {
|
||||||
|
return QuickWizardEntry()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addOrUpdate(newItem: QuickWizardEntry) {
|
||||||
|
if (newItem.position == -1)
|
||||||
|
storage.put(newItem.storage)
|
||||||
|
else
|
||||||
|
storage.put(newItem.position, newItem.storage)
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun remove(position: Int) {
|
||||||
|
storage.remove(position)
|
||||||
|
save()
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.data.QuickWizard;
|
||||||
import info.nightscout.androidaps.data.QuickWizardEntry;
|
import info.nightscout.androidaps.data.QuickWizardEntry;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
@ -827,7 +828,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
|
|
||||||
final QuickWizardEntry quickWizardEntry = OverviewPlugin.INSTANCE.getQuickWizard().getActive();
|
final QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive();
|
||||||
if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) {
|
if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) {
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
|
final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
|
||||||
|
@ -1221,7 +1222,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuickWizard button
|
// QuickWizard button
|
||||||
QuickWizardEntry quickWizardEntry = OverviewPlugin.INSTANCE.getQuickWizard().getActive();
|
QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive();
|
||||||
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
|
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
||||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.general.overview
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.data.QuickWizard
|
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
|
@ -19,8 +18,6 @@ import info.nightscout.androidaps.utils.SP
|
||||||
import info.nightscout.androidaps.utils.plusAssign
|
import info.nightscout.androidaps.utils.plusAssign
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONException
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
object OverviewPlugin : PluginBase(PluginDescription()
|
object OverviewPlugin : PluginBase(PluginDescription()
|
||||||
|
@ -39,19 +36,8 @@ object OverviewPlugin : PluginBase(PluginDescription()
|
||||||
var bgTargetLow = 80.0
|
var bgTargetLow = 80.0
|
||||||
var bgTargetHigh = 180.0
|
var bgTargetHigh = 180.0
|
||||||
|
|
||||||
var quickWizard = QuickWizard()
|
|
||||||
|
|
||||||
var notificationStore = NotificationStore()
|
var notificationStore = NotificationStore()
|
||||||
|
|
||||||
init {
|
|
||||||
val storedData = SP.getString("QuickWizard", "[]")
|
|
||||||
try {
|
|
||||||
quickWizard.setData(JSONArray(storedData))
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
log.error("Unhandled exception", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
disposable += RxBus
|
disposable += RxBus
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.cardview.widget.CardView;
|
import androidx.cardview.widget.CardView;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
@ -19,7 +20,6 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||||
import info.nightscout.androidaps.data.QuickWizard;
|
import info.nightscout.androidaps.data.QuickWizard;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.EditQuickWizardDialog;
|
import info.nightscout.androidaps.plugins.general.overview.dialogs.EditQuickWizardDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
@ -42,6 +42,7 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
this.fragmentManager = fragmentManager;
|
this.fragmentManager = fragmentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public QuickWizardEntryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
public QuickWizardEntryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_quickwizardlist_item, viewGroup, false);
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_quickwizardlist_item, viewGroup, false);
|
||||||
|
@ -63,7 +64,7 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
super.onAttachedToRecyclerView(recyclerView);
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,13 +81,13 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
|
|
||||||
QuickWizardEntryViewHolder(View itemView, FragmentManager fragmentManager, QuickWizard qvData) {
|
QuickWizardEntryViewHolder(View itemView, FragmentManager fragmentManager, QuickWizard qvData) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
cv = (CardView) itemView.findViewById(R.id.overview_quickwizard_cardview);
|
cv = itemView.findViewById(R.id.overview_quickwizard_cardview);
|
||||||
buttonText = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_buttonText);
|
buttonText = itemView.findViewById(R.id.overview_quickwizard_item_buttonText);
|
||||||
carbs = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_carbs);
|
carbs = itemView.findViewById(R.id.overview_quickwizard_item_carbs);
|
||||||
from = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_from);
|
from = itemView.findViewById(R.id.overview_quickwizard_item_from);
|
||||||
to = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_to);
|
to = itemView.findViewById(R.id.overview_quickwizard_item_to);
|
||||||
editButton = (Button) itemView.findViewById(R.id.overview_quickwizard_item_edit_button);
|
editButton = itemView.findViewById(R.id.overview_quickwizard_item_edit_button);
|
||||||
removeButton = (Button) itemView.findViewById(R.id.overview_quickwizard_item_remove_button);
|
removeButton = itemView.findViewById(R.id.overview_quickwizard_item_remove_button);
|
||||||
editButton.setOnClickListener(this);
|
editButton.setOnClickListener(this);
|
||||||
removeButton.setOnClickListener(this);
|
removeButton.setOnClickListener(this);
|
||||||
this.fragmentManager = fragmentManager;
|
this.fragmentManager = fragmentManager;
|
||||||
|
@ -118,15 +119,15 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.overview_quickwizardlist_activity);
|
setContentView(R.layout.overview_quickwizardlist_activity);
|
||||||
|
|
||||||
recyclerView = (RecyclerView) findViewById(R.id.overview_quickwizardactivity_recyclerview);
|
recyclerView = findViewById(R.id.overview_quickwizardactivity_recyclerview);
|
||||||
recyclerView.setHasFixedSize(true);
|
recyclerView.setHasFixedSize(true);
|
||||||
llm = new LinearLayoutManager(this);
|
llm = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(llm);
|
recyclerView.setLayoutManager(llm);
|
||||||
|
|
||||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(OverviewPlugin.INSTANCE.getQuickWizard(), getSupportFragmentManager());
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(QuickWizard.INSTANCE, getSupportFragmentManager());
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
adButton = (Button) findViewById(R.id.overview_quickwizardactivity_add_button);
|
adButton = findViewById(R.id.overview_quickwizardactivity_add_button);
|
||||||
adButton.setOnClickListener(this);
|
adButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +145,10 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
if (v.getId() == R.id.overview_quickwizardactivity_add_button) {
|
||||||
case R.id.overview_quickwizardactivity_add_button:
|
FragmentManager manager = getSupportFragmentManager();
|
||||||
FragmentManager manager = getSupportFragmentManager();
|
EditQuickWizardDialog editQuickWizardDialog = new EditQuickWizardDialog();
|
||||||
EditQuickWizardDialog editQuickWizardDialog = new EditQuickWizardDialog();
|
editQuickWizardDialog.show(manager, "EditQuickWizardDialog");
|
||||||
editQuickWizardDialog.show(manager, "EditQuickWizardDialog");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,12 +160,9 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
Activity activity = this;
|
Activity activity = this;
|
||||||
if (activity != null && recyclerView != null) {
|
if (activity != null && recyclerView != null) {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(() -> {
|
||||||
@Override
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(QuickWizard.INSTANCE, getSupportFragmentManager());
|
||||||
public void run() {
|
recyclerView.swapAdapter(adapter, false);
|
||||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).getQuickWizard(), getSupportFragmentManager());
|
|
||||||
recyclerView.swapAdapter(adapter, false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,7 @@ import info.nightscout.androidaps.utils.SafeParse;
|
||||||
public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener {
|
public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class);
|
private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class);
|
||||||
|
|
||||||
QuickWizardEntry entry = new QuickWizard().newEmptyItem();
|
QuickWizardEntry entry = QuickWizard.INSTANCE.newEmptyItem();
|
||||||
QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).getQuickWizard();
|
|
||||||
|
|
||||||
EditText buttonEdit;
|
EditText buttonEdit;
|
||||||
EditText carbsEdit;
|
EditText carbsEdit;
|
||||||
|
@ -151,7 +150,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
quickWizard.addOrUpdate(entry);
|
QuickWizard.INSTANCE.addOrUpdate(entry);
|
||||||
dismiss();
|
dismiss();
|
||||||
MainApp.bus().post(new EventQuickWizardChange());
|
MainApp.bus().post(new EventQuickWizardChange());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package info.nightscout.androidaps.data;
|
package info.nightscout.androidaps.data;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
@ -16,16 +16,15 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({SP.class, MainApp.class})
|
@PrepareForTest({SP.class, MainApp.class, Profile.class})
|
||||||
public class QuickWizardTest {
|
public class QuickWizardTest {
|
||||||
|
|
||||||
String data1 = "{\"buttonText\":\"Meal\",\"carbs\":36,\"validFrom\":0,\"validTo\":18000," +
|
private String data1 = "{\"buttonText\":\"Meal\",\"carbs\":36,\"validFrom\":0,\"validTo\":18000," +
|
||||||
"\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":0,\"useBasalIOB\":0,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}";
|
"\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":0,\"useBasalIOB\":0,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}";
|
||||||
String data2 = "{\"buttonText\":\"Lunch\",\"carbs\":18,\"validFrom\":36000,\"validTo\":39600," +
|
private String data2 = "{\"buttonText\":\"Lunch\",\"carbs\":18,\"validFrom\":36000,\"validTo\":39600," +
|
||||||
"\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":1,\"useBasalIOB\":2,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}";
|
"\"useBG\":0,\"useCOB\":0,\"useBolusIOB\":1,\"useBasalIOB\":2,\"useTrend\":0,\"useSuperBolus\":0,\"useTemptarget\":0}";
|
||||||
|
|
||||||
JSONArray array;
|
private JSONArray array;
|
||||||
QuickWizard qv = new QuickWizard();
|
|
||||||
|
|
||||||
public QuickWizardTest() {
|
public QuickWizardTest() {
|
||||||
try {
|
try {
|
||||||
|
@ -36,48 +35,64 @@ public class QuickWizardTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void mock() {
|
public void mock() throws Exception {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
SPMocker.prepareMock();
|
SPMocker.prepareMock();
|
||||||
|
PowerMockito.mockStatic(Profile.class);
|
||||||
|
PowerMockito.when(Profile.class, "secondsFromMidnight").thenReturn(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setDataTest() {
|
public void setDataTest() {
|
||||||
qv.setData(array);
|
QuickWizard.INSTANCE.setData(array);
|
||||||
Assert.assertEquals(2, qv.size());
|
Assert.assertEquals(2, QuickWizard.INSTANCE.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void saveTest() {
|
public void saveTest() {
|
||||||
qv.setData(array);
|
QuickWizard.INSTANCE.setData(array);
|
||||||
qv.save();
|
QuickWizard.INSTANCE.save();
|
||||||
Assert.assertEquals("[{\"useBolusIOB\":0,\"buttonText\":\"Meal\",\"useTrend\":0,\"carbs\":36,\"useCOB\":0,\"useBasalIOB\":0,\"useTemptarget\":0,\"useBG\":0,\"validFrom\":0,\"useSuperBolus\":0,\"validTo\":18000},{\"useBolusIOB\":1,\"buttonText\":\"Lunch\",\"useTrend\":0,\"carbs\":18,\"useCOB\":0,\"useBasalIOB\":2,\"useTemptarget\":0,\"useBG\":0,\"validFrom\":36000,\"useSuperBolus\":0,\"validTo\":39600}]", SP.getString("QuickWizard", "d"));
|
Assert.assertEquals("[{\"useBolusIOB\":0,\"buttonText\":\"Meal\",\"useTrend\":0,\"carbs\":36,\"useCOB\":0,\"useBasalIOB\":0,\"useTemptarget\":0,\"useBG\":0,\"validFrom\":0,\"useSuperBolus\":0,\"validTo\":18000},{\"useBolusIOB\":1,\"buttonText\":\"Lunch\",\"useTrend\":0,\"carbs\":18,\"useCOB\":0,\"useBasalIOB\":2,\"useTemptarget\":0,\"useBG\":0,\"validFrom\":36000,\"useSuperBolus\":0,\"validTo\":39600}]", SP.getString("QuickWizard", "d"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTest() {
|
public void getTest() {
|
||||||
qv.setData(array);
|
QuickWizard.INSTANCE.setData(array);
|
||||||
Assert.assertEquals("Lunch", qv.get(1).buttonText());
|
Assert.assertEquals("Lunch", QuickWizard.INSTANCE.get(1).buttonText());
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isActive() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getActive() {
|
public void getActive() {
|
||||||
|
QuickWizard.INSTANCE.setData(array);
|
||||||
|
QuickWizardEntry e = QuickWizard.INSTANCE.getActive();
|
||||||
|
Assert.assertEquals(36d, e.carbs(), 0.01d);
|
||||||
|
QuickWizard.INSTANCE.remove(0);
|
||||||
|
QuickWizard.INSTANCE.remove(0);
|
||||||
|
Assert.assertNull(QuickWizard.INSTANCE.getActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void newEmptyItemTest() {
|
public void newEmptyItemTest() {
|
||||||
Assert.assertNotNull(qv.newEmptyItem());
|
Assert.assertNotNull(QuickWizard.INSTANCE.newEmptyItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addOrUpdate() {
|
public void addOrUpdate() {
|
||||||
|
QuickWizard.INSTANCE.setData(array);
|
||||||
|
Assert.assertEquals(2, QuickWizard.INSTANCE.size());
|
||||||
|
QuickWizard.INSTANCE.addOrUpdate(QuickWizard.INSTANCE.newEmptyItem());
|
||||||
|
Assert.assertEquals(3, QuickWizard.INSTANCE.size());
|
||||||
|
QuickWizardEntry q = QuickWizard.INSTANCE.newEmptyItem();
|
||||||
|
q.position = 0;
|
||||||
|
QuickWizard.INSTANCE.addOrUpdate(q);
|
||||||
|
Assert.assertEquals(3, QuickWizard.INSTANCE.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void remove() {
|
public void remove() {
|
||||||
|
QuickWizard.INSTANCE.setData(array);
|
||||||
|
QuickWizard.INSTANCE.remove(0);
|
||||||
|
Assert.assertEquals(1, QuickWizard.INSTANCE.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue