Skip to content

Commit

Permalink
chore: use shorter async mock syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Mar 17, 2024
1 parent 05f42a2 commit e09ff11
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 58 deletions.
14 changes: 5 additions & 9 deletions packages/cli/test/behavior/buy_ship_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ void main() {
final agent = Agent.test();
when(() => caches.agent.agent).thenReturn(agent);
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

when(() => caches.waypoints.waypointsInSystem(symbol.system))
.thenAnswer((_) => Future.value([]));
// when(() => caches.ships.ships).thenReturn([ship]);
// when(() => caches.ships.frameCounts).thenReturn({});
.thenAnswer((_) async => []);

const shipType = ShipType.HEAVY_FREIGHTER;
final state = BehaviorState(shipSymbol, Behavior.buyShip)
Expand Down Expand Up @@ -152,13 +149,12 @@ void main() {
).thenReturn(route);

registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});

registerFallbackValue(ShipyardListing.fallbackValue());
when(() => db.upsertShipyardListing(any()))
.thenAnswer((_) => Future.value());
when(() => db.upsertShipyardListing(any())).thenAnswer((_) async {});
registerFallbackValue(Ship.fallbackValue());
when(() => db.upsertShip(any())).thenAnswer((_) => Future.value());
when(() => db.upsertShip(any())).thenAnswer((_) async {});
when(db.allShipyardListings).thenAnswer((_) async => []);
when(db.allShips).thenAnswer((_) async => []);
registerFallbackValue(ShipyardListingSnapshot([]));
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/test/behavior/miner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main() {
final marketPrices = _MockMarketPrices();
final symbol = WaypointSymbol.fromString('S-E-A');
when(() => db.recentSurveysAtWaypoint(symbol, count: 100))
.thenAnswer((_) => Future.value([]));
.thenAnswer((_) async => []);
final surveys = await surveysWorthMining(
db,
marketPrices,
Expand Down Expand Up @@ -180,9 +180,9 @@ void main() {
),
);
when(() => db.recentSurveysAtWaypoint(waypointSymbol, count: 100))
.thenAnswer((_) => Future.value([]));
.thenAnswer((_) async => []);
registerFallbackValue(ExtractionRecord.fallbackValue());
when(() => db.insertExtraction(any())).thenAnswer((_) => Future.value());
when(() => db.insertExtraction(any())).thenAnswer((_) async {});

final logger = _MockLogger();

Expand Down Expand Up @@ -218,7 +218,7 @@ void main() {
remainingSeconds: 0,
),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(const SystemSymbol.fallbackValue());
when(() => db.marketPricesInSystem(any())).thenAnswer((_) async => []);

Expand Down Expand Up @@ -483,8 +483,8 @@ void main() {
),
),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(hauler)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
when(() => db.upsertShip(hauler)).thenAnswer((_) async {});

final logger = _MockLogger();

Expand Down Expand Up @@ -605,8 +605,7 @@ void main() {
final fleetApi = _MockFleetApi();
final agent = Agent.test();
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

final transaction = MarketTransaction(
tradeSymbol: tradeSymbol.value,
Expand All @@ -619,7 +618,7 @@ void main() {
timestamp: now,
);
registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});

