public final void testSetName() { // Test normal final FoodItem item = new FoodItem(); final String name = "aname"; item.setName(name); assertEquals(name, item.getName()); // Test null // try // { // item.setName(null); // fail("Item.setName(String) must not allow null as parameter"); // } catch (AssertionError e) // { // //No code as the exception SHOULD be thrown. // } }
public static void main(String[] args) { FoodItem mixedVegCurry = new FoodItem(); mixedVegCurry.setName("Mixed Vegetable Curry"); mixedVegCurry.setSpicynessLevel(EnumSpicynessLevel.EXTRA_HOT); }
@Override public void run() { // TODO Auto-generated method stub if (choice == 0) { String selection = DBHelperRestaurent.Name + " LIKE '%" + searchName + "%'"; MainActivity.databaseAdapter.open(); cursor = MainActivity.databaseAdapter.database.query( DBHelperRestaurent.TableName, columnsRestaurent, selection, null, null, null, null); Log.d("cursor made", "done"); RestaurentInfo restInfo; searchRestResult.clear(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { restInfo = new RestaurentInfo(); restInfo.setId(cursor.getLong(0)); restInfo.setName(cursor.getString(1)); restInfo.setAddress(cursor.getString(2)); restInfo.setLatitude(cursor.getFloat(3)); restInfo.setLongitude(cursor.getFloat(4)); restInfo.setRank(cursor.getFloat(5)); Log.d("searching", restInfo.toString()); searchRestResult.add(restInfo); handler.sendEmptyMessage(1); cursor.moveToNext(); MainActivity.databaseAdapter.close(); } } else if (choice == 1) { String selection = DBHelperMenu.MenuName + " LIKE '%" + searchName + "%'"; DataBaseAdapterMenu menudbAdapter = new DataBaseAdapterMenu(getActivity().getApplicationContext()); menudbAdapter.open(); SQLiteDatabase database = menudbAdapter.getDatabase(); cursor = database.query( DBHelperMenu.TableNameMenu, columnsFood, selection, null, null, null, null); Log.d("cursor is null", (cursor == null) + ""); FoodItem foodItem; searchFoodResult.clear(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { foodItem = new FoodItem(); foodItem.setRest_Id(cursor.getLong(0)); foodItem.setName(cursor.getString(1)); foodItem.setPrice(cursor.getInt(2)); Log.d("New favourite", foodItem.toString()); searchFoodResult.add(foodItem); handler.sendEmptyMessage(1); cursor.moveToNext(); menudbAdapter.close(); } } }