Junit testing in java [closed] - junit

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Please, how can I write a junit test cases for these methods :
public void setDishProvider(DishProvider dishProvider) {
this.dishProvider= dishProvider;
dishProvider.addDishListener(this);
}
public int peopleHelped() {
return counter; //returns the counter..
}

guessing blindly...
#Test
public void testSetDishProvider() {
YourClass yourclass = new YourClass();
DishProvider dishProvider = new DishProvider();
yourClass.setDishProvider(dishProvider);
assertEquals(dishProvider, yourClass.getDishProvider());
assertTrue(dishProvider.getListeners().contains(yourClass));
}

Related

Making a button display a text field on click in ActionScript 3.0 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to make a button in ActionScript 3.0 that, when clicked, displays a text field that contains three paragraphs of text.
I have a dynamic text field named textField.
I have a button on stage named learn_button.
import flash.events.MouseEvent;
import flash.display.DisplayObjectContainer;
import flash.text.TextField;
learn_button.addEventListener(MouseEvent.CLICK, onButtonClick);
function onButtonClick(e:MouseEvent):void
{
var button:DisplayObjectContainer = DisplayObjectContainer(e.target);
var textField:TextField = TextField(learn_button.getChildByName("textField"));
textField.text = "Three paragraphs of text...";
}
learn_button.addEventListener(MouseEvent.CLICK, onButtonClick);
textField.visible=false;
function onButtonClick(e:MouseEvent):void
{
textField.visible=true;
textField.text = "Three paragraphs of text...";
}

How do i maintain session on a windows phone 8 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to maintain session on a windows phone 8 app.how do i maintain a session of user
In WP8 there are events that are fired to tell you when the application is launched, closed, activated, or deactivated. These event handlers can be seen in the App.xaml.cs file in your Wp8 app.
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
Also see this diagram obtained from this pdf from Microsoft:
So, the thing to do then is to place the appropriate code for saving and retrieving data to and from the isolated storage of the application. An example of this might be the following code that reads a stored xml file:
XElement doc;
using (var isoStoreStream = new IsolatedStorageFileStream("TimeSpaceData.xml", FileMode.Open, isoStoreFile))
{
doc = XElement.Load(isoStoreStream);
}
return doc;
The following code would save an xml file:
XElement pDoc = GetXElementYouWantToSave();
using (var isoStoreStream = new IsolatedStorageFileStream("TimeSpaceData.xml", FileMode.Create, isoStoreFile))
{
pDoc.Save(isoStoreStream);
}

AS3 How to make separate menus/windows with heavy data? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
In games it's usual to be able to access some kind of menus.
A list of things with descriptions, a menu of upgrades, anything that's pretty heavy with pictures, text etc.
So what is a convenient way to organize it all?
As I tried classes, it seems like they don't share variables between them.
I need a way of sharing data between these windows/menus. And it shouldn't be overweighted with data, meaning each time I close a menu it's parts disappear to not make Flash calculate MovieClip positions, alphas, effects and other values that I don't need, working with another menu.
As an example to better understand, what if I make 5 games in one and need to share variables between them?
Say, first I play Arcanoid, then switch to Tetris and use Arcanoid score as a number of blocks I can get, then switch to Pinball and use the number of lines scored in Tetris as a number of balls, then switch to Gradius and my ship attack power is Pinball score divided by 1000, then I see a window of overall scores with heavy victory firework effects.
I'd need each game to work separately, otherwise they will go very slow overloaded with graphics and the length of code to find functions.
How is that achieved?
Thanks moskito, I'm a bit messy ^_^'
How is that achieved?
You create the architecture to make it happen. Your particular example could be approached like this:
Firstly, you want to define the foundation that these mini-games or separate batches of content will run on. This foundation will deal with running the mini-games, as well as tracking their state and information associated with them that you want to pass off to subsequent mini-games.
Secondly, you want to define the base class that will represent one of these mini-games. This class will be extended for each of the new games you want to create and have run on the platform. This base class will deal with notifying the platform of changes.
Lastly, you want to create some models represting a state in change within the mini-game. The inbuilt Event system is a good way to approach this, but you can easily create your own data models in this instance which you pass off to the platform directly.
Code samples.
The basics of your platform could be something along the lines of:
public class Platform
{
private var _game:MiniGame;
private var _recentGameStateData:GameStateData;
public function loadGame(game:MiniGame):void
{
if(_game != null) game.unload();
_game = game;
_game.start(this, _recentGameStateData);
}
public function update():void
{
if(_game != null) _game.update();
}
internal function manageStateChange(gameStateData:GameStateData):void
{
_recentGameStateData = gameStateData;
// Do stuff with the new game state data, like save the current score
// to use in your next game.
//
}
}
Your mini-game:
public class MiniGame
{
private var _platform:Platorm;
private var _score:int = 0;
public function start(platform:Platform, previousGameStateData:GameStateData):void
{
_platform = platform;
// Use previous GameStateData here.
//
}
public function update():void{}
public function unload():void{}
public function notifyPlatform(gameStateData:GameStateData):void
{
_platform.manageStateChange(gameStateData);
}
protected function get score():int{ return _score; }
}
Your game state data for the platform to manage:
public class GameStateData
{
private var _game:MiniGame;
private var _score:int;
public function GameStateData(game:MiniGame, score:int)
{
_game = game;
_score = score;
}
public function get game():MiniGame{ return _game; }
public function get score():int{ return _score; }
}
And then an example of sending that information up to the platform in your own mini-game:
public class TetrisGame extends MiniGame
{
override public function unload():void
{
// Let the Platform know about the current score when this game is
// being unloaded.
var state:GameStateData = new GameStateData(this, _score);
notifyPlatform(state);
}
}

Drag and drop objects simultaneously [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I face a problem... and am looking for a solution or an idea. I want to drag drop several objects (markers,polylines,...) simultaneously, but I do not know if this is possible ...
Does anyone have an idea ?
Thanks in advance !
Regards,
Sebastien
Thanks Nils !!!
You give me the good way !
Here you have how i've made it possible :
google.maps.event.addListener(window["Overlay" + i] , 'click', function(event) {
var path = this.getPath();
google.maps.event.addListener(path, 'set_at', function(indEdited,newLatLng){
var oo = this.getAt(indEdited);
diffLat = (newLatLng.lat() - oo.lat());
diffLng = (newLatLng.lng() - oo.lng());
moveOverlay(this,indEdited,diffLat,diffLng);
var temp = "Do you want to me the others overlays ?"
if (fromPath == lastPath )
{
if ( confirm(temp) ){
moveOthersOverlays(diffLat,diffLng);
}
}
});
});
The problem is that it's only markers that you can drag n' drop, so you must design the functionality with this in mind.
First we need to now the starting position, this is done with the dragstart event. Please not that you have to do this on all your markers.
var startLatLng;
google.maps.event.addListener(marker, 'dragstart', function(){
marker.getPosition()
});
You will utilize the function the drag event, and loop over all objects. I will utilize pseudo code here, let me know if it's something that is unclear. The assumption is that you save your markers in an array
google.maps.event.addListener(dragmarker, 'drag', function(){
end = dragmarker.getPosition();
for (marker in markers){
// Don't care about marker being dragged
if (dragmarker == marker)
continue;
current = marker.getPossition();
// Bellow we create a new position for the marker by calculating the difference
// and add it to the current possition of the marker
marker.setPosition(new google.maps.LatLng(
current.lat() + (end.lat() - start.lat()),
current.lng() + (end.lng() + start.lng()));
}
// Same same for the polylines but you will have to loop over the path
});
Please note that this will be really slow if there are alot of objects that you are moving around. But this works great for me when moving a couple of markers and a small polyline. Also, please note that the code is a bit crude, I just wanted to show how it's done. In my solution I'm storing my markers and polylines in objects that will update them self.
You can check out my code at this github repo

How Can I do a trigger keyboard (left and right arrow) in flash CS4 for next / prev frame? Like a PowerPoint Presentation [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
StackOverflow community.
I'm full newbie, but I like CS4 and Javascript code. I wanna spend my time practicing this. Thanks for help!
add a KeyboardEvent. and getting a keyCode, handle as follows.
notice. need to add a stop(); code on frame 1 of your MovieClip.
check out this my sample code: simple_ppt
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownHandler);
function onKeyDownHandler(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.LEFT)
{
trace("left!!!");
if(myMovieClip.currentFrame > 1)
{
myMovieClip.prevFrame();
}
}
else if(e.keyCode == Keyboard.RIGHT)
{
trace("right!!!");
if(myMovieClip.currentFrame < mc.totalFrames)
{
myMovieClip.nextFrame();
}
}
}