when(() => api.fleet).thenReturn(fleetApi);
when(
Expand Down Expand Up @@ -670,16 +669,17 @@ void main() {
when(() => centralCommand.minimumSurveys).thenReturn(10);
when(() => centralCommand.surveyPercentileThreshold).thenReturn(0.9);

when(() => db.marketListingForSymbol(waypointSymbol))
.thenAnswer((_) => Future.value());
when(() => db.marketListingForSymbol(waypointSymbol)).thenAnswer((_) async {
return null;
});

final state = BehaviorState(shipSymbol, Behavior.miner)
..extractionJob = ExtractionJob(
source: waypointSymbol,
marketForGood: const {},
extractionType: ExtractionType.mine,
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(TradeSymbol.ADVANCED_CIRCUITRY);
when(() => db.medianMarketPurchasePrice(any()))
.thenAnswer((_) async => 100);
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/test/behavior/mount_from_buy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ void main() {
final agent = Agent.test();
when(() => caches.agent.agent).thenReturn(agent);
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

final ship = _MockShip();
when(() => ship.fleetRole).thenReturn(FleetRole.command);
Expand Down Expand Up @@ -142,7 +141,7 @@ void main() {

when(
() => caches.waypoints.waypointsInSystem(waypointSymbol.system),
).thenAnswer((_) => Future.value([]));
).thenAnswer((_) async => []);

when(() => centralCommand.templateForShip(ship)).thenReturn(
ShipTemplate(
Expand Down Expand Up @@ -221,7 +220,7 @@ void main() {
),
);
registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});

when(
() => caches.routePlanner.planRoute(
Expand All @@ -247,7 +246,7 @@ void main() {
mountSymbol: mountSymbolForTradeSymbol(toMount)!,
shipyardSymbol: waypointSymbol,
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(TradeSymbol.ADVANCED_CIRCUITRY);
when(() => db.medianMarketPurchasePrice(any()))
.thenAnswer((_) async => 100);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/behavior/siphoner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void main() {
),
);
registerFallbackValue(ExtractionRecord.fallbackValue());
when(() => db.insertExtraction(any())).thenAnswer((_) => Future.value());
when(() => db.insertExtraction(any())).thenAnswer((_) async {});

final logger = _MockLogger();

Expand Down Expand Up @@ -149,7 +149,7 @@ void main() {
remainingSeconds: 0,
),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final waitUntil = await runWithLogger(
logger,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/test/behavior/surveyor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void main() {

when(
() => caches.waypoints.waypointsInSystem(waypointSymbol.system),
).thenAnswer((_) => Future.value([]));
).thenAnswer((_) async => []);

when(() => fleetApi.createSurvey(shipSymbol.symbol)).thenAnswer(
(_) => Future.value(
Expand All @@ -93,7 +93,7 @@ void main() {
marketForGood: const {},
extractionType: ExtractionType.mine,
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
final waitUntil = await runWithLogger(
Expand Down
29 changes: 13 additions & 16 deletions packages/cli/test/behavior/trader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ void main() {
final agent = Agent.test();
when(() => caches.agent.agent).thenReturn(agent);
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

final state = BehaviorState(shipSymbol, Behavior.trader);

Expand Down Expand Up @@ -191,14 +190,14 @@ void main() {
),
);
registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});
when(db.allBehaviorStates).thenAnswer((_) async => []);
registerFallbackValue(BehaviorSnapshot([]));
registerFallbackValue(ShipSnapshot([]));
when(() => centralCommand.otherTraderSystems(any(), any(), shipSymbol))
.thenReturn([]);
when(db.allShips).thenAnswer((_) async => []);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

when(() => caches.marketPrices.prices).thenReturn([]);

Expand Down Expand Up @@ -371,8 +370,7 @@ void main() {
final agent = Agent.test();
when(() => caches.agent.agent).thenReturn(agent);
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

final transaction = MarketTransaction(
pricePerUnit: 100,
Expand Down Expand Up @@ -483,8 +481,8 @@ void main() {
),
).thenReturn(routePlan);
registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(TradeSymbol.ADVANCED_CIRCUITRY);
when(() => db.medianMarketPurchasePrice(any()))
.thenAnswer((_) async => 100);
Expand Down Expand Up @@ -720,7 +718,7 @@ void main() {
).thenReturn([]);

when(db.allBehaviorStates).thenAnswer((_) async => []);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
final waitUntil = await runWithLogger(
Expand Down Expand Up @@ -931,7 +929,7 @@ void main() {

final state = BehaviorState(const ShipSymbol('S', 1), Behavior.trader)
..deal = costedDeal;
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
final result = await runWithLogger(
Expand Down Expand Up @@ -1226,17 +1224,16 @@ void main() {

when(() => caches.agent.agent).thenReturn(agent);
registerFallbackValue(agent);
when(() => caches.agent.updateAgent(any()))
.thenAnswer((_) => Future.value());
when(() => caches.agent.updateAgent(any())).thenAnswer((_) async {});

registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});
registerFallbackValue(Contract.fallbackValue());
when(() => db.upsertContract(any())).thenAnswer((_) async {});

final state = BehaviorState(const ShipSymbol('S', 1), Behavior.trader)
..deal = costedDeal;
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(TradeSymbol.ADVANCED_CIRCUITRY);
when(() => db.medianMarketPurchasePrice(any()))
.thenAnswer((_) async => 100);
Expand Down Expand Up @@ -1421,7 +1418,7 @@ void main() {
when(() => caches.agent.agent).thenReturn(agent);

registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) => Future.value());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});

when(caches.construction.allRecords).thenAnswer((_) async => []);
when(
Expand All @@ -1430,7 +1427,7 @@ void main() {

final state = BehaviorState(const ShipSymbol('S', 1), Behavior.trader)
..deal = costedDeal;
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
registerFallbackValue(TradeSymbol.ADVANCED_CIRCUITRY);
when(() => db.medianMarketPurchasePrice(any()))
.thenAnswer((_) async => 100);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/nav/navigation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void main() {

registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});
when(() => centralCommand.medianAntimatterPurchasePrice).thenReturn(10000);

final singleJumpResult = await runWithLogger(
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/test/net/actions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void main() {
registerFallbackValue(agent1);
when(() => db.upsertAgent(any())).thenAnswer((_) async {});
registerFallbackValue(Ship.fallbackValue());
when(() => db.upsertShip(any())).thenAnswer((_) => Future.value());
when(() => db.upsertShip(any())).thenAnswer((_) async {});

final agentCache = AgentCache(agent1, db);
final shipyardSymbol = WaypointSymbol.fromString('S-A-Y');
Expand Down Expand Up @@ -99,7 +99,7 @@ void main() {
).thenAnswer(
(invocation) => Future.value(GetShipNav200Response(data: shipNav)),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

await setShipFlightMode(db, api, ship, ShipNavFlightMode.CRUISE);
verify(() => ship.nav = shipNav).called(1);
Expand All @@ -125,7 +125,7 @@ void main() {
when(() => ship.nav).thenReturn(shipNav);
when(() => shipNav.waypointSymbol).thenReturn('S-A-W');
when(() => shipNav.status).thenReturn(ShipNavStatus.IN_ORBIT);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
await runWithLogger(logger, () => undockIfNeeded(db, api, ship));
Expand Down Expand Up @@ -156,7 +156,7 @@ void main() {
when(() => ship.nav).thenReturn(shipNav);
when(() => shipNav.waypointSymbol).thenReturn('S-A-W');
when(() => shipNav.status).thenReturn(ShipNavStatus.DOCKED);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
await runWithLogger(logger, () => dockIfNeeded(db, api, ship));
Expand Down Expand Up @@ -209,7 +209,7 @@ void main() {
),
),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final logger = _MockLogger();
await runWithLogger(
Expand Down Expand Up @@ -280,8 +280,8 @@ void main() {
),
),
);
when(() => db.upsertShip(fromShip)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(toShip)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(fromShip)).thenAnswer((_) async {});
when(() => db.upsertShip(toShip)).thenAnswer((_) async {});

final _ = await runWithLogger(
logger,
Expand Down Expand Up @@ -392,7 +392,7 @@ void main() {
),
]);
when(() => ship.fuel).thenReturn(ShipFuel(capacity: 1000, current: 634));
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

await runWithLogger(
logger,
Expand Down Expand Up @@ -649,7 +649,7 @@ void main() {
],
);
when(() => ship.cargo).thenReturn(shipCargo);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

final transactions = await runWithLogger(logger, () async {
final result = await sellAllCargoAndLog(
Expand Down Expand Up @@ -711,7 +711,7 @@ void main() {
),
),
);
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

await runWithLogger(logger, () async {
await jettisonCargoAndLog(db, api, ship, itemOne);
Expand Down Expand Up @@ -934,7 +934,7 @@ void main() {

registerFallbackValue(Transaction.fallbackValue());
when(() => db.insertTransaction(any())).thenAnswer((_) async {});
when(() => db.upsertShip(ship)).thenAnswer((_) => Future.value());
when(() => db.upsertShip(ship)).thenAnswer((_) async {});

await runWithLogger(logger, () async {
await useJumpGateAndLog(
Expand Down

0 comments on commit e09ff11

Please sign in to comment.