Skip to content

Instantly share code, notes, and snippets.

@namphho
Created October 12, 2018 16:06
Show Gist options
  • Save namphho/f8c637136f1f9fd1973ebc7882ce0310 to your computer and use it in GitHub Desktop.
Save namphho/f8c637136f1f9fd1973ebc7882ce0310 to your computer and use it in GitHub Desktop.
package com.mgxvietnam.bike.business.price;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Mockito.when;
/**
* Created by nampham on 10/12/18.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({TimeUtils.class})
public class PriceModuleTest {
public PriceModule module;
@Before
public void setUp() throws Exception {
int priceDay = 5000;
int priceNight = 7000;
int priceOverNight = 10000;
String moc = "18:00";
module = new PriceModule(priceDay, priceNight, priceOverNight, moc);
PowerMockito.mockStatic(TimeUtils.class);
}
@Test
public void getDayPriceIsTrue() {
//prepare
long in = 1539302400000L;
long out = 1539327600000L;
//action
when(TimeUtils.getTotalDayParked(in, out)).thenReturn(0);
int result = module.getPrice(in, out);
//assert
Assert.assertEquals(5000, result);
}
@Test
public void getNightPriceIsTrue() {
//prepare
long in = 1539356400000L;
long out = 1539360000000L;
//action
when(TimeUtils.getTotalDayParked(in, out)).thenReturn(0);
int result = module.getPrice(in, out);
//assert
Assert.assertEquals(7000, result);
}
@Test
public void getDayToNightPriceIsTrue() {
//prepare
long in = 1539302400000L;
long out = 1539360000000L;
//action
when(TimeUtils.getTotalDayParked(in, out)).thenReturn(0);
int result = module.getPrice(in, out);
//assert
Assert.assertEquals(7000, result);
}
@Test
public void getOverDayDayPriceIsTrue() {
//prepare
long in = 1539302400000L;
long out = 1539396000000L;
//action
when(TimeUtils.getTotalDayParked(in, out)).thenReturn(1);
int result = module.getPrice(in, out);
//assert
Assert.assertEquals(15000, result);
}
@Test
public void getOverDayNightPriceIsTrue() {
//prepare
long in = 1539302400000L;
long out = 1539428460000L;
//action
when(TimeUtils.getTotalDayParked(in, out)).thenReturn(1);
int result = module.getPrice(in, out);
//assert
Assert.assertEquals(17000, result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment