Skip to content

Commit

Permalink
TestLogWriter.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-martinez committed Nov 24, 2023
1 parent 4522d84 commit fafcf3e
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/test/java/Controller/TestLogWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package Controller;

import Model.*;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;


/**
* Test if LogEntry(observable) updates the LogWriter(observer)
* and writes to log file log.txt*
*/
public class TestLogWriter {

/**
* d_Ge is reference for gameEngine
*/
public GameEngine d_Ge;
Player d_Player1;
Player d_Player2;
WargameMap d_Map;
ArrayList<Player> d_Players;
String d_PlayerName="xyz";
EngineCommand d_Rge;
String[] d_Data={"gameplayer", "-add", "Alekhya"};
String[] d_Data1 = new String[]{"loadmap","world.map"};
String d_MapName;

/**
* initial setup
*/
@Before
public void before(){
d_Ge = new GameEngine();
d_Rge = new EngineCommand();
d_Players = new ArrayList<Player>();
d_Map = new WargameMap("demo.map");
d_Player1 = new Player("Alekhya");
d_Player2 = new Player("Sujith");
d_Players.add(d_Player1);
d_Players.add(d_Player2);
}

/**
*Test if LogEntryBuffer(observable) updates the WriteLogEntry(observer)
* to write to log file log.txt
*/
@Test
public void testLogEntryBuffer(){

//Testing preload phase logs are stored in log file or not
d_Ge.setPhase(new MapEditorLoad(d_Ge));
d_MapName= "demo.map";
d_Ge.d_LogEntry.setGamePhase(d_Ge.d_Phase);
d_Ge.d_Phase.loadMap(d_Data1,d_MapName);

//Testing if invalid
System.out.println("Testing invalid command(gameplayer) in phase: "+ d_Ge.d_Phase.getD_PhaseName());
d_Ge.d_Phase.gamePlayer(d_Data,d_Players,d_Player1.getPlayerName());
assertEquals("Invalid command in PostLoad state","Invalid command in PostLoad state");

d_Map = d_Rge.editMap(d_MapName);
d_Ge.d_Phase.showMap(d_Map);

//Testing startup phase are stored in log file or not
d_Ge.setPhase(new StartUp(d_Ge));
d_Ge.d_LogEntry.setGamePhase(d_Ge.d_Phase);
d_Ge.d_Phase.gamePlayer(d_Data,d_Players,d_Player1.getPlayerName());
d_Ge.d_Phase.gamePlayer(d_Data,d_Players,d_Player2.getPlayerName());
d_Ge.d_Phase.assignCountries(d_Map,d_Players );

}


}

0 comments on commit fafcf3e

Please sign in to comment